2011-10-16 38 views
0

我從Example class的mymethod方法中有一個methodInfo。使用C#設置methodInfo.IsDefined()爲true#

internal class Example 
{ 
    public static void mymethod(string str1, ref string str2, out string str3) 
    { 
     .... 


MethodInfo mm = typeof(Example).GetMethod("mymethod"); 

我怎樣才能讓一個屬性(例如,ABCAttribute)毫米,使

mm.IsDefined(typeof(ABCAttribute), true) 

爲真?

回答

3

您需要定義屬性。

[AttributeUsage(AttributeTargets.Method)] 
public class ABCAttribute : Attribute 
{ 
} 

然後將其應用於您的方法。

internal class Example 
{ 
    [ABC] 
    public static void mymethod(string str1, ref string str2, out string str3) 
    { 
    } 
} 
相關問題