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


C# Type.GetTypeInfo方法代码示例

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


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

示例1: CanConvert

        /// <summary>
        ///     Determines whether this instance can convert the specified object type.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns></returns>
        public override bool CanConvert(Type objectType)
        {
            if (typeof(IMessageNotification).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()))
                return true;

            return typeof(ICommentNotification).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
        }
开发者ID:DamienDennehy,项目名称:Imgur.API,代码行数:12,代码来源:NotificationConverter.cs

示例2: CreateExpressionNode

        /// <summary>
        /// Creates an instace of type <paramref name="nodeType"/>.
        /// </summary>
        /// <exception cref="ExpressionNodeInstantiationException">
        /// Thrown if the <paramref name="parseInfo"/> or the <paramref name="additionalConstructorParameters"/> 
        /// do not match expected constructor parameters of the <paramref name="nodeType"/>.
        /// </exception>
        public static IExpressionNode CreateExpressionNode(
        Type nodeType, MethodCallExpressionParseInfo parseInfo, object[] additionalConstructorParameters)
        {
            ArgumentUtility.CheckNotNull ("nodeType", nodeType);
              ArgumentUtility.CheckTypeIsAssignableFrom ("nodeType", nodeType, typeof (IExpressionNode));
              ArgumentUtility.CheckNotNull ("additionalConstructorParameters", additionalConstructorParameters);

            #if NETFX_CORE
              var constructors = nodeType.GetTypeInfo().DeclaredConstructors.Where (c => c.IsPublic).ToArray();
            #else
              var constructors = nodeType.GetTypeInfo().GetConstructors().Where (c => c.IsPublic).ToArray();
            #endif
              if (constructors.Length > 1)
              {
            var message = string.Format (
            "Expression node type '{0}' contains too many constructors. It must only contain a single constructor, allowing null to be passed for any optional arguments.",
            nodeType.FullName);
            throw new ArgumentException (message, "nodeType");
              }

              object[] constructorParameterArray = GetParameterArray (constructors[0], parseInfo, additionalConstructorParameters);
              try
              {
            return (IExpressionNode) constructors[0].Invoke (constructorParameterArray);
              }
              catch (ArgumentException ex)
              {
            var message = GetArgumentMismatchMessage (ex);
            throw new ExpressionNodeInstantiationException (message);
              }
        }
开发者ID:nicocrm,项目名称:DotNetSDataClient,代码行数:38,代码来源:MethodCallExpressionNodeFactory.cs

示例3: InvokeMemberOnType

        private static object InvokeMemberOnType(Type type, object target, string name, object[] args)
        {
            BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            try
            {
                // Try to invokethe method
                return type.InvokeMember(
                    name,
                    BindingFlags.InvokeMethod | bindingFlags,
                    null,
                    target,
                    args);
            }
            catch (MissingMethodException)
            {
                // If we couldn't find the method, try on the base class
                if (type.GetTypeInfo().BaseType != null)
                {
                    return InvokeMemberOnType(type.GetTypeInfo().BaseType, target, name, args);
                }
                //Don't care if the method don't exist.
                return null;
            }
        }
开发者ID:henningst,项目名称:coreclrplayground,代码行数:25,代码来源:Program.cs

示例4: checkGenericType

        private static bool checkGenericType(Type pluggedType, Type pluginType)
        {
            if (pluginType.GetTypeInfo().IsAssignableFrom(pluggedType.GetTypeInfo())) return true;

            // check interfaces
            foreach (var type in pluggedType.GetInterfaces())
            {
                if (!type.GetTypeInfo().IsGenericType)
                {
                    continue;
                }

                if (type.GetGenericTypeDefinition() == pluginType)
                {
                    return true;
                }
            }

            if (pluggedType.GetTypeInfo().BaseType.GetTypeInfo().IsGenericType)
            {
                var baseType = pluggedType.GetTypeInfo().BaseType.GetGenericTypeDefinition();

                if (baseType == pluginType)
                {
                    return true;
                }
                else
                {
                    return CanBeCast(pluginType, baseType);
                }
            }

            return false;
        }
开发者ID:e-tobi,项目名称:structuremap,代码行数:34,代码来源:GenericsPluginGraph.cs

示例5: Resolve

        /// <summary>
        /// Returns any bindings from the specified collection that match the specified service.
        /// </summary>
        /// <param name="bindings">The multimap of all registered bindings.</param>
        /// <param name="service">The service in question.</param>
        /// <returns>The series of matching bindings.</returns>
        public IEnumerable<IBinding> Resolve(IDictionary<Type, IEnumerable<IBinding>> bindings, Type service)
        {
            if (!service.GetTypeInfo().IsGenericType || service.GetTypeInfo().IsGenericTypeDefinition || !bindings.ContainsKey(service.GetGenericTypeDefinition()))
                return Enumerable.Empty<IBinding>();

            return bindings[service.GetGenericTypeDefinition()];
        }
开发者ID:LuckyStarry,项目名称:Ninject,代码行数:13,代码来源:OpenGenericBindingResolver.cs

示例6: GetSerializer

        internal IContentSerializer GetSerializer(Type storageType, Type objectType)
        {
            lock (contentSerializers)
            {
                // Process serializer attributes of objectType
                foreach (var contentSerializer in GetSerializers(objectType))
                {
                    if (objectType.GetTypeInfo().IsAssignableFrom(contentSerializer.ActualType.GetTypeInfo()) && (storageType == null || contentSerializer.SerializationType == storageType))
                        return contentSerializer;
                }

                // Process serializer attributes of storageType
                if (storageType != null)
                {
                    foreach (var contentSerializer in GetSerializers(storageType))
                    {
                        if (objectType.GetTypeInfo().IsAssignableFrom(contentSerializer.ActualType.GetTypeInfo()) && contentSerializer.SerializationType == storageType)
                            return contentSerializer;
                    }
                }

                //foreach (var contentSerializerGroup in contentSerializers)
                //{
                //    if (contentSerializerGroup.Key.GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()))
                //    {
                //        return GetSerializer(contentSerializerGroup.Value, storageType);
                //    }
                //}
            }

            throw new Exception(string.Format("Could not find a serializer for the type [{0}, {1}]", storageType == null ? null : storageType.Name, objectType == null ? null : objectType.Name));
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:32,代码来源:AssetSerializer.cs

示例7: GetSerializer

        internal IContentSerializer GetSerializer(Type storageType, Type objectType)
        {
            lock (contentSerializers)
            {
                // Process serializer attributes of objectType
                foreach (var contentSerializer in GetSerializers(objectType))
                {
                    if (objectType.GetTypeInfo().IsAssignableFrom(contentSerializer.ActualType.GetTypeInfo()) && (storageType == null || contentSerializer.SerializationType == storageType))
                        return contentSerializer;
                }

                // Process serializer attributes of storageType
                if (storageType != null)
                {
                    foreach (var contentSerializer in GetSerializers(storageType))
                    {
                        if (objectType.GetTypeInfo().IsAssignableFrom(contentSerializer.ActualType.GetTypeInfo()) && contentSerializer.SerializationType == storageType)
                            return contentSerializer;
                    }
                }

                //foreach (var contentSerializerGroup in contentSerializers)
                //{
                //    if (contentSerializerGroup.Key.GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()))
                //    {
                //        return GetSerializer(contentSerializerGroup.Value, storageType);
                //    }
                //}
            }

            return null;
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:32,代码来源:AssetSerializer.cs

示例8: FindGetters

		private Tuple<IList<MethodInfo>, IList<MethodInfo>> FindGetters(Type viewModelType)
		{
			Tuple<IList<MethodInfo>, IList<MethodInfo>> methodInfos;
			if (!_knownTypes.TryGetValue(viewModelType, out methodInfos))
			{
				var commandTypeInfo = typeof(ICommand).GetTypeInfo();
				var observablePropertyType = typeof(IObservableProperty<>);
				var ovvmTypeTypeInfo = typeof(IObservableViewModel).GetTypeInfo();
				var propertieGetters = viewModelType.GetTypeInfo()
												.DeclaredProperties
												.Where(p => commandTypeInfo.IsAssignableFrom(p.PropertyType.GetTypeInfo()) ||
															ovvmTypeTypeInfo.IsAssignableFrom(p.PropertyType.GetTypeInfo()) ||
															IsGenericTypeDefinitionProperty(p.PropertyType, observablePropertyType))
												.Select(p => p.GetMethod)
												.ToList();

				//find inner view models  recursively
				var viewModelTypeInfo = typeof(IViewModel).GetTypeInfo();
				var childrenGetters = viewModelType.GetTypeInfo()
												   .DeclaredProperties
												   .Where(p => viewModelTypeInfo.IsAssignableFrom(p.PropertyType.GetTypeInfo()))
												   .Select(p => p.GetMethod)
												   .ToList();

				methodInfos = new Tuple<IList<MethodInfo>, IList<MethodInfo>>(propertieGetters, childrenGetters);
				_knownTypes.Add(viewModelType, methodInfos);
			}
			return methodInfos;
		}
开发者ID:Galad,项目名称:Hanno,代码行数:29,代码来源:CreateCommandsAndOvvmViewModelFactory.cs

示例9: DoesTypeMeetGenericConstraints

        /// <summary>
        /// A helper to check to see if a generic parameter type meets the specified constraints
        /// </summary>
        /// <param name="genericParameterType">The generic parameter type</param>
        /// <param name="exported">The type parameter on the exported class</param>
        /// <returns>True if the type meets the constraints, otherwise false</returns>
        public static bool DoesTypeMeetGenericConstraints(Type genericParameterType, Type exported)
        {
            bool meets = true;
            var constraints = genericParameterType.GetTypeInfo().GetGenericParameterConstraints();

            foreach (Type constraint in constraints)
            {
                if (constraint.GetTypeInfo().IsInterface)
                {
                    if (exported.GetTypeInfo().GUID == constraint.GetTypeInfo().GUID)
                    {
                        continue;
                    }

                    if (exported.GetTypeInfo().ImplementedInterfaces.Any(x => x.GetTypeInfo().GUID == constraint.GetTypeInfo().GUID))
                    {
                        continue;
                    }

                    meets = false;
                    break;
                }

                if (!constraint.GetTypeInfo().IsAssignableFrom(exported.GetTypeInfo()))
                {
                    meets = false;
                    break;
                }
            }

            return meets;
        }
开发者ID:jrjohn,项目名称:Grace,代码行数:38,代码来源:OpenGenericUtilities.cs

示例10: IsValidRazorFileInfoCollection

 public static bool IsValidRazorFileInfoCollection(Type type)
 {
     return 
         RazorFileInfoCollectionType.IsAssignableFrom(type) &&
         !type.GetTypeInfo().IsAbstract &&
         !type.GetTypeInfo().ContainsGenericParameters;
 }
开发者ID:ryanbrandenburg,项目名称:Mvc,代码行数:7,代码来源:RazorFileInfoCollections.cs

示例11: GetGenericInterface

        public Type GetGenericInterface(Type type, Type interfaceType)
        {
            if (!interfaceType.GetTypeInfo().IsGenericTypeDefinition)
            {
                throw new ArgumentException(
                    "The interface must be a generic interface definition: " + interfaceType.Name,
                    "interfaceType");
            }

            // our contract states that we will not return generic interface definitions without generic type arguments
            if (type == interfaceType)
                return null;
            if (type.GetTypeInfo().IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == interfaceType)
                    return type;
            }
            Type[] interfaces = type.GetTypeInfo().ImplementedInterfaces.ToArray();
            for (int i = 0; i < interfaces.Length; i++)
            {
                if (interfaces[i].GetTypeInfo().IsGenericType)
                {
                    if (interfaces[i].GetGenericTypeDefinition() == interfaceType)
                        return interfaces[i];
                }
            }

            return null;
        }
开发者ID:kinpro,项目名称:RapidTransit,代码行数:29,代码来源:InterfaceReflectionCache.cs

示例12: GenerateProxy

        private static ProxyGeneratorResult GenerateProxy(
            Type typeOfProxy,
            ProxyGenerationOptions options,
            IEnumerable<Type> additionalInterfacesToImplement,
            IEnumerable<object> argumentsForConstructor,
            IFakeCallProcessorProvider fakeCallProcessorProvider)
        {
            Guard.AgainstNull(typeOfProxy, nameof(typeOfProxy));
            Guard.AgainstNull(additionalInterfacesToImplement, nameof(additionalInterfacesToImplement));
            Guard.AgainstNull(fakeCallProcessorProvider, nameof(fakeCallProcessorProvider));

            if (typeOfProxy.GetTypeInfo().IsValueType)
            {
                return GetProxyResultForValueType(typeOfProxy);
            }

            if (typeOfProxy.GetTypeInfo().IsSealed)
            {
                return new ProxyGeneratorResult(DynamicProxyResources.ProxyIsSealedTypeMessage.FormatInvariant(typeOfProxy));
            }

            GuardAgainstConstructorArgumentsForInterfaceType(typeOfProxy, argumentsForConstructor);

            return CreateProxyGeneratorResult(typeOfProxy, options, additionalInterfacesToImplement, argumentsForConstructor, fakeCallProcessorProvider);
        }
开发者ID:bman61,项目名称:FakeItEasy,代码行数:25,代码来源:CastleDynamicProxyGenerator.cs

示例13: ReadController

        public ActionsGroupNode ReadController(Type type, AssemblyNode assemblyNode)
        {
            var controller = new ActionsGroupNode
            {
                Assembly = assemblyNode
            };

            string routePrefix = null;
            var routePrefixAttribute = type.GetTypeInfo().GetCustomAttribute<RouteAttribute>(false) ?? type.GetTypeInfo().GetCustomAttribute<RouteAttribute>();
            if (routePrefixAttribute != null)
            {
                routePrefix = routePrefixAttribute.Template;
            }

            controller.Name = type.Name.Replace("Controller", string.Empty);
            controller.Name = NameCleaner.Replace(controller.Name, string.Empty);
            controller.Documentation = documentation.GetDocumentation(type);

            foreach (var methodInfo in type.GetMethods().Where(x => x.IsPublic))
            {
                if (methodInfo.GetCustomAttribute<NonActionAttribute>() != null) continue;
                if (methodInfo.IsSpecialName) continue;

                var action = ReadAction(routePrefix, methodInfo, controller);
                if (action != null)
                {
                    controller.Actions.Add(action);
                }
            }
            return controller;
        }
开发者ID:folkelib,项目名称:Folke.CsTsService,代码行数:31,代码来源:Converter.cs

示例14: EnumDescriptor

            public EnumDescriptor(Type type)
            {
                _type = type;
                _enum2name = new Dictionary<object, string>();
                _name2enum = new Dictionary<string, object>();

                var names = Enum.GetNames(type);

                foreach (string name in names)
                {
                    #if NET40
                    var member = type.GetFields().Single(x => x.Name == name);
                    #elif !PCL
                    var member = type.GetTypeInfo().GetRuntimeFields().Single((x) => x.Name == name);
                    #else
                    var member = type.GetTypeInfo().GetDeclaredField(name);
                    #endif
                    var value = Enum.Parse(type, name);
                    var realName = name;

                    #if NET40
                    var attr = (EnumValueAttribute)member.GetCustomAttributes(typeof(EnumValueAttribute), false).FirstOrDefault();
                    #else
                    var attr = member.GetCustomAttribute<EnumValueAttribute>();
                    #endif

                    if (attr != null)
                        realName = attr.Value;

                    _enum2name[value] = realName;
                    _name2enum[realName] = value;
                }
            }
开发者ID:thalesmello,项目名称:pagarme-net,代码行数:33,代码来源:EnumMagic.cs

示例15: GetConverter

		/// <summary>
		/// Gets the type converter for the specified type.
		/// </summary>
		/// <returns>The type converter, or null if the type has no defined converter.</returns>
		/// <param name="type">Type to get the converter for.</param>
		public static TypeConverter GetConverter(Type type)
		{
			var attr = type.GetTypeInfo().GetCustomAttribute<TypeConverterAttribute>();
			Type converterType = null;
			if (attr != null)
				converterType = Type.GetType(attr.ConverterTypeName);
			if (converterType == null)
			{
				if (!converters.TryGetValue(type, out converterType))
				{
					if (type.GetTypeInfo().IsGenericType && type.GetTypeInfo().GetGenericTypeDefinition() == typeof(Nullable<>))
						return new NullableConverter(type);
					if (type.GetTypeInfo().IsEnum)
						return new EnumConverter(type);
					if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
						return new EventConverter();
				}
			}
			
			if (converterType != null)
			{
				if (converterType.GetTypeInfo().GetConstructors().Any(r => r.GetParameters().Select(p => p.ParameterType).SequenceEqual(new [] { typeof(Type) })))
					return Activator.CreateInstance(converterType, type) as TypeConverter;
				return Activator.CreateInstance(converterType) as TypeConverter;
			}
			
			return null;
		}
开发者ID:wieslawsoltes,项目名称:Portable.Xaml,代码行数:33,代码来源:TypeDescriptor.cs


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