本文整理汇总了C#中System.Reflection.MemberInfo.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.HasAttribute方法的具体用法?C# MemberInfo.HasAttribute怎么用?C# MemberInfo.HasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.HasAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldInject
/// <summary>
/// Returns a value indicating whether the specified member should be injected.
/// </summary>
/// <param name="member">The member in question.</param>
/// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
public virtual bool ShouldInject(MemberInfo member)
{
Ensure.ArgumentNotNull(member, "member");
var propertyInfo = member as PropertyInfo;
if (propertyInfo != null)
{
#if !SILVERLIGHT
bool injectNonPublic = Settings.InjectNonPublic;
#else
const bool injectNonPublic = false;
#endif // !SILVERLIGHT
#if !WINRT
var setMethod = propertyInfo.GetSetMethod(injectNonPublic);
#else
var setMethod = propertyInfo.SetMethod;
if (setMethod != null && !injectNonPublic)
{
if (!setMethod.IsPublic)
setMethod = null;
}
#endif
return member.HasAttribute(Settings.InjectAttribute) && setMethod != null;
}
return member.HasAttribute(Settings.InjectAttribute);
}
示例2: CreateForMember
static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType)
{
var identifier = memInfo.AllAttributes<InjectAttribute>().Select(x => x.Identifier)
.Concat(memInfo.AllAttributes<InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault();
Type memberType;
Action<object, object> setter;
if (memInfo is FieldInfo)
{
var fieldInfo = (FieldInfo)memInfo;
setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value));
memberType = fieldInfo.FieldType;
}
else
{
Assert.That(memInfo is PropertyInfo);
var propInfo = (PropertyInfo)memInfo;
setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
memberType = propInfo.PropertyType;
}
return new InjectableInfo(
memInfo.HasAttribute(typeof(InjectOptionalAttribute)),
identifier,
memInfo.Name,
memberType,
parentType,
setter);
}
示例3: CreateForMember
static InjectableInfo CreateForMember(MemberInfo memInfo, Type enclosingType)
{
var injectAttr = memInfo.Attribute<InjectAttribute>();
var info = new InjectableInfo()
{
Optional = memInfo.HasAttribute(typeof(InjectOptionalAttribute)),
Identifier = (injectAttr == null ? null : injectAttr.Identifier),
SourceName = memInfo.Name,
EnclosingType = enclosingType,
};
if (memInfo is FieldInfo)
{
var fieldInfo = (FieldInfo)memInfo;
info.Setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value));
info.ContractType = fieldInfo.FieldType;
}
else
{
Assert.That(memInfo is PropertyInfo);
var propInfo = (PropertyInfo)memInfo;
info.Setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
info.ContractType = propInfo.PropertyType;
}
return info;
}
示例4: ShouldInject
/// <summary>
/// Returns a value indicating whether the specified member should be injected.
/// </summary>
/// <param name="member">The member in question.</param>
/// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
public virtual bool ShouldInject(MemberInfo member)
{
var propertyInfo = member as PropertyInfo;
if (propertyInfo != null)
{
bool injectNonPublic = Settings.InjectNonPublic;
var setMethod = propertyInfo.SetMethod;
if (setMethod != null && !injectNonPublic)
{
if (!setMethod.IsPublic)
setMethod = null;
}
return member.HasAttribute(Settings.InjectAttribute) && setMethod != null;
}
return member.HasAttribute(Settings.InjectAttribute);
}
示例5: ShouldInject
/// <summary>
/// Returns a value indicating whether the specified member should be injected.
/// </summary>
/// <param name="member">The member in question.</param>
/// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
public bool ShouldInject(MemberInfo member)
{
Ensure.ArgumentNotNull(member, "member");
return member.HasAttribute(Settings.InjectAttribute);
}
示例6: IsInterceptable
private bool IsInterceptable(MembersCollector collector, MemberInfo member)
{
if (collector.Type.IsInterface)
return true;
if (member.HasAttribute(typeof(NonInterceptableAttribute)))
return false;
if (member is MethodInfo && (member as MethodInfo).ContainsGenericParameters)
return false;
return true;
}
示例7: HasExpansions
public static bool HasExpansions(Type type, MemberInfo mi)
{
return GetFieldExpansion(type, mi) != null || mi is MethodInfo && mi.HasAttribute<MethodExpanderAttribute>();
}
示例8: IsInterceptable
private bool IsInterceptable(MembersCollector collector, MemberInfo member)
{
return collector.Type.IsInterface || member.HasAttribute(typeof(IInterceptable));
}