The following snippet will allow you to use the IsOfType extension method, simple but usefull!

Extension method C#

public static bool IsOfType<T>(this object input)
{
	return input.IsOfType(typeof (T));
}

public static bool IsOfType(this object input, Type type)
{
	return (input.GetType() == type);
}

Extension method VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsOfType(Of T)(obj As Object) As Boolean
	Return input.IsOfType(GetType(T))
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsOfType(input As Object, type As Type) As Boolean
	Return (input.GetType() = type)
End Function

One thought on “IsOfType extension method for C# and VB.NET”

Leave a Reply