Click or drag to resize

TypeExtensionsInheritsFromT Method (Type)

Determines if the specified type inherits from the target type.

Read our blog on this topic: Effective Extensions – Extending Types in C#

Namespace:  Xcalibur.Extensions
Assembly:  Xcalibur.Extensions (in Xcalibur.Extensions.dll) Version: 1.0.4.0 (1.0.0.0)
Syntax
public static bool InheritsFrom<T>(
	this Type type
)

Parameters

type
Type: SystemType
The type.

Type Parameters

T

Return Value

Type: Boolean

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Type. 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).
Examples
C#
1var context = ((FrameworkElement)e.OriginalSource).DataContext;
2if (!context.GetType().InheritsFrom<IMyInterface>())
3{
4    e.Handled = true;
5}
6else
7{
8    ViewModel.ContextMenuOpening(context as IMyInterface);
9}
See Also