Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对于空检查。在许多地方(例如字符串比较、大写/小写、带参数的方法等)仍应加强逻辑。但我已经多次使用了这个基本概念,它是有效的。如果我能提供任何帮助,请告诉我;) [Command("ping")] public async Task P_C#_Methods_Reflection_Attributes - Fatal编程技术网

C# 对于空检查。在许多地方(例如字符串比较、大写/小写、带参数的方法等)仍应加强逻辑。但我已经多次使用了这个基本概念,它是有效的。如果我能提供任何帮助,请告诉我;) [Command("ping")] public async Task P

C# 对于空检查。在许多地方(例如字符串比较、大写/小写、带参数的方法等)仍应加强逻辑。但我已经多次使用了这个基本概念,它是有效的。如果我能提供任何帮助,请告诉我;) [Command("ping")] public async Task P,c#,methods,reflection,attributes,C#,Methods,Reflection,Attributes,对于空检查。在许多地方(例如字符串比较、大写/小写、带参数的方法等)仍应加强逻辑。但我已经多次使用了这个基本概念,它是有效的。如果我能提供任何帮助,请告诉我;) [Command("ping")] public async Task Ping() { //some logic here } [AttributeUsage(AttributeTargets.Method)] public class Command : Attribute {

对于空检查。在许多地方(例如字符串比较、大写/小写、带参数的方法等)仍应加强逻辑。但我已经多次使用了这个基本概念,它是有效的。如果我能提供任何帮助,请告诉我;)
[Command("ping")]
public async Task Ping()
{
    //some logic here
}

[AttributeUsage(AttributeTargets.Method)]
    public class Command : Attribute
    {
        
        public string Name { get; set; }

        public Command(string name)
        {
            Name = name;
        }
        public Command()
        {
            Name = string.Empty;
        }
    }
[Command("ping")]
public void Ping()
{
    //do sth 
}
public void Handle(string command)
{
    var methods = from t in Assembly.GetExecutingAssembly().GetTypes()
                  where t.GetCustomAttributes<Command>().Count() > 0
                  select t;
     //run method where command.name = ping
}