IsStatic

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

Description

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

Details

  • Author: jlafay
  • Submitted on: 11/15/2010 2:58:22 PM
  • Language: C#
  • Type: System.Type
  • Views: 1795

Double click on the code to select all.

 

;