Exemple #1
0
        /// <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));
        }
Exemple #2
0
        /// <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));
        }
Exemple #3
0
 /// <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");
 }
Exemple #4
0
 /// <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);
 }
Exemple #5
0
 /// <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));
 }
Exemple #6
0
 /// <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));
 }
Exemple #7
0
 /// <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);
 }
Exemple #8
0
        /// <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));
        }
Exemple #9
0
 /// <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");
 }
Exemple #10
0
        /// <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));
        }
Exemple #11
0
        /// <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));
        }
Exemple #12
0
 /// <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"));
 }
Exemple #13
0
 /// <summary>
 /// Is the given type System.Nullable&lt;T&gt;?
 /// </summary>
 public static bool IsNullableT(this XTypeReference type)
 {
     type = type.GetWithoutModifiers();
     return(type.FullName == "System.Nullable`1");
 }
Exemple #14
0
 /// <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));
 }
Exemple #15
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"));
 }
Exemple #16
0
 /// <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"));
 }
Exemple #17
0
 /// <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"));
 }
Exemple #18
0
 /// <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"));
 }
Exemple #19
0
 /// <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()));
 }
Exemple #20
0
 /// <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));
 }