本文整理汇总了C#中System.Attribute.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.GetAttribute方法的具体用法?C# Attribute.GetAttribute怎么用?C# Attribute.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Attribute
的用法示例。
在下文中一共展示了Attribute.GetAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttribute
public void GetAttribute()
{
var attrs = new Attribute[] { new ActionNameAttribute("test", ActionFlags.Execute), new ActionNameAttribute("fail") };
var attr = attrs.GetAttribute<ActionNameAttribute>();
Assert.IsNotNull(attr);
Assert.AreEqual(ActionFlags.Execute, attr.Action);
Assert.AreEqual("test", attr.Name);
}
示例2: Initialize
public BaseDrawer Initialize(EditorMember member, Attribute[] attributes, BaseGUI gui, EditorRecord prefs)
{
if (attributes == null)
attributes = Empty;
if (this.prefs == null)
this.prefs = prefs;
this.member = member;
this.attributes = attributes;
this.gui = gui;
if (_dynamicFormatter != null)
{
_formatArgs[0] = member.Value;
displayText = _dynamicFormatter(rawTarget, _formatArgs);
}
if (_hasInit)
{
#if DBG
Log(this + " is Already initialized");
#endif
return this;
}
#if DBG
Log("Initializing: " + this);
#endif
var displayAttr = attributes.GetAttribute<DisplayAttribute>();
if (displayAttr != null && MemberDrawersHandler.IsApplicableAttribute(memberType, displayAttr, attributes))
{
var hasCustomFormat = !string.IsNullOrEmpty(displayAttr.FormatMethod);
var formatMethod = hasCustomFormat ? displayAttr.FormatMethod : ("Format" + member.Name);
var method = targetType.GetMemberFromAll(formatMethod, Flags.StaticInstanceAnyVisibility) as MethodInfo;
if (method == null)
{
if (hasCustomFormat)
Debug.Log("Couldn't find format method: " + displayAttr.FormatMethod);
}
else
{
if (method.ReturnType != typeof(string) && method.GetParameters().Length > 0)
Debug.Log("Format Method should return a string and take no parameters: " + method);
else
{
_dynamicFormatter = method.DelegateForCall<object, string>();
_formatArgs[0] = member.Value;
displayText = _dynamicFormatter(rawTarget, _formatArgs);
}
}
}
_hasInit = true;
InternalInitialize();
Initialize();
return this;
}