本文整理汇总了C#中System.Reflection.MemberInfo.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.GetAttributes方法的具体用法?C# MemberInfo.GetAttributes怎么用?C# MemberInfo.GetAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.GetAttributes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTargetName
private string GetTargetName(
Option<BindingConfig> bindingConfig,
TypePair typePair,
MemberInfo sourceMember,
Dictionary<string, string> targetBindings)
{
Option<string> targetName;
List<BindAttribute> binds = sourceMember.GetAttributes<BindAttribute>();
BindAttribute bind = binds.FirstOrDefault(x => x.TargetType.IsNull());
if (bind.IsNull())
{
bind = binds.FirstOrDefault(x => typePair.Target.IsAssignableFrom(x.TargetType));
}
if (bind.IsNotNull())
{
targetName = new Option<string>(bind.MemberName);
}
else
{
targetName = bindingConfig.Map(x => x.GetBindField(sourceMember.Name));
if (targetName.HasNoValue)
{
string targetMemberName;
if (targetBindings.TryGetValue(sourceMember.Name, out targetMemberName))
{
targetName = new Option<string>(targetMemberName);
}
else
{
targetName = new Option<string>(sourceMember.Name);
}
}
}
return targetName.Value;
}
示例2: GetActionsFromAttributeProvider
public static ITestAction[] GetActionsFromAttributeProvider(MemberInfo attributeProvider)
{
if (attributeProvider == null)
return new ITestAction[0];
var actions = attributeProvider.GetAttributes<ITestAction>(false).ToList();
actions.Sort(SortByTargetDescending);
return actions.ToArray();
}
示例3: ApplyAttributesToTest
/// <summary>
/// Modify a newly constructed test by applying any of NUnit's common
/// attributes, based on a supplied ICustomAttributeProvider, which is
/// usually the reflection element from which the test was constructed,
/// but may not be in some instances. The attributes retrieved are
/// saved for use in subsequent operations.
/// </summary>
/// <param name="provider">An object deriving from MemberInfo</param>
public void ApplyAttributesToTest(MemberInfo provider)
{
foreach (IApplyToTest iApply in provider.GetAttributes<IApplyToTest>(true))
iApply.ApplyToTest(this);
}
示例4: CreateMemberImportDefinition
public static ReflectionMemberImportDefinition CreateMemberImportDefinition(MemberInfo member, ICompositionElement origin)
{
Requires.NotNull(member, "member");
ReflectionWritableMember reflectionMember = member.ToReflectionWritableMember();
IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionMember, member);
ImportType importType = new ImportType(reflectionMember.ReturnType, attributedImport.Cardinality);
if (importType.IsPartCreator)
{
return new PartCreatorMemberImportDefinition(
new LazyMemberInfo(member),
origin,
new ContractBasedImportDefinition(
attributedImport.GetContractNameFromImport(importType),
attributedImport.GetTypeIdentityFromImport(importType),
CompositionServices.GetRequiredMetadata(importType.MetadataViewType),
attributedImport.Cardinality,
attributedImport.AllowRecomposition,
false,
(attributedImport.RequiredCreationPolicy != CreationPolicy.NewScope) ? CreationPolicy.NonShared : CreationPolicy.NewScope,
CompositionServices.GetImportMetadata(importType, attributedImport)));
}
else
{
// A Standard parameter import is not allowed to be marked as requiring NewScope at this time.
if(attributedImport.RequiredCreationPolicy == CreationPolicy.NewScope)
{
throw new ComposablePartException(
String.Format(CultureInfo.CurrentCulture,
Strings.InvalidPartCreationPolicyOnImport,
attributedImport.RequiredCreationPolicy),
origin);
}
//Does this Import re-export the value if so, make it a rpe-requisite
bool isPrerequisite = member.GetAttributes<ExportAttribute>().Length > 0;
return new ReflectionMemberImportDefinition(
new LazyMemberInfo(member),
attributedImport.GetContractNameFromImport(importType),
attributedImport.GetTypeIdentityFromImport(importType),
CompositionServices.GetRequiredMetadata(importType.MetadataViewType),
attributedImport.Cardinality,
attributedImport.AllowRecomposition,
isPrerequisite,
attributedImport.RequiredCreationPolicy,
CompositionServices.GetImportMetadata(importType, attributedImport),
origin);
}
}
示例5: GetMaxStringLength
internal static int GetMaxStringLength(MemberInfo info)
{
MaxLengthAttribute[] attrs = info.GetAttributes<MaxLengthAttribute>().ToArray();
int maxLength = attrs.Any()
? attrs.First().Length
: DefaultMaxStringLength;
return maxLength;
}
示例6: GetColumnName
internal static string GetColumnName(MemberInfo info)
{
string name = info.Name;
ColumnAttribute[] attrs = info.GetAttributes<ColumnAttribute>().ToArray();
if (attrs.Any())
{
string attributeName = attrs.First().Name;
if (!string.IsNullOrEmpty(attributeName))
{
name = attributeName;
}
}
return name;
}
示例7: GetCollation
internal static Collation GetCollation(MemberInfo info)
{
CollationAttribute[] attrs = info.GetAttributes<CollationAttribute>().ToArray();
return attrs.Any() ? attrs.First().Collation : Collation.Default;
}
示例8: GetDefaultValue
internal static string GetDefaultValue(MemberInfo info)
{
DefaultAttribute[] attrs = info.GetAttributes<DefaultAttribute>().ToArray();
return attrs.Any() ? attrs.First().Value : null;
}
示例9: IsIgnore
private bool IsIgnore(Option<BindingConfig> bindingConfig, TypePair typePair, MemberInfo sourceMember)
{
List<IgnoreAttribute> ignores = sourceMember.GetAttributes<IgnoreAttribute>();
if (ignores.Any(x => x.TargetType.IsNull()))
{
return true;
}
if (ignores.FirstOrDefault(x => typePair.Target.IsAssignableFrom(x.TargetType)).IsNotNull())
{
return true;
}
return bindingConfig.Map(x => x.IsIgnoreSourceField(sourceMember.Name)).Value;
}
示例10: GetDisplayNameGetter
/// <summary>
/// Gets the display name getter.
/// </summary>
/// <param name="member">The member.</param>
/// <returns></returns>
public static Func<string> GetDisplayNameGetter(MemberInfo member) {
if (member == null) return null;
var displayAttribute = member.GetAttributes<DisplayAttribute>(true).FirstOrDefault();
if (displayAttribute != null) return displayAttribute.GetName;
return null;
}
示例11: GetValidator
private static ConfigurationValidatorBase GetValidator(MemberInfo mi)
{
ConfigurationValidatorBase validator = new DefaultValidator();
var validators = mi.GetAttributes<ValidationAttribute>();
if (validators.IsNullOrEmpty() == false)
{
validator = new CompositeConfigurationValidator(validators, mi.Name);
}
return validator;
}