ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

IsStatic

Determines if a type is static by checking if it's abstract, sealed, and has no public constructors.

Source

public static class TypeExtensions
{
	public static bool IsStatic(this Type t)
	{
		var c = t.GetConstructors();
		return (t.IsAbstract && t.IsSealed && c.Length == 0);
	}
}

Example

Type env = typeof(Environment);
Type str = typeof(String);

string result = String.Format("Env-> {0}  Str-> {1}", env.IsStatic(), str.IsStatic());

Console.WriteLine(result);
// Env-> True  Str-> False

Author: jlafay

Submitted on: 15 nov 2010

Language: C#

Type: System.Type

Views: 4710