/// <summary> /// Is the given type an enum? /// </summary> public static bool IsEnum(this XTypeReference type) { type = type.GetWithoutModifiers(); XTypeDefinition typeDef; return(type.IsEnum(out typeDef)); }
/// <summary> /// Is the given type a struct? /// </summary> public static bool IsStruct(this XTypeReference type) { XTypeDefinition typeDef; type = type.GetWithoutModifiers(); return(type.IsStruct(out typeDef)); }
/// <summary> /// Is the given type a reference to System.Collections.Generic.IEnumerable`1? /// </summary> public static bool IsSystemCollectionsIEnumerableT(this XTypeReference type) { if (type == null || !type.IsGenericInstance) { return(false); } return(type.GetWithoutModifiers().FullName == "System.Collections.Generic.IEnumerable`1"); }
/// <summary> /// Is the given type a type definition or a normal type reference? /// </summary> public static bool IsDefinitionOrReferenceOrPrimitive(this XTypeReference type) { type = type.GetWithoutModifiers(); if (type.IsDefinition || type.IsPrimitive) { return(true); } return(type.Kind == XTypeReferenceKind.TypeReference); }
/// <summary> /// Is the given type void? /// </summary> public static bool IsVoid(this XTypeReference type) { if (type == null) { return(false); } type = type.GetWithoutModifiers(); return((type.FullName == "System.Void") || type.Module.TypeSystem.Void.IsSame(type)); }
/// <summary> /// Is the given type of the given kind? /// </summary> public static bool Is(this XTypeReference type, XTypeReferenceKind kind1, XTypeReferenceKind kind2) { if (type == null) { return(false); } type = type.GetWithoutModifiers(); return((type.Kind == kind1) || (type.Kind == kind2)); }
/// <summary> /// Is the given type a struct? /// </summary> public static bool IsStruct(this XTypeReference type, out XTypeDefinition typeDef) { typeDef = null; if (type == null) { return(false); } type = type.GetWithoutModifiers(); return(type.TryResolve(out typeDef) && typeDef.IsStruct); }
/// <summary> /// Is the given type a wide primitive (long, ulong, double)? /// </summary> public static bool IsWide(this XTypeReference type) { if (type == null) { return(false); } var ts = type.Module.TypeSystem; type = type.GetWithoutModifiers(); return(ts.Long.IsSame(type) || ts.ULong.IsSame(type) || ts.Double.IsSame(type)); }
/// <summary> /// Is the given type a reference to System.Collections.Generic.ICollection`1? /// </summary> public static bool IsSystemCollectionsICollectionT(this XTypeReference type) { if (type == null) { return(false); } type = type.GetWithoutModifiers(); if (!type.IsGenericInstance) { return(false); } return(type.FullName == "System.Collections.Generic.ICollection`1"); }
/// <summary> /// Is the given type IEnumerable or a derived interface? /// </summary> public static bool ExtendsIEnumerable(this XTypeReference type) { type = type.GetWithoutModifiers(); if (type.FullName == "System.Collections.IEnumerable") { return(true); } XTypeDefinition typeDef; if (!type.TryResolve(out typeDef) || !typeDef.IsInterface) { return(false); } return(typeDef.Interfaces.Any(ExtendsIEnumerable)); }
/// <summary> /// Is the given type System.Collections.IList, System.Collections.Generic.IList(T) or a derived interface? /// </summary> public static bool ExtendsIList(this XTypeReference type) { type = type.GetWithoutModifiers(); var fullName = type.FullName; if ((fullName == "System.Collections.IList") || (fullName == "System.Collections.Generic.IList`1")) { return(true); } XTypeDefinition typeDef; if (!type.TryResolve(out typeDef) || !typeDef.IsInterface) { return(false); } return(typeDef.Interfaces.Any(ExtendsIList)); }
/// <summary> /// Is the given type a reference to System.Collections.Generic.IList`1? /// </summary> public static bool IsSystemCollectionsIListT(this XTypeReference type) { return((type != null) && (type.GetWithoutModifiers().FullName == "System.Collections.Generic.IList`1")); }
/// <summary> /// Is the given type System.Nullable<T>? /// </summary> public static bool IsNullableT(this XTypeReference type) { type = type.GetWithoutModifiers(); return(type.FullName == "System.Nullable`1"); }
/// <summary> /// Is the given type of the given kind? /// </summary> public static bool Is(this XTypeReference type, params XTypeReferenceKind[] kinds) { return((type != null) && (Array.IndexOf(kinds, type.GetWithoutModifiers().Kind) >= 0)); }
/// <summary> /// Is the given type a reference to System.Collections.IEnumerable? /// </summary> public static bool IsSystemCollectionsIEnumerable(this XTypeReference type) { return((type != null) && (type.GetWithoutModifiers().FullName == "System.Collections.IEnumerable")); }
/// <summary> /// Is the given type a reference to System.IFormattable? /// </summary> public static bool IsSystemIFormattable(this XTypeReference type) { return((type != null) && (type.GetWithoutModifiers().FullName == "System.IFormattable")); }
/// <summary> /// Is the given type a reference to System.Array? /// </summary> public static bool IsSystemArray(this XTypeReference type) { return((type != null) && (type.GetWithoutModifiers().FullName == "System.Array")); }
/// <summary> /// Is the given type Dot42.Internal.Enum? /// </summary> public static bool IsInternalEnum(this XTypeReference type) { return((type != null) && (type.GetWithoutModifiers().FullName == InternalConstants.Dot42InternalNamespace + ".Enum")); }
/// <summary> /// Is the given type a uint? /// </summary> public static bool IsUInt32(this XTypeReference type) { return((type != null) && type.Module.TypeSystem.UInt.IsSame(type.GetWithoutModifiers())); }
/// <summary> /// Is the given type of the given kind? /// </summary> public static bool Is(this XTypeReference type, XTypeReferenceKind kind) { return((type != null) && (type.GetWithoutModifiers().Kind == kind)); }