PostSharp 4.3 / / Post­Sharp Documentation / API Reference / Post­Sharp.​Patterns.​Model Namespace / Query­Interface­Extensions Class / Query­Interface­Extensions Methods / Query­Interface­Extensions.​Query­Interface(T) Method
QueryInterfaceExtensions.QueryInterface<T> Method
Gets the implementation of a specified interface for the specified object.

Namespace: PostSharp.Patterns.Model
Assembly: PostSharp.Patterns.Common (in PostSharp.Patterns.Common.dll) Version: (
public static T QueryInterface<T>(
	this Object obj,
	bool throwing = true
where T : class


Type: System.Object
The object for which the interface should be queried.
throwing (Optional)
Type: System.Boolean
true if the method should throw a InvalidCastException if obj does not implement the T interface, false if null be returned instead. The default value is true.

Type Parameters

The type of the required interface.

Return Value

Type: T
An object implementing the T interface on behalf of obj, or null if obj does not implement T and throwing is true.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Object. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

This method shall return obj if the type of obj statically implements the interface. Otherwise, the method shall return another object that implements T on behalf of obj. In this case, the returned object shall implement the IDynamicInterfaceImplementation interface, which allows to navigate back to obj.

See Also