0

Example クラスの mymethod メソッドから methodInfo があります。

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


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

mm の属性 (ABCAttribute など) を作成するにはどうすればよいですか?

mm.IsDefined(typeof(ABCAttribute), true)

真になる?

4

1 に答える 1

3

属性を定義する必要があります。

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

次に、それをメソッドに適用します。

internal class Example
{
    [ABC]
    public static void mymethod(string str1, ref string str2, out string str3)
    {
    }
}
于 2011-10-16T22:07:57.477 に答える