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


C# TypeInfo.GetCustomAttributes方法代码示例

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


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

示例1: GetValidTargetElementAttributes

        private static IEnumerable<TargetElementAttribute> GetValidTargetElementAttributes(
            TypeInfo typeInfo,
            ErrorSink errorSink)
        {
            var targetElementAttributes = typeInfo.GetCustomAttributes<TargetElementAttribute>(inherit: false);

            return targetElementAttributes.Where(attribute => ValidTargetElementAttributeNames(attribute, errorSink));
        }
开发者ID:antiufo,项目名称:Razor,代码行数:8,代码来源:TagHelperDescriptorFactory.cs

示例2: CreateGroup

 private static TestGroup CreateGroup(TypeInfo type)
 {
     TestGroup group = new TestGroup();
     group.Name = type.Name;
     group.Tags.Add(type.Name);
     group.Tags.Add(type.FullName);
     if (type.GetCustomAttribute<FunctionalTestAttribute>(true) != null)
     {
         group.Tags.Add("Functional");
     }
     foreach (TagAttribute attr in type.GetCustomAttributes<TagAttribute>(true))
     {
         group.Tags.Add(attr.Tag);
     }
     return group;
 }
开发者ID:TroyBolton,项目名称:azure-mobile-services,代码行数:16,代码来源:TestDiscovery.cs

示例3: ClassMetadata

        internal ClassMetadata(TypeInfo typeInfo)
        {
            #if !DataAnnotations_Missing
            var table = (TableAttribute)typeInfo.GetCustomAttributes(typeof(TableAttribute), true).SingleOrDefault();
            if (table != null)
            {
                MappedTableName = table.Name;
                MappedSchemaName = table.Schema;
            }
            #endif

            #if Weird_Reflection
            var shadowingProperties = (from p in typeInfo.DeclaredProperties where IsHidingMember(p) select p).ToList();
            var propertyList = typeInfo.DeclaredProperties.ToList();
            #elif TypeInfo_Is_Not_Type
            var type = typeInfo.AsType();
            var shadowingProperties = (from p in type.GetProperties() where IsHidingMember(p) select p).ToList();
            var propertyList = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            #else
            var shadowingProperties = (from p in typeInfo.GetProperties() where IsHidingMember(p) select p).ToList();
            var propertyList = typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            #endif

            Func<PropertyInfo, bool> IsHidden = propertyInfo => !shadowingProperties.Contains(propertyInfo) && shadowingProperties.Any(p => p.Name == propertyInfo.Name);

            Properties = new PropertyMetadataCollection(propertyList.Where(p => !IsHidden(p)).Select(p => new PropertyMetadata(p)));

            //List the properties that are affected when the indicated property is modified.
            foreach (var property in Properties)
                foreach (CalculatedFieldAttribute fieldList in property.PropertyInfo.GetCustomAttributes(typeof(CalculatedFieldAttribute), true))
                    foreach (var field in fieldList.SourceProperties)
                    {
                        if (!Properties.Contains(field))
                            throw new InvalidOperationException(string.Format("Cannot find property {0} on type {1}. This is needed for the calculated property {2}", field, typeInfo.FullName, property.Name));

                        Properties[field].AddCalculatedField(property);
                    }

            foreach (var property in Properties)
                property.EndInit();

            Constructors = new ConstructorMetadataCollection(typeInfo.DeclaredConstructors);
        }
开发者ID:docevaad,项目名称:Anchor,代码行数:43,代码来源:ClassMetadata.cs

示例4: GetApplicableDebuggerTypeProxyAttribute

        private static DebuggerTypeProxyAttribute GetApplicableDebuggerTypeProxyAttribute(TypeInfo type)
        {
            // includes inherited attributes. The debugger uses the first attribute if multiple are applied.
            var result = type.GetCustomAttributes<DebuggerTypeProxyAttribute>().FirstOrDefault();
            if (result != null)
            {
                return result;
            }

            // TODO (tomat): which assembly should we look at for proxy attributes?
            foreach (DebuggerTypeProxyAttribute attr in type.Assembly.GetCustomAttributes<DebuggerTypeProxyAttribute>())
            {
                if (IsApplicableAttribute(type, attr.Target.GetTypeInfo(), attr.TargetTypeName))
                {
                    return attr;
                }
            }

            return null;
        }
开发者ID:daking2014,项目名称:roslyn,代码行数:20,代码来源:ObjectFormatter.cs

示例5: HasJsonUseTypeHintAttribute

		public static bool HasJsonUseTypeHintAttribute ( TP tp ) {
#if WINDOWS_STORE
			return tp.GetCustomAttribute<JsonUseTypeHintAttribute> (true) != null;
#else
			return tp.GetCustomAttributes(typeof(JsonUseTypeHintAttribute),true).Length != 0;
#endif
		}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:7,代码来源:TypeCoercionUtility.cs

示例6: EntitySystemOnComponentTypeAdded

        private void EntitySystemOnComponentTypeAdded(object sender, TypeInfo type)
        {
            var rendererTypeAttributes = type.GetCustomAttributes<DefaultEntityComponentRendererAttribute>();
            foreach (var rendererTypeAttribute in rendererTypeAttributes)
            {
                var processorType = AssemblyRegistry.GetType(rendererTypeAttribute.TypeName);
                if (processorType == null || !typeof(IEntityComponentRenderProcessor).GetTypeInfo().IsAssignableFrom(processorType.GetTypeInfo()))
                {
                    continue;
                }

                var registeredProcessors = new RegisteredRenderProcessors(processorType, VisibilityGroups.Count);
                registeredRenderProcessorTypes.Add(type, registeredProcessors);

                // Create a render processor for each visibility group
                foreach (var visibilityGroup in VisibilityGroups)
                {
                    CreateRenderProcessor(registeredProcessors, visibilityGroup);
                }
            }
        }
开发者ID:cg123,项目名称:xenko,代码行数:21,代码来源:SceneInstance.cs

示例7: CreateGroup

 private static TestGroup CreateGroup(TypeInfo type)
 {
     TestGroup group = new TestGroup();
     group.Name = type.Name;
     group.Tags.Add(type.Name);
     group.Tags.Add(type.FullName);
     if (type.GetCustomAttributes(true).Where(a => a.GetType() == typeof(FunctionalTestAttribute)).Any())
     {
         group.Tags.Add("Functional");
     }
     foreach (TagAttribute attr in type.GetCustomAttributes(true).Where(a => a.GetType() == typeof(TagAttribute)))
     {
         group.Tags.Add(attr.Tag);
     }
     return group;
 }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:16,代码来源:TestHarness.cs

示例8: GetRequiredRoles

 private IEnumerable<string> GetRequiredRoles(TypeInfo screenType)
 {
     var attributes = screenType.GetCustomAttributes(typeof (RequiredRoleAttribute)).Select(x => (RequiredRoleAttribute)x);
     return attributes.Select(x => x.RoleName);
 }
开发者ID:bhlaban,项目名称:Manufacturing.WinApp,代码行数:5,代码来源:MenuViewModel.cs

示例9: GenerateCommands

 private void GenerateCommands(TypeInfo commandType)
 {
     foreach (var attr in commandType.GetCustomAttributes<RunCommandAtPhaseStartAttribute>())
     {
         if (!m_phaseCommands.ContainsKey(attr.Phase))
             m_phaseCommands.Add(attr.Phase, new List<Command>());
         m_phaseCommands[attr.Phase].Add(CreateCommand(commandType));
     }
     foreach (var attr in commandType.GetCustomAttributes<RunCommandOnJoystickAttribute>())
     {
         var button = m_buttons.OfType<JoystickButton>().Where(btn => btn.Joystick is Joystick)
             .FirstOrDefault(btn => (btn.Joystick as Joystick).Port == attr.ControllerId && btn.ButtonNumber == attr.ButtonId);
         if (button == null)
         {
             m_buttons.Add(button = new JoystickButton(new Joystick(attr.ControllerId), attr.ButtonId));
         }
         AttachCommandToButton(commandType, button, attr.ButtonMethod);
     }
     foreach (var attr in commandType.GetCustomAttributes<RunCommandOnNetworkKeyAttribute>())
     {
         var button = m_buttons.OfType<NetworkButton>().FirstOrDefault(btn => btn.SourceTable == NetworkTable.GetTable(attr.TableName) && btn.Field == attr.Key);
         if(button == null)
         {
             m_buttons.Add(button = new NetworkButton(attr.TableName, attr.Key));
         }
         AttachCommandToButton(commandType, button, attr.ButtonMethod);
     }
 }
开发者ID:chopshop-166,项目名称:WPILib,代码行数:28,代码来源:AttributedRobot.cs

示例10: EnumerateGeneratedSubsystems

 private static IEnumerable<KeyValuePair<Subsystem, string>> EnumerateGeneratedSubsystems(TypeInfo subsystemType)
 {
     foreach (var attr in subsystemType.GetCustomAttributes<ExportSubsystemAttribute>())
     {
         var subsystem = (Subsystem)Activator.CreateInstance(subsystemType);
         if (attr.DefaultCommandType != null && subsystem is Subsystem)
         {
             var defaultCommandType = attr.DefaultCommandType;
             if (!typeof(Command).IsAssignableFrom(defaultCommandType))
             {
                 throw new IllegalUseOfCommandException("Default command type is not an attributed commmand.");
             }
             var defaultCommand = (Command)Activator.CreateInstance(defaultCommandType, subsystem);
             if (!defaultCommand.DoesRequire(subsystem))
             {
                 defaultCommand.Requires(subsystem);
             }
             subsystem.SetDefaultCommand(defaultCommand);
         }
         yield return new KeyValuePair<Subsystem, string>(subsystem, attr.Name);
     }
 }
开发者ID:chopshop-166,项目名称:WPILib,代码行数:22,代码来源:AttributedRobot.cs

示例11: SetupPart

		void SetupPart(TypeInfo sourceType, BindingExpressionPart part)
		{
			part.Arguments = null;
			part.LastGetter = null;
			part.LastSetter = null;

			PropertyInfo property = null;
			if (part.IsIndexer)
			{
				if (sourceType.IsArray)
				{
					int index;
					if (!int.TryParse(part.Content, out index))
						Log.Warning("Binding", "{0} could not be parsed as an index for a {1}", part.Content, sourceType);
					else
						part.Arguments = new object[] { index };

					part.LastGetter = sourceType.GetDeclaredMethod("Get");
					part.LastSetter = sourceType.GetDeclaredMethod("Set");
					part.SetterType = sourceType.GetElementType();
				}

				DefaultMemberAttribute defaultMember = sourceType.GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType<DefaultMemberAttribute>().FirstOrDefault();
				string indexerName = defaultMember != null ? defaultMember.MemberName : "Item";

				part.IndexerName = indexerName;

				property = sourceType.GetDeclaredProperty(indexerName);
				if (property == null)
					property = sourceType.BaseType.GetProperty(indexerName);

				if (property != null)
				{
					ParameterInfo parameter = property.GetIndexParameters().FirstOrDefault();
					if (parameter != null)
					{
						try
						{
							object arg = Convert.ChangeType(part.Content, parameter.ParameterType, CultureInfo.InvariantCulture);
							part.Arguments = new[] { arg };
						}
						catch (FormatException)
						{
						}
						catch (InvalidCastException)
						{
						}
						catch (OverflowException)
						{
						}
					}
				}
			}
			else
			{
				property = sourceType.GetDeclaredProperty(part.Content);
				if (property == null)
					property = sourceType.BaseType.GetProperty(part.Content);
			}

			if (property != null)
			{
				if (property.CanRead && property.GetMethod.IsPublic && !property.GetMethod.IsStatic)
					part.LastGetter = property.GetMethod;
				if (property.CanWrite && property.SetMethod.IsPublic && !property.SetMethod.IsStatic)
				{
					part.LastSetter = property.SetMethod;
					part.SetterType = part.LastSetter.GetParameters().Last().ParameterType;

					if (Binding.AllowChaining)
					{
						FieldInfo bindablePropertyField = sourceType.GetDeclaredField(part.Content + "Property");
						if (bindablePropertyField != null && bindablePropertyField.FieldType == typeof(BindableProperty) && sourceType.ImplementedInterfaces.Contains(typeof(IElementController)))
						{
							MethodInfo setValueMethod = null;
							foreach (MethodInfo m in sourceType.AsType().GetRuntimeMethods())
							{
								if (m.Name.EndsWith("IElementController.SetValueFromRenderer"))
								{
									ParameterInfo[] parameters = m.GetParameters();
									if (parameters.Length == 2 && parameters[0].ParameterType == typeof(BindableProperty))
									{
										setValueMethod = m;
										break;
									}
								}
							}
							if (setValueMethod != null)
							{
								part.LastSetter = setValueMethod;
								part.IsBindablePropertySetter = true;
								part.BindablePropertyField = bindablePropertyField.GetValue(null);
							}
						}
					}
				}
			}
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:98,代码来源:BindingExpression.cs


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