The problem of your question is that the title is done that way, probably nobody will search it and answering here probably won't bring any points later :).
As in the comments were mentioned these are extension methods. It means that they can extend some regular classes' functions.
Some information about extension methods:
- They should be declared in a static class;
- The extension class should be the first class in the file. (In C# you can have more than one class in one file, but extension class will work only if it is the first in the file);
- Extension functions should be static as well because there is a dynamic member following the keyword "this" which is extended;
- Extension function's first parameter should be starting with "this" keyword (mentioned above) as it tells the compiler which object is extended.
In your case: static public void QueryService<T>(this IServiceProvider serviceProvider, out T service) where T : class
means that thanks to this function, any IServiceProvider type object will be able to have additional (extended) function QueryService which will take generic type which should be class (not struct) see: where T : class
.
out T service
means that passed parameter can be not initialized (as out
doesn't need parameter initialization despite ref
).
Usage will be something like this:
CustomServiceType myService;
IServiceProvider serviceProvider = new TypeWhichImplementsIServiceProvider();
//Now we can use extension function
serviceProvider.QueryService<CustomServiceType>(out myService);
//After this function myService should be initialized (probably...)