Exemple #1
0
		internal static Array GetEnumValues(System.Type enumType)
		{
			if(!enumType.GetTypeInfo().IsEnum)
				throw new ArgumentException("Not an enumeration type", "enumType");

			return Enum.GetValues(enumType);
		}
		public static TP GetTypeInfo ( System.Type type ) {
#if NETFX_CORE
			return type.GetTypeInfo();
#else
			return type;
#endif
		}
		//private HashSet<Type> typeHasTypeHintCache;

		#endregion Fields

		#region Properties

		public static TP GetTypeInfo ( System.Type tp ) {
#if WINDOWS_STORE
			return tp.GetTypeInfo ();
#else
			return tp;
#endif
		}
Exemple #4
0
        internal static bool IsEnumType(System.Type t)
        {
#if NEW_REFLECTION
            return t.GetTypeInfo().IsEnum;
#else
            return t.IsEnum;
#endif
        }
 /**
  * Missing IsSubclassOf, this works well
  */
 public static bool IsSubclassOf(this System.Type type, System.Type parent)
 {
     #if NETFX_CORE
     return parent.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
     #else
     return type.IsSubclassOf(parent);
     #endif
 }
 /**
  * Just forward this call to the proper spot
  */
 public static bool IsAssignableFrom(this System.Type type, System.Type other)
 {
     #if NETFX_CORE
     return type.GetTypeInfo().IsAssignableFrom(other.GetTypeInfo());
     #else
     return type.IsAssignableFrom(other);
     #endif
 }
        internal static Enum GetEnumValue(System.Type enumType, string s)
        {
            if(!enumType.GetTypeInfo().IsEnum)
                throw new ArgumentException("Not an enumeration type", "enumType");

            // We only want to parse single named constants
            if(s.Length > 0 && char.IsLetter(s[0]) && s.IndexOf(',') < 0)
            {
                s = s.Replace('-', '_');
                s = s.Replace('/', '_');

                return (Enum)Enum.Parse(enumType, s, false);
            }

            throw new ArgumentException();
        }
Exemple #8
0
		internal static Array GetEnumValues(System.Type enumType)
		{
			if (!enumType.GetTypeInfo().IsEnum)
				throw new ArgumentException("Not an enumeration type", "enumType");

#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
            IList result = Platform.CreateArrayList();
			FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
			foreach (FieldInfo field in fields)
			{
				result.Add(field.GetValue(null));
			}
            object[] arr = new object[result.Count];
            result.CopyTo(arr, 0);
            return arr;
#else
			return Enum.GetValues(enumType);
#endif
		}
        private static string FormatAssemblyVersion(System.Type type)
        {
            // Prefer AssemblyInformationalVersion, then AssemblyFileVersion,
            // then AssemblyVersion.

            var assembly = type.GetTypeInfo().Assembly;
            var info = assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().FirstOrDefault()?.InformationalVersion;
            if (info != null)
            {
                return info;
            }
            var file = assembly.GetCustomAttributes<AssemblyFileVersionAttribute>().FirstOrDefault()?.Version;
            if (file != null)
            {
                return string.Join(".", file.Split('.').Take(3));
            }
            var version = assembly.GetName().Version;
            return $"{version.Major}.{version.Minor}.{version.Build}";
        }
Exemple #10
0
		internal static Enum GetEnumValue(System.Type enumType, string s)
		{
			if (!enumType.GetTypeInfo().IsEnum)
				throw new ArgumentException("Not an enumeration type", "enumType");

			// We only want to parse single named constants
			if (s.Length > 0 && char.IsLetter(s[0]) && s.IndexOf(',') < 0)
			{
				s = s.Replace('-', '_');

#if NETCF_1_0
				FieldInfo field = enumType.GetField(s, BindingFlags.Static | BindingFlags.Public);
				if (field != null)
				{
					return (Enum)field.GetValue(null);
				}
#else
				return (Enum)Enum.Parse(enumType, s, false);
#endif		
			}

			throw new ArgumentException();
		}
 /**
  * Missing IsSubclassOf, this works well
  */
 public static bool IsSubclassOf(this Type type, System.Type parent)
 {
     #if NETFX_CORE
     return parent.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
     #else
     throw new NotImplementedException();
     #endif
 }
Exemple #12
0
 private static Dictionary<object, string> GetNameMapping(System.Type enumType) =>
     enumType.GetTypeInfo().DeclaredFields
         .Where(f => f.IsStatic)
         .ToDictionary(f => f.GetValue(null),
                       f => f.GetCustomAttributes<OriginalNameAttribute>()
                             .FirstOrDefault()
                             // If the attribute hasn't been applied, fall back to the name of the field.
                             ?.Name ?? f.Name);
Exemple #13
0
        static IEnumerable<string> GenerateHelp(string contentPath, string assembly, string keys, System.Type type)
        {
            var cmdletAttributes = type.GetTypeInfo().GetCustomAttributes().Where((a) => a.GetType().FullName == "System.Management.Automation.CmdletAttribute" || a.GetType().FullName == "System.Management.Automation.PSCmdletAttribute");
            dynamic cmdletAttribute = cmdletAttributes.FirstOrDefault();
            var commandName = String.Format("{0}-{1}", cmdletAttribute.VerbName, cmdletAttribute.NounName);

            var cmdlet = new Microsoft.CLU.InstalledCmdletInfo() { AssemblyName = assembly, CommandName = commandName, Keys = keys, Type = type };
            var help = Microsoft.CLU.Help.CmdletHelp.Generate(FormatParameterName, contentPath, assembly, cmdlet);

            return help;

        }
		/// <summary>
		/// Returns the xml qualified name for the specified system type id.
		/// </summary>
        /// <remarks>
        /// Returns the xml qualified name for the specified system type id.
        /// </remarks>
        /// <param name="systemType">The underlying type to query and return the Xml qualified name of</param>
        public static XmlQualifiedName GetXmlName(System.Type systemType)
		{
            if (systemType == null)
            {
                return null;
            }

            object[] attributes = systemType.GetTypeInfo().GetCustomAttributes(typeof(DataContractAttribute), true).ToArray();
            
            if (attributes != null)
            {
                for (int ii = 0; ii < attributes.Length; ii++)
                {
                    DataContractAttribute contract = attributes[ii] as DataContractAttribute;

                    if (contract != null)
                    {
                        if (String.IsNullOrEmpty(contract.Name))
                        {
                            return new XmlQualifiedName(systemType.Name, contract.Namespace);
                        }
                         
                        return new XmlQualifiedName(contract.Name, contract.Namespace);
                    }
                }                            
            }

            attributes = systemType.GetTypeInfo().GetCustomAttributes(typeof(CollectionDataContractAttribute), true).ToArray();
            
            if (attributes != null)
            {
                for (int ii = 0; ii < attributes.Length; ii++)
                {
                    CollectionDataContractAttribute contract = attributes[ii] as CollectionDataContractAttribute;

                    if (contract != null)
                    {
                        if (String.IsNullOrEmpty(contract.Name))
                        {
                            return new XmlQualifiedName(systemType.Name, contract.Namespace);
                        }
                         
                        return new XmlQualifiedName(contract.Name, contract.Namespace);
                    }
                }                            
            }
            
            return new XmlQualifiedName(systemType.FullName);
		}
Exemple #15
0
 private static string GetSimpleTypeName(System.Type ty)
 {
     return ty.GetTypeInfo().Assembly.GetName().Name + "." + ty.Name;
 }