本文整理汇总了C#中System.Reflection.MethodInfo.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetCustomAttribute方法的具体用法?C# MethodInfo.GetCustomAttribute怎么用?C# MethodInfo.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodMetadata
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="obj">The S# object the method belongs to.</param>
/// <param name="method">The CLR method the metadata should be provided for.</param>
/// <param name="name">The name of the method; if <c>null</c>, the method's CLR name is used.</param>
/// <param name="baseMethod">The overridden base method, if any.</param>
internal MethodMetadata(IMetadataObject obj, MethodInfo method, string name = null, MethodMetadata baseMethod = null)
{
Requires.NotNull(obj, () => obj);
Requires.NotNull(method, () => method);
Requires.That(name == null || !String.IsNullOrWhiteSpace(name), () => name, "The name must be null or non-whitespace only.");
Requires.That(baseMethod == null || method != baseMethod.MethodInfo, "A method cannot override itself.");
Requires.That(baseMethod == null || obj == baseMethod._object, "The base method must belong to the same object.");
Requires.That(baseMethod == null || baseMethod.OverridingMethod == null, "The base method has already been overridden.");
_object = obj;
Name = EscapeName(name ?? method.Name);
MethodInfo = method;
BaseMethod = baseMethod;
if (baseMethod != null)
baseMethod.OverridingMethod = this;
var backingFieldAttribute = MethodInfo.GetCustomAttribute<BackingFieldAttribute>();
if (backingFieldAttribute != null)
BackingField = backingFieldAttribute.GetFieldInfo(MethodInfo.DeclaringType);
var behaviorAttribute = MethodInfo.GetCustomAttribute<IntendedBehaviorAttribute>();
if (behaviorAttribute != null)
IntendedBehavior = behaviorAttribute.GetMethodInfo(MethodInfo.DeclaringType);
if (backingFieldAttribute == null && behaviorAttribute == null)
IntendedBehavior = MethodInfo;
Behaviors = new MethodBehaviorCollection(obj, this);
ImplementedMethods = DetermineImplementedInterfaceMethods().ToArray();
_methodBody = new Lazy<MethodBodyMetadata>(InitializeMethodBody);
}
示例2: GetRpcMethodName
public static string GetRpcMethodName(MethodInfo mi)
{
string rpcMethod;
string MethodName = mi.Name;
Attribute attr = mi.GetCustomAttribute<XmlRpcBeginAttribute>();
if (attr != null)
{
rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
if (rpcMethod == "")
{
if (!MethodName.StartsWith("Begin") || MethodName.Length <= 5)
throw new Exception(String.Format(
"method {0} has invalid signature for begin method",
MethodName));
rpcMethod = MethodName.Substring(5);
}
return rpcMethod;
}
// if no XmlRpcBegin attribute, must have XmlRpcMethod attribute
attr = mi.GetCustomAttribute<XmlRpcMethodAttribute>();
if (attr == null)
{
throw new Exception("missing method attribute");
}
XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
rpcMethod = xrmAttr.Method;
if (rpcMethod == "")
{
rpcMethod = mi.Name;
}
return rpcMethod;
}
示例3: CreateMethod
private static TestMethod CreateMethod(TypeInfo type, object instance, MethodInfo method)
{
TestMethod test = new TestMethod();
test.Name = method.Name;
if (method.GetCustomAttribute<AsyncTestMethodAttribute>(true) != null)
{
test.Test = new AsyncTestMethodAsyncAction(instance, method);
}
else
{
test.Test = new TestMethodAsyncAction(instance, method);
}
ExcludeTestAttribute excluded = method.GetCustomAttribute<ExcludeTestAttribute>(true);
if (excluded != null)
{
test.Exclude(excluded.Reason);
}
if (method.GetCustomAttribute<FunctionalTestAttribute>(true) != null)
{
test.Tags.Add("Functional");
}
test.Tags.Add(type.FullName + "." + method.Name);
test.Tags.Add(type.Name + "." + method.Name);
foreach (TagAttribute attr in method.GetCustomAttributes<TagAttribute>(true))
{
test.Tags.Add(attr.Tag);
}
return test;
}
示例4: GetHttpMethod
static HttpMethods GetHttpMethod(MethodInfo m)
{
var postAttr = m.GetCustomAttribute<HttpPostAttribute>();
var getAttr = m.GetCustomAttribute<HttpGetAttribute>();
var putAttr = m.GetCustomAttribute<HttpPutAttribute>();
var deleteAttr = m.GetCustomAttribute<HttpDeleteAttribute>();
var patchAttr = m.GetCustomAttribute<HttpPatchAttribute>();
if (postAttr != null) return HttpMethods.Post;
else if (getAttr != null) return HttpMethods.Get;
else if (putAttr != null) return HttpMethods.Put;
else if (deleteAttr != null) return HttpMethods.Delete;
else if (patchAttr != null) return HttpMethods.Patch;
else return HttpMethods.Unknown;
}
示例5: IsVisible
/// <summary>
/// Returns a value indicating whether or not a server-side dispatcher should be generated for the provided <paramref name="method"/>.
/// </summary>
/// <param name="containingType">
/// The containing type.
/// </param>
/// <param name="method">
/// The method.
/// </param>
/// <returns>
/// A value indicating whether or not a server-side dispatcher should be generated for the provided <paramref name="method"/>.
/// </returns>
public static bool IsVisible(Type containingType, MethodInfo method)
{
var typeLevelAttribute = method.DeclaringType.GetCustomAttribute<VisibleAttribute>()
?? containingType.GetCustomAttribute<VisibleAttribute>();
var hasTypeOverride = typeLevelAttribute != null && typeLevelAttribute.Visible.HasValue;
var typeVisibility = typeLevelAttribute != null && typeLevelAttribute.Visible.HasValue
&& typeLevelAttribute.Visible.Value;
var methodLevelAttribute = method.GetCustomAttribute<VisibleAttribute>();
var hasMethodOverride = methodLevelAttribute != null && methodLevelAttribute.Visible.HasValue;
var methodVisibility = methodLevelAttribute != null && methodLevelAttribute.Visible.HasValue
&& methodLevelAttribute.Visible.Value;
if (hasMethodOverride)
{
return methodVisibility;
}
if (hasTypeOverride)
{
return typeVisibility;
}
return true;
}
示例6: GetMethodName
private static string GetMethodName(MethodInfo methodInfo)
{
var webMetodAttribute = methodInfo.GetCustomAttribute(typeof(WebMethodAttribute), true)
as WebMethodAttribute;
var methodCustomName = webMetodAttribute.MessageName;
return String.IsNullOrEmpty(methodCustomName) ? methodInfo.Name : methodCustomName;
}
示例7: Discover
public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetadata)
{
var notes = publicMethod.GetCustomAttribute<NotesAttribute>() ?? new NotesAttribute("");
methodMetadata.Notes = notes.Notes;
methodMetadata.Notes += "Uri template " + methodMetadata.Uri.Uri;
return true;
}
示例8: CommandHandlerInfo
internal CommandHandlerInfo(MethodInfo method)
{
Method = method;
Attribute = method.GetCustomAttribute<CommandHandlerAttribute>();
Debug.Assert(Attribute != null);
Parameters = (from e in method.GetParameters() select new CommandParameterInfo(e)).ToArray();
}
示例9: Generate
public IAction Generate(MethodInfo method)
{
if (!method.IsPublic) return null;
//标记了NoAction的方法跳过
var noAction = method.GetCustomAttribute<NonActionAttribute>();
if (noAction != null) return null;
var buildContext = new ActionGenerationContext(method, this.BinderFactory);
return Generate(buildContext);
}
示例10: Discover
public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetdata)
{
var responseType = publicMethod.GetCustomAttribute<ResponseTypeIsAttribute>() ??
new ResponseTypeIsAttribute(publicMethod.ReturnType);
methodMetdata.ReturnType = responseType.ResponseType;
methodMetdata.HandlerType = publicMethod.DeclaringType;
return IsTypeMatch(methodMetdata.DesiredReturnType, methodMetdata.ReturnType);
}
示例11: GetInvocationName
public static string GetInvocationName(MethodInfo mi)
{
var result = mi.Name;
var attr = mi.GetCustomAttribute(typeof(ActionAttribute), false) as ActionAttribute;
if (attr!=null)
if (attr.Name.IsNotNullOrWhiteSpace()) result = attr.Name;
return result;
}
示例12: Add
/// <summary>
/// Adds the given test to the session. This test has to be a member of the test class and needs a TestMethod Attribute.
/// </summary>
public void Add(MethodInfo test)
{
if (test.GetCustomAttribute<JUUTTestMethodAttribute>() == null) {
throw new ArgumentException("Tests to be added to a TestRunner needs a TestMethod-Attribute.");
}
if (test.DeclaringType != TestClass) {
throw new ArgumentException("The given method isn't a member of the test class.");
}
TestsToRun.Add(test);
}
示例13: TestMethodInfo
public TestMethodInfo(MethodInfo info) {
if (!info.IsPublic) return;
var attr = info.GetCustomAttribute(typeof(TestAttribute)) as TestAttribute;
if (attr == null) return;
var argCount = info.GetParameters().Length;
if (argCount != 0) return;
this.IsValid = true;
this.Description = attr.Description;
this.MethodInfo = info;
}
示例14: Discover
public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetadata)
{
var attribute = publicMethod.GetCustomAttribute<NotesAttribute>() ?? new NotesAttribute("");
if(string.IsNullOrEmpty(attribute.Notes))
methodMetadata.Notes += "Uri template " + methodMetadata.Uri.Uri;
else
methodMetadata.Notes = attribute.Notes;
return true;
}
示例15: Initialize
public void Initialize(MethodInfo method, object rawTarget, UnityObject unityTarget, int id, BaseGUI gui, EditorRecord prefs)
{
this.prefs = prefs;
this.gui = gui;
this.rawTarget = rawTarget;
this.unityTarget = unityTarget;
this.id = id;
if (initialized) return;
initialized = true;
isCoroutine = method.ReturnType == typeof(IEnumerator);
var commentAttr = method.GetCustomAttribute<CommentAttribute>();
if (commentAttr != null)
comment = commentAttr.comment;
niceName = method.GetNiceName();
if (niceName.IsPrefix("dbg") || niceName.IsPrefix("Dbg"))
niceName = niceName.Remove(0, 3);
invoke = method.DelegateForCall();
var argInfos = method.GetParameters();
int len = argInfos.Length;
argValues = new object[len];
argKeys = new int[len];
argMembers = new EditorMember[len];
for (int iLoop = 0; iLoop < len; iLoop++)
{
int i = iLoop;
var argInfo = argInfos[i];
argKeys[i] = RuntimeHelper.CombineHashCodes(id, argInfo.ParameterType.Name + argInfo.Name);
argValues[i] = TryLoad(argInfos[i].ParameterType, argKeys[i]);
argMembers[i] = EditorMember.WrapGetSet(
@get : () => argValues[i],
@set : x => argValues[i] = x,
@rawTarget : rawTarget,
@unityTarget : unityTarget,
@attributes : argInfo.GetCustomAttributes(true) as Attribute[],
@name : argInfo.Name,
@id : argKeys[i],
@dataType : argInfo.ParameterType
);
}
#if DBG
Log("Method drawer init");
#endif
}