本文整理汇总了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));
}
示例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;
}
示例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);
}
示例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;
}
示例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
}
示例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);
}
}
}
示例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;
}
示例8: GetRequiredRoles
private IEnumerable<string> GetRequiredRoles(TypeInfo screenType)
{
var attributes = screenType.GetCustomAttributes(typeof (RequiredRoleAttribute)).Select(x => (RequiredRoleAttribute)x);
return attributes.Select(x => x.RoleName);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
}
}
}