I am trying to write an anonymous(is that the right term?) method that accepts an object and some string parameters to work with.
This method needs to take these parameters, perform an API request, and then return those results.
In order for this to work, I need to be able to pass in the object calling the method, as I need this instantiated object returned with the results. If I can't achieve this then I can't make this method anonymous.
Reason for wanting to achieve this: I will have a dozen or so objects that will need these tasks done and I'd rather not have to copy and paste the bulk of reusable code.
Here is the method's current structure:
public static async Task<object> gqlQueryMethod(object senderObject,string gqlQueryString, string gqlVarString, string gqlQueryName)
{
var query = new GraphQLRequest
{
Query = gqlQueryString,
Variables = gqlVarString
};
var graphQLResponse = await _gqlClient.SendQueryAsync(query);
if (graphQLResponse.Errors != null)
{
//Can't access the object that is being passed in as "senderObject"
var errorExists = senderObject;
errorExists.errorMessage = graphQLResponse.Errors[0].Message;
return errorExists;
}
//More code logic down here, based on the error check passing or failing
var apiFetchResults = graphQLResponse.GetDataFieldAs<senderObject>("gqlQuery");
This method attempt is probably the most complex thing I've attempted in my short .NET journey so I feel as though I'm missing something fundamental here, as to why I can't access the sender object inside of that if statement.
My other thought is perhaps I'm not leveraging inheritance correctly, which might help this situation?
Edit: