문제

I have a methodInfo from mymethod method of Example class.

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


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

How can I make an attribute (for example, ABCAttribute) of mm so that

mm.IsDefined(typeof(ABCAttribute), true)

becomes true?

도움이 되었습니까?

해결책

You need to define your attribute.

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

Then apply it to your method.

internal class Example
{
    [ABC]
    public static void mymethod(string str1, ref string str2, out string str3)
    {
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top