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


C# Reflection.TypeInfo类代码示例

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


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


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