• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Reflection.TypeInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TypeInfo类属于System.Reflection命名空间,在下文中一共展示了TypeInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetConstructors

 public static ConstructorInfo[] GetConstructors(TypeInfo typeInfo, bool nonPublic = false)
 {
     if (nonPublic)
         return typeInfo.DeclaredConstructors.ToArray();
     return
         typeInfo.DeclaredConstructors.Where(x => x.IsPublic).ToArray();
 }
开发者ID:rudimk,项目名称:HAMMER,代码行数:7,代码来源:TypeExtensions.cs


示例2: GetComponentFullName

        public static string GetComponentFullName(TypeInfo componentType)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            var attribute = componentType.GetCustomAttribute<ViewComponentAttribute>();
            if (!string.IsNullOrEmpty(attribute?.Name))
            {
                return attribute.Name;
            }

            // If the view component didn't define a name explicitly then use the namespace + the
            // 'short name'.
            var shortName = GetShortNameByConvention(componentType);
            if (string.IsNullOrEmpty(componentType.Namespace))
            {
                return shortName;
            }
            else
            {
                return componentType.Namespace + "." + shortName;
            }
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:25,代码来源:ViewComponentConventions.cs


示例3: IsValid

        private static bool IsValid(Type type, TypeInfo typeInfo)
        {
            if (!ReferenceEquals(null, type))
            {
                if (typeInfo.IsArray)
                {
                    type = type.GetElementType();
                }

                if (typeInfo.IsAnonymousType || type.IsAnonymousType())
                {
                    var properties = type.GetProperties().Select(x => x.Name).ToList();
                    var propertyNames = typeInfo.Properties.Select(x => x.Name).ToList();

                    var match =
                        type.IsAnonymousType() &&
                        typeInfo.IsAnonymousType &&
                        properties.Count == propertyNames.Count &&
                        propertyNames.All(x => properties.Contains(x));

                    if (!match)
                    {
                        return false;
                    }
                }

                return true;
            }

            return false;
        }
开发者ID:6bee,项目名称:aqua-core,代码行数:31,代码来源:TypeResolver.cs


示例4: FormatNonGenericTypeName

        private static string FormatNonGenericTypeName(TypeInfo typeInfo, CommonTypeNameFormatterOptions options)
        {
            if (options.ShowNamespaces)
            {
                return typeInfo.FullName.Replace('+', '.');
            }

            if (typeInfo.DeclaringType == null)
            {
                return typeInfo.Name;
            }

            var stack = ArrayBuilder<string>.GetInstance();

            do
            {
                stack.Push(typeInfo.Name);
                typeInfo = typeInfo.DeclaringType?.GetTypeInfo();
            } while (typeInfo != null);

            stack.ReverseContents();
            var typeName = string.Join(".", stack);
            stack.Free();

            return typeName;
        }
开发者ID:binsys,项目名称:roslyn,代码行数:26,代码来源:CommonTypeNameFormatter.cs


示例5: FindSyncMethod

        public static MethodInfo FindSyncMethod(TypeInfo componentType, object[] args)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            var method = GetMethod(componentType, args, SyncMethodName);
            if (method == null)
            {
                return null;
            }

            if (method.ReturnType == typeof(void))
            {
                throw new InvalidOperationException(
                    Resources.FormatViewComponent_SyncMethod_ShouldReturnValue(SyncMethodName));
            }
            else if (method.ReturnType.IsAssignableFrom(typeof(Task)))
            {
                throw new InvalidOperationException(
                    Resources.FormatViewComponent_SyncMethod_CannotReturnTask(SyncMethodName, nameof(Task)));
            }

            return method;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:26,代码来源:ViewComponentMethodSelector.cs


示例6: CloseGenericExport

 public override DiscoveredExport CloseGenericExport(TypeInfo closedPartType, Type[] genericArguments)
 {
     var closedContractType = Contract.ContractType.MakeGenericType(genericArguments);
     var newContract = Contract.ChangeType(closedContractType);
     var property = closedPartType.AsType().GetRuntimeProperty(_property.Name);
     return new DiscoveredPropertyExport(newContract, Metadata, property);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:DiscoveredPropertyExport.cs


示例7: InheritsOrImplements

        public static bool InheritsOrImplements(this TypeInfo child, TypeInfo parent)
        {
            if (child == null || parent == null)
                return false;

            parent = resolveGenericTypeDefinition(parent);

            var currentChild = child.IsGenericType
                                   ? child.GetGenericTypeDefinition().GetTypeInfo()
                                   : child;

            while (currentChild != typeof(object).GetTypeInfo())
            {
                if (parent == currentChild || hasAnyInterfaces(parent, currentChild))
                    return true;

                currentChild = currentChild.BaseType != null
                               && currentChild.BaseType.GetTypeInfo().IsGenericType
                                   ? currentChild.BaseType.GetTypeInfo().GetGenericTypeDefinition().GetTypeInfo()
                                   : currentChild.BaseType.GetTypeInfo();

                if (currentChild == null)
                    return false;
            }
            return false;
        }
开发者ID:Banane9,项目名称:SilverConfig,代码行数:26,代码来源:Util.cs


示例8: FindSyncMethod

        /// <summary>
        /// Finds a synchronous method to execute.
        /// </summary>
        /// <param name="context">The widget context.</param>
        /// <param name="widgetType">The widget type.</param>
        /// <returns>The synchronous method.</returns>
        public static MethodInfo FindSyncMethod(WidgetContext context, TypeInfo widgetType)
        {
            string httpMethod = ResolveHttpMethod(context);
            string state = string.Empty; // Resolve a widget state?
            MethodInfo method = null;

            for (int i = 0; i < SyncMethodNames.Length; i++)
            {
                string name = string.Format(SyncMethodNames[i], state, httpMethod);
                method = GetMethod(name, widgetType);
                if (method != null)
                {
                    break;
                }
            }

            if (method == null)
            {
                return null;
            }

            if (method.ReturnType == typeof(void))
            {
                throw new InvalidOperationException($"Sync method '{method.Name}' should return a value.");
            }

            if (method.ReturnType.IsAssignableFrom(typeof(Task)))
            {
                throw new InvalidOperationException($"Sync method '{method.Name}' cannot return a task.");
            }

            return method;
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:39,代码来源:WidgetMethodSelector.cs


示例9: DiscoverPropertyExports

        private IEnumerable<DiscoveredExport> DiscoverPropertyExports(TypeInfo partType)
        {
            var partTypeAsType = partType.AsType();
            foreach (var property in partTypeAsType.GetRuntimeProperties()
                .Where(pi => pi.CanRead && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic))
            {
                foreach (var export in _attributeContext.GetDeclaredAttributes<ExportAttribute>(partTypeAsType, property))
                {
                    IDictionary<string, object> metadata = new Dictionary<string, object>();
                    ReadMetadataAttribute(export, metadata);

                    var applied = _attributeContext.GetDeclaredAttributes(partTypeAsType, property);
                    ReadLooseMetadata(applied, metadata);

                    var contractType = export.ContractType ?? property.PropertyType;
                    CheckPropertyExportCompatibility(partType, property, contractType.GetTypeInfo());

                    var exportKey = new CompositionContract(export.ContractType ?? property.PropertyType, export.ContractName);

                    if (metadata.Count == 0)
                        metadata = s_noMetadata;

                    yield return new DiscoveredPropertyExport(exportKey, metadata, property);
                }
            }
        }
开发者ID:benpye,项目名称:corefx,代码行数:26,代码来源:TypeInspector.cs


示例10: CreateMethod

        private static TestMethod CreateMethod(TypeInfo type, object instance, MethodInfo method)
        {
            TestMethod test = new TestMethod();
            test.Name = method.Name;

            if (method.GetCustomAttribute<AsyncTestMethodAttribute>(true) != null)
            {
                test.Test = new AsyncTestMethodAsyncAction(instance, method);                
            }
            else
            {
                test.Test = new TestMethodAsyncAction(instance, method);
            }

            ExcludeTestAttribute excluded = method.GetCustomAttribute<ExcludeTestAttribute>(true);
            if (excluded != null)
            {
                test.Exclude(excluded.Reason);
            }

            if (method.GetCustomAttribute<FunctionalTestAttribute>(true) != null)
            {
                test.Tags.Add("Functional");
            }

            test.Tags.Add(type.FullName + "." + method.Name);
            test.Tags.Add(type.Name + "." + method.Name);
            foreach (TagAttribute attr in method.GetCustomAttributes<TagAttribute>(true))
            {
                test.Tags.Add(attr.Tag);
            }

            return test;
        }
开发者ID:TroyBolton,项目名称:azure-mobile-services,代码行数:34,代码来源:TestDiscovery.cs


示例11: FindAsyncMethod

        /// <summary>
        /// Finds an asynchronous method to execute.
        /// </summary>
        /// <param name="context">The widget context.</param>
        /// <param name="widgetType">The widget type.</param>
        /// <returns>The asynchronous method.</returns>
        public static MethodInfo FindAsyncMethod(WidgetContext context, TypeInfo widgetType)
        {
            string httpMethod = ResolveHttpMethod(context);
            string state = string.Empty; // Resolve a widget state?
            MethodInfo method = null;

            for (int i = 0; i < AsyncMethodNames.Length; i++)
            {
                string name = string.Format(AsyncMethodNames[i], state, httpMethod);
                method = GetMethod(name, widgetType);
                if (method != null)
                {
                    break;
                }
            }

            if (method == null)
            {
                return null;
            }

            if (!method.ReturnType.GetTypeInfo().IsGenericType
                || method.ReturnType.GetGenericTypeDefinition() != typeof(Task<>))
            {
                throw new InvalidOperationException($"Async method '{method.Name}' must return a task.");
            }

            return method;
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:35,代码来源:WidgetMethodSelector.cs


示例12: HandlerDescriptor

        public HandlerDescriptor(TypeInfo handlerType, DispatchingPriority priority)
        {
            Argument.IsNotNull(handlerType, nameof(handlerType));

            HandlerType = handlerType;
            Priority = priority;
        }
开发者ID:Ontropix,项目名称:CQRSalad,代码行数:7,代码来源:HandlerDescriptor.cs


示例13: IsSupportedPrimitive

 protected static bool IsSupportedPrimitive(TypeInfo typeInfo)
 {
     return typeInfo.IsPrimitive
         || typeInfo.IsEnum
         || typeInfo == typeof(string).GetTypeInfo()
         || IsNullable(typeInfo.AsType());
 }
开发者ID:nbarbettini,项目名称:FlexibleConfiguration,代码行数:7,代码来源:ObjectVisitor.cs


示例14: ControllerModel

        public ControllerModel(
            TypeInfo controllerType,
            IReadOnlyList<object> attributes)
        {
            if (controllerType == null)
            {
                throw new ArgumentNullException(nameof(controllerType));
            }

            if (attributes == null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }

            ControllerType = controllerType;

            Actions = new List<ActionModel>();
            ApiExplorer = new ApiExplorerModel();
            Attributes = new List<object>(attributes);
            ControllerProperties = new List<PropertyModel>();
            Filters = new List<IFilterMetadata>();
            Properties = new Dictionary<object, object>();
            RouteValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            Selectors = new List<SelectorModel>();
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:25,代码来源:ControllerModel.cs


示例15: BuildTagHelperDescriptors

        private static IEnumerable<TagHelperDescriptor> BuildTagHelperDescriptors(
            TypeInfo typeInfo,
            string assemblyName,
            IEnumerable<TagHelperAttributeDescriptor> attributeDescriptors,
            IEnumerable<TargetElementAttribute> targetElementAttributes)
        {
            var typeName = typeInfo.FullName;

            // If there isn't an attribute specifying the tag name derive it from the name
            if (!targetElementAttributes.Any())
            {
                var name = typeInfo.Name;

                if (name.EndsWith(TagHelperNameEnding, StringComparison.OrdinalIgnoreCase))
                {
                    name = name.Substring(0, name.Length - TagHelperNameEnding.Length);
                }

                return new[]
                {
                    BuildTagHelperDescriptor(
                        ToHtmlCase(name),
                        typeName,
                        assemblyName,
                        attributeDescriptors,
                        requiredAttributes: Enumerable.Empty<string>())
                };
            }

            return targetElementAttributes.Select(
                attribute => BuildTagHelperDescriptor(typeName, assemblyName, attributeDescriptors, attribute));
        }
开发者ID:billwaddyjr,项目名称:Razor,代码行数:32,代码来源:TagHelperDescriptorFactory.cs


示例16: ControllerModel

        public ControllerModel(
            TypeInfo controllerType,
            IReadOnlyList<object> attributes)
        {
            if (controllerType == null)
            {
                throw new ArgumentNullException(nameof(controllerType));
            }

            if (attributes == null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }

            ControllerType = controllerType;

            Actions = new List<ActionModel>();
            ApiExplorer = new ApiExplorerModel();
            Attributes = new List<object>(attributes);
            AttributeRoutes = new List<AttributeRouteModel>();
            ActionConstraints = new List<IActionConstraintMetadata>();
            Filters = new List<IFilterMetadata>();
            RouteConstraints = new List<IRouteConstraintProvider>();
            Properties = new Dictionary<object, object>();
            ControllerProperties = new List<PropertyModel>();
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:26,代码来源:ControllerModel.cs


示例17: AddController

 public void AddController(TypeInfo controllerTypeInfo)
 {
     if (IsValidController(controllerTypeInfo))
     {
         ControllersType.Add(controllerTypeInfo);
     }
 }
开发者ID:kyrylovych,项目名称:zstu-docs,代码行数:7,代码来源:ControllerTypeRegistrator.cs


示例18: TypesToTypeInfos

 static TypeInfo[] TypesToTypeInfos(Type[] types)
 {
     TypeInfo[] result = new TypeInfo[types.Length];
     for (int i = 0; i < types.Length; i++)
         result[i] = types[i].GetTypeInfo();
     return result;
 }
开发者ID:noahfalk,项目名称:corert,代码行数:7,代码来源:ConstraintValidator.cs


示例19: EntityProcessor

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityProcessor"/> class.
        /// </summary>
        /// <param name="mainComponentType">Type of the main component.</param>
        /// <param name="additionalTypes">The additional types required by this processor.</param>
        /// <exception cref="System.ArgumentNullException">If parameteters are null</exception>
        /// <exception cref="System.ArgumentException">If a type does not inherit from EntityComponent</exception>
        protected EntityProcessor(Type mainComponentType, Type[] additionalTypes)
        {
            if (mainComponentType == null) throw new ArgumentNullException(nameof(mainComponentType));
            if (additionalTypes == null) throw new ArgumentNullException(nameof(additionalTypes));

            MainComponentType = mainComponentType;
            mainTypeInfo = MainComponentType.GetTypeInfo();
            Enabled = true;

            RequiredTypes = new TypeInfo[additionalTypes.Length];

            // Check that types are valid
            for (int i = 0; i < additionalTypes.Length; i++)
            {
                var requiredType = additionalTypes[i];
                if (!typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(requiredType.GetTypeInfo()))
                {
                    throw new ArgumentException($"Invalid required type [{requiredType}]. Expecting only an EntityComponent type");
                }

                RequiredTypes[i] = requiredType.GetTypeInfo();
            }

            if (RequiredTypes.Length > 0)
            {
                componentTypesSupportedAsRequired = new Dictionary<TypeInfo, bool>();
            }

            UpdateProfilingKey = new ProfilingKey(GameProfilingKeys.GameUpdate, this.GetType().Name);
            DrawProfilingKey = new ProfilingKey(GameProfilingKeys.GameDraw, this.GetType().Name);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:38,代码来源:EntityProcessor.cs


示例20: EnsureSatisfiesClassConstraints

        static void EnsureSatisfiesClassConstraints(TypeInfo[] typeParameters, TypeInfo[] typeArguments, object definition, SigTypeContext typeContext)
        {
            if (typeParameters.Length != typeArguments.Length)
            {
                throw new ArgumentException(SR.Argument_GenericArgsCount);
            }

            // Do sanity validation of all arguments first. The actual constraint validation can fail in unexpected ways 
            // if it hits SigTypeContext with these never valid types.
            for (int i = 0; i < typeParameters.Length; i++)
            {
                TypeInfo actualArg = typeArguments[i];

                if (actualArg.IsSystemVoid() || (actualArg.HasElementType && !actualArg.IsArray))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_NeverValidGenericArgument, actualArg));
                }
            }

            for (int i = 0; i < typeParameters.Length; i++)
            {
                TypeInfo formalArg = typeParameters[i];
                TypeInfo actualArg = typeArguments[i];

                if (!formalArg.SatisfiesConstraints(typeContext, actualArg))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_ConstraintFailed, actualArg, definition.ToString(), formalArg),
                        String.Format("GenericArguments[{0}]", i));
                }
            }
        }
开发者ID:noahfalk,项目名称:corert,代码行数:31,代码来源:ConstraintValidator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Emit.AssemblyBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Reflection.TargetInvocationException类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap