本文整理汇总了C#中System.Reflection.MemberInfo.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.IsDefined方法的具体用法?C# MemberInfo.IsDefined怎么用?C# MemberInfo.IsDefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.IsDefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
if (member.IsDefined(typeof(DisableAuditingAttribute)) || member.IsDefined(typeof(JsonIgnoreAttribute)))
{
property.ShouldSerialize = instance => false;
}
return property;
}
示例2: GetOpenTypeDescription
public static string GetOpenTypeDescription(MemberInfo typeElement)
{
Type typeToQuery;
if (typeElement.MemberType == MemberTypes.TypeInfo || typeElement.MemberType == MemberTypes.NestedType)
{
typeToQuery = (Type)typeElement;
}
else
{
typeToQuery = typeElement.DeclaringType;
}
if (typeToQuery.IsDefined(typeof(OpenTypeAttribute), true))
{
OpenTypeAttribute mappingSpec =
(OpenTypeAttribute) typeToQuery.GetCustomAttributes(typeof (OpenTypeAttribute), true)[0];
if (!string.IsNullOrEmpty(mappingSpec.ResourceName))
{
ResourceManager manager = new ResourceManager(mappingSpec.ResourceName, typeToQuery.Assembly);
string descr = manager.GetString(typeElement.Name);
if (descr == null)
{
throw new MissingResourceItemException(typeElement.Name, mappingSpec.ResourceName,
typeToQuery.Assembly.FullName);
}
return descr;
}
}
if (typeElement.IsDefined(typeof(DescriptionAttribute), true))
{
DescriptionAttribute descrAttr =
(DescriptionAttribute) typeElement.GetCustomAttributes(typeof (DescriptionAttribute), true)[0];
return descrAttr.Description;
}
return typeElement.Name;
}
示例3: GetOpenTypeName
public static string GetOpenTypeName(MemberInfo typeElement)
{
if (typeElement.IsDefined(typeof(OpenTypeAttribute), true))
{
OpenTypeAttribute mappingSpec =
(OpenTypeAttribute)typeElement.GetCustomAttributes(typeof(OpenTypeAttribute), true)[0];
if (!string.IsNullOrEmpty(mappingSpec.MappedName))
{
return mappingSpec.MappedName;
}
}
return typeElement.Name;
}
示例4: CreateMemberInstance
protected override Object CreateMemberInstance(Type memberType, MemberInfo memberInfo, ISearchContext searchContext)
{
var locator = CreateElementLocator(memberInfo);
var isCached = memberInfo.IsDefined(typeof (CacheLookupAttribute), true);
if (memberType.IsWebElement())
{
ILoader<IWebElement> elementLoader = _loaderFactory.CreateElementLoader(searchContext, locator, isCached);
IWebElement elementProxy =
typeof(HtmlFrame).IsAssignableFrom(memberType)
? _proxyFactory.CreateFrameProxy(elementLoader)
: _proxyFactory.CreateElementProxy(elementLoader);
if (typeof (IWebElement) == memberType || typeof (IHtmlElement) == memberType)
{
return new HtmlElement(elementProxy);
}
return Create(memberType, elementProxy);
}
if (memberType.IsWebElementList())
{
var genericArguments = memberType.GetGenericArguments();
if (genericArguments.Length == 0)
{
return null;
}
var elementType = genericArguments[0];
if (elementType == typeof (IWebElement) || elementType == typeof (IHtmlElement))
{
elementType = typeof (HtmlElement);
}
return _proxyFactory.CreateListProxy(
elementType, _loaderFactory.CreateListLoader(elementType, searchContext, locator, isCached)
);
}
return null;
}
示例5: MyTransformer
private IEnumerable<TransformedName> MyTransformer(MemberInfo member, TransformReason reason) {
if (member.IsDefined(typeof(OperatorMethodAttribute), false)) {
Operators op;
switch(member.Name) {
case "Add": op = Operators.Add; break;
case "Subtract": op = Operators.Subtract; break;
case "Divide": op = Operators.Divide; break;
case "Multiply": op = Operators.Multiply; break;
default: throw new NotImplementedException();
}
yield return new TransformedName(
new OperatorMapping(op, false, true, false),
ContextId.Empty);
}
yield return new TransformedName(member.Name, ContextId.Empty);
}
示例6: IsExtensionMethod
private bool IsExtensionMethod(MemberInfo memberInfo)
{
return memberInfo.IsDefined(typeof (ExtensionAttribute), true);
}
示例7: HasIgnoreAttribute
public static bool HasIgnoreAttribute( MemberInfo member )
{
return member.IsDefined( IgnoreType, false );
}
示例8: ExpandProperty
bool ExpandProperty(MemberInfo memberInfo)
{
return (memberInfo.IsDefined(typeof(Debugger.Tests.ExpandAttribute), true)) ||
ListContains(expandProperties, memberInfo);
}
示例9: OutlineMemberAttribute
void OutlineMemberAttribute (MemberInfo mi)
{
if (!mi.IsDefined (typeof (System.ObsoleteAttribute), false))
return;
var oa = mi.GetCustomAttributes (typeof (System.ObsoleteAttribute), false) [0] as ObsoleteAttribute;
var msg = oa.Message;
o.WriteLine ("[Obsolete{0}]", msg == null || msg == "" ? "" : string.Format ("(\"{0}\")", msg));
}
示例10: GetColumnAttribute
protected ColumnAttribute GetColumnAttribute(MemberInfo member)
{
if (member.IsDefined(typeof(ColumnAttribute), false))
{
return (ColumnAttribute)member.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
}
return null;
}
示例11: IsDefined
public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
{
// Returns true if a custom attribute subclass of attributeType class/interface with inheritance walk
if (element == null)
throw new ArgumentNullException(nameof(element));
if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
Contract.EndContractBlock();
switch(element.MemberType)
{
case MemberTypes.Property:
return InternalIsDefined((PropertyInfo)element, attributeType, inherit);
case MemberTypes.Event:
return InternalIsDefined((EventInfo)element, attributeType, inherit);
default:
return element.IsDefined(attributeType, inherit);
}
}
示例12: GetDescription
/// <summary>
/// Get The Type Description using Description Attribute and
/// objects to format the Description.
/// </summary>
/// <param name="member"> Specified Member for which Info is Required</param>
/// <param name="args">An Object array containing zero or more objects to format.</param>
/// <returns>return <see cref="String.Empty"/> if DescriptionAttribute is
/// not found or return type description</returns>
public static string GetDescription(MemberInfo member, params object[] args)
{
string text1;
if (member == null)
{
throw new ArgumentNullException("member");
}
if (member.IsDefined(typeof(DescriptionAttribute), false))
{
DescriptionAttribute[] attributes =
(DescriptionAttribute[])member.GetCustomAttributes(typeof(DescriptionAttribute), false);
text1 = attributes[0].Description;
}
else
{
return String.Empty;
}
if ((args != null) && (args.Length > 0))
{
return String.Format(null, text1, args);
}
return text1;
}
示例13: IsXmlIgnore
private bool IsXmlIgnore(MemberInfo member) {
return member.IsDefined(typeof(XmlIgnoreAttribute), false);
}
示例14: IsDefined
internal static bool IsDefined(MemberInfo target, Type caType, bool inherit) {
// JScript implements subclasses of MemberInfo which throw an exception when Module is
// accessed. We know that none of these are from a ReflectionOnly assembly.
Type t = target.GetType();
if (t.Assembly == typeof(CustomAttribute).Assembly || !target.Module.Assembly.ReflectionOnly)
return target.IsDefined(caType, inherit);
return CustomAttribute.CheckForCustomAttribute(CustomAttributeData.GetCustomAttributes(target), caType);
}
示例15: AssertIsDeprecated
private static void AssertIsDeprecated(MemberInfo member)
{
Assert.NotNull(member);
Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
}