当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetTypeInfo方法代码示例

本文整理汇总了C#中Type.GetTypeInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetTypeInfo方法的具体用法?C# Type.GetTypeInfo怎么用?C# Type.GetTypeInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetTypeInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSerializableFields

        private static FieldInfo[] GetSerializableFields(Type type)
        {
            if (type.GetTypeInfo().IsInterface)
            {
                return Array.Empty<FieldInfo>();
            }

            if (!type.GetTypeInfo().IsSerializable)
            {
                throw new SerializationException(SR.Format(SR.Serialization_NonSerType, type.GetTypeInfo().FullName, type.GetTypeInfo().Assembly.FullName));
            }

            var results = new List<FieldInfo>();
            for (Type t = type; t != typeof(object); t = t.GetTypeInfo().BaseType)
            {
                foreach (FieldInfo field in t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    if ((field.Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                    {
                        results.Add(field);
                    }
                }
            }
            return results.ToArray();
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:25,代码来源:FormatterServices.cs

示例2: ToCode

 internal static InternalPrimitiveTypeE ToCode(Type type) =>
         type == null ? ToPrimitiveTypeEnum(TypeCode.Empty) :
         type.GetTypeInfo().IsPrimitive ? ToPrimitiveTypeEnum(type.GetTypeCode()) :
         ReferenceEquals(type, s_typeofDateTime) ? InternalPrimitiveTypeE.DateTime :
         ReferenceEquals(type, s_typeofTimeSpan) ? InternalPrimitiveTypeE.TimeSpan :
         ReferenceEquals(type, s_typeofDecimal) ? InternalPrimitiveTypeE.Decimal :
         InternalPrimitiveTypeE.Invalid;
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:Converter.cs

示例3: IsTypeReferenceable

 private static bool IsTypeReferenceable(Type type)
 {
     Type itemType;
     return (type.GetTypeInfo().IsEnum ||
             type.GetTypeInfo().IsDefined(Globals.TypeOfDataContractAttribute, false) ||
             (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) && !type.GetTypeInfo().IsGenericTypeDefinition) ||
             CollectionDataContract.IsCollection(type, out itemType) ||
             ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:DataContractSet.cs

示例4: ValidateType

 public static void ValidateType(Type type, string paramName)
 {
     if (type != typeof(void))
     {
         // A check to avoid a bunch of reflection (currently not supported) during cctor
         if (type.GetTypeInfo().ContainsGenericParameters)
         {
             throw type.GetTypeInfo().IsGenericTypeDefinition ? Error.TypeIsGeneric(type, paramName) : Error.TypeContainsGenericParameters(type, paramName);
         }
     }
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:TypeUtils.cs

示例5: AreReferenceAssignable

 public static bool AreReferenceAssignable(Type dest, Type src)
 {
     // This actually implements "Is this identity assignable and/or reference assignable?"
     if (AreEquivalent(dest, src))
     {
         return true;
     }
     if (!dest.GetTypeInfo().IsValueType && !src.GetTypeInfo().IsValueType && dest.GetTypeInfo().IsAssignableFrom(src.GetTypeInfo()))
     {
         return true;
     }
     return false;
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:13,代码来源:TypeUtils.cs

示例6: GetDefaultValueIfAny

        public static bool GetDefaultValueIfAny(MemberType memberType, MetadataReader reader, Handle constantHandle, Type declaredType, IEnumerable<CustomAttributeData> customAttributes, out Object defaultValue)
        {
            if (!(constantHandle.IsNull(reader)))
            {
                defaultValue = ParseMetadataConstant(reader, constantHandle);
                if (declaredType.GetTypeInfo().IsEnum)
                    defaultValue = Enum.ToObject(declaredType, defaultValue);
                return true;
            }

            if (memberType != MemberType.Property)  // the attributes in question cannot be applied to properties.
            {
                // Legacy: If there are multiple default value attribute, the desktop picks one at random (and so do we...)
                foreach (CustomAttributeData cad in customAttributes)
                {
                    Type attributeType = cad.AttributeType;
                    TypeInfo attributeTypeInfo = attributeType.GetTypeInfo();
                    if (attributeTypeInfo.IsSubclassOf(typeof(CustomConstantAttribute)))
                    {
                        CustomConstantAttribute customConstantAttribute = (CustomConstantAttribute)(cad.Instantiate());
                        defaultValue = customConstantAttribute.Value;
                        return true;
                    }
                    if (attributeType.Equals(typeof(DecimalConstantAttribute)))
                    {
                        DecimalConstantAttribute decimalConstantAttribute = (DecimalConstantAttribute)(cad.Instantiate());
                        defaultValue = decimalConstantAttribute.Value;
                        return true;
                    }
                }
            }

            defaultValue = null;
            return false;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:DefaultValueParser.cs

示例7: TryResolveType

        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (type == null)
            {
                typeName = null;
                typeNamespace = null;
                return false;
            }
            if (declaredType != null && declaredType.GetTypeInfo().IsInterface && CollectionDataContract.IsCollectionInterface(declaredType))
            {
                typeName = null;
                typeNamespace = null;
                return true;
            }

            DataContract contract = DataContract.GetDataContract(type);
            if (_context.IsKnownType(contract, contract.KnownDataContracts, declaredType))
            {
                typeName = contract.Name;
                typeNamespace = contract.Namespace;
                return true;
            }
            else
            {
                typeName = null;
                typeNamespace = null;
                return false;
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:29,代码来源:KnownTypeDataContractResolver.cs

示例8: GetProxyType

        private static Type GetProxyType(Type type)
        {
            // Get the DebuggerTypeProxyAttibute for obj
            var attrs =
                type.GetTypeInfo().CustomAttributes
                .Where(a => a.AttributeType == typeof(DebuggerTypeProxyAttribute))
                .ToArray();
            if (attrs.Length != 1)
            {
                throw new InvalidOperationException(
                    string.Format("Expected one DebuggerTypeProxyAttribute on {0}.", type));
            }
            CustomAttributeData cad = attrs[0];

            // Get the proxy type.  As written, this only works if the proxy and the target type
            // have the same generic parameters, e.g. Dictionary<TKey,TValue> and Proxy<TKey,TValue>.
            // It will not work with, for example, Dictionary<TKey,TValue>.Keys and Proxy<TKey>,
            // as the former has two generic parameters and the latter only one.
            Type proxyType = cad.ConstructorArguments[0].ArgumentType == typeof(Type) ?
                (Type)cad.ConstructorArguments[0].Value :
                Type.GetType((string)cad.ConstructorArguments[0].Value);
            var genericArguments = type.GenericTypeArguments;
            if (genericArguments.Length > 0)
            {
                proxyType = proxyType.MakeGenericType(genericArguments);
            }

            return proxyType;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:DebuggerAttributes.cs

示例9: IsWinRTType

 internal static bool IsWinRTType(Type type)
 {
     // All WinRT Types would contain the Attributes flag set to TypeAttributes.WindowsRuntime
     // TypeAttributes.WindowsRuntime is part of CLR 4.5. Inorder to build PowerShell for
     // CLR 4.0, a string comparison for the for the existence of TypeAttributes.WindowsRuntime
     // in the Attributes flag is performed rather than the actual bitwise comparison.
     return type.GetTypeInfo().Attributes.ToString().Contains("WindowsRuntime");
 }
开发者ID:40a,项目名称:PowerShell,代码行数:8,代码来源:IInspectable.cs

示例10: String_Type_TypeArray_Type

        public void String_Type_TypeArray_Type(string name, Type returnType, Type[] parameterTypes, Type owner)
        {
            DynamicMethod method1 = new DynamicMethod(name, returnType, parameterTypes, owner);
            Helpers.VerifyMethod(method1, name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner.GetTypeInfo().Module);

            DynamicMethod method2 = new DynamicMethod(name, returnType, parameterTypes, owner, true);
            Helpers.VerifyMethod(method2, name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner.GetTypeInfo().Module);

            DynamicMethod method3 = new DynamicMethod(name, returnType, parameterTypes, owner, false);
            Helpers.VerifyMethod(method3, name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner.GetTypeInfo().Module);

            DynamicMethod method4 = new DynamicMethod(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner, true);
            Helpers.VerifyMethod(method4, name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner.GetTypeInfo().Module);

            DynamicMethod method5 = new DynamicMethod(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner, false);
            Helpers.VerifyMethod(method5, name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner.GetTypeInfo().Module);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:17,代码来源:DynamicMethodCtor.cs

示例11: Excute

    /// <summary>
    /// Excutes the specified test assembly.
    /// </summary>
    /// <param name="t">The t.</param>
    public static void Excute(Type t) {
#if NETFULL
        var dataAccess = t.Assembly;
#else
        var dataAccess = t.GetTypeInfo().Assembly;
#endif

        IList<ExecuteFunc> list = new List<ExecuteFunc>();

        foreach (var type in dataAccess.GetTypes()) {
            var clazz = type.GetConstructor(Type.EmptyTypes);
            if (clazz == null) continue;
            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) {
                var attr = method.GetCustomAttributes(typeof(DemoAttribute), false).FirstOrDefault() as DemoAttribute;
                if (attr != null) {
                    object instance = Activator.CreateInstance(type);
                    ExecuteFunc func = new ExecuteFunc(instance, method, attr.Description);
                    list.Add(func);
                }
            }
        }

        if (list.Count > 0) {
            StringBuilder text = new StringBuilder();

            lrTag("Select the use-case", "-", 20);

            for (int i = 0; i < list.Count; i++) {
                text.AppendFormat("[{0}] {1}{2}", i + 1, list[i], Environment.NewLine);
            }

            text.AppendLine("\r\n[0] \texit. ");
            string _display = text.ToString();

            Console.Out.WriteLine(ConsoleColor.Green, _display);
            Console.Out.Write("select>");
            string input = Console.ReadLine();
            while (input != "0" && input != "quit" && input != "q" && input != "exit") {
                if (input.Equals("cls", StringComparison.OrdinalIgnoreCase)) {
                    Console.Clear();
                }
                int idx;
                if (int.TryParse(input, out idx)) {
                    if (idx > 0 && idx <= list.Count) {
                        Console.Clear();
                        Console.Out.WriteLine(ConsoleColor.DarkCyan, list[idx - 1] + " Running...");
                        list[idx - 1].Execute();
                        Console.Out.WriteLine(ConsoleColor.DarkCyan, list[idx - 1] + " Complete...");
                    }
                }
                Console.Out.WriteLine();
                lrTag("Select the use-case", "-", 20);
                Console.Out.WriteLine(ConsoleColor.Green, _display);
                Console.Out.Write("select>");
                input = Console.ReadLine();
            }
        }
    }
开发者ID:EsWork,项目名称:Es.Logging,代码行数:62,代码来源:DemoExcute.cs

示例12: GetValue_ThrowsTargetParameterCountException

        public static void GetValue_ThrowsTargetParameterCountException(string propertyName, Type type, object[]testObj)
        {
            object obj = Activator.CreateInstance(type);
            PropertyInfo pi = type.GetTypeInfo().GetProperty(propertyName);

            Assert.Equal(propertyName, pi.Name);

            Assert.Throws<TargetParameterCountException>(() => pi.GetValue(obj, testObj));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:PropertyInfo_GetSetValueTests.cs

示例13: IsInstanceOfType

        internal static bool IsInstanceOfType(object o, Type type)
        {
            Debug.Assert(type != null);

            if (o == null)
                return false;

            return type.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
        }
开发者ID:Corillian,项目名称:corefx,代码行数:9,代码来源:XHelper.cs

示例14: Create

        internal static object Create(Type tInterface, OrderedDictionary<Type, List<MethodInfo, MethodInfo>> instanceMethods, List<Delegate, MethodInfo> delegateMethods, List<MethodInfo> stubMethods, List<Type, object> usedInstances) {
            // now we can calculate the key based on the content of the *Methods collections
            var key = tInterface.GetTypeInfo().Assembly.FullName + "::" + tInterface.Name + ":::" + instanceMethods.Keys.Select(each => each.GetTypeInfo().Assembly.FullName + "." + each.FullName + "." + instanceMethods[each].Select(mi => mi.Value.ToSignatureString()).JoinWithComma()).JoinWith(";\r\n") +
                      "::" + delegateMethods.Select(each => each.GetType().FullName).JoinWith(";\r\n") +
                      "::" + stubMethods.Select(mi => mi.ToSignatureString()).JoinWithComma();
            // + "!->" + (onUnhandledExceptionMethod == null ? (onUnhandledExceptionDelegate == null ? "GenerateOnUnhandledException" : onUnhandledExceptionDelegate.ToString()) : onUnhandledExceptionMethod.ToSignatureString());

            return _proxyClassDefinitions.GetOrAdd(key, () => new DynamicType(tInterface, instanceMethods, delegateMethods, stubMethods)).CreateInstance(usedInstances, delegateMethods);
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:9,代码来源:DynamicTypeCoreClr.cs

示例15: GetNullableType

 public static Type GetNullableType(Type type)
 {
     Debug.Assert(type != null, "type cannot be null");
     if (type.GetTypeInfo().IsValueType && !IsNullableType(type))
     {
         return typeof(Nullable<>).MakeGenericType(type);
     }
     return type;
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:9,代码来源:TypeUtils.cs


注:本文中的Type.GetTypeInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。