C # Attribute for use (1)

xiaoxiao2021-03-06  69

Characteristics of the class using System; public enum RemoteServers {TTT, AAA, CHAIN} public class RemoteObjectAttribute: Attribute {public RemoteObjectAttribute (RemoteServers Server) {this.server = Server;} protected RemoteServers server; public string Server {get {return Enum.GetName (TypeOf (transservers), this.server;}}

} [RemoteObjectAttribute (RemoteServers.TTT)] public class RemoteObjectClass {} public class ClientTestApp {public static void Main () {System.Type type = typeof (RemoteObjectClass); foreach (Attribute attr in type.GetCustomAttributes (true)) {RemoteObjectAttribute remoteAttr = Attr as RemoteObjectttribute; if (attr! = null) {Console.WriteLine (RemoteTtr.Server);}}}}

转载请注明原文地址:https://www.9cbs.com/read-90077.html

New Post(0)