📜  属性 c# 获取方法名称反射 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:13.999000             🧑  作者: Mango

代码示例1
void Main()
{
    ControlCharacter control = new ControlCharacter();
    control.GetType()
           .GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
           .Where(method => method.GetCustomAttribute() == null)
           .Select(method => method.Name)
           .ToList()
           .ForEach(Console.WriteLine);
}

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

public class NetworkBehavior
{
}

public class ControlCharacter : NetworkBehavior
{
    [RPC] 
    public void Move() { }

    public void DrawHud() { }
}