enum based attribute : Properties : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Properties »

 

enum based attribute








    
 


using System;

public enum RemoteServers
{
    A,
    B,
    C
}
   
public class RemoteObjectAttribute : Attribute
{
    public RemoteObjectAttribute(RemoteServers Server)
    {
        this.server = Server;
    }
   
    protected RemoteServers server;
    public string Server
    {
        get 
        { 
            return RemoteServers.GetName(
                typeof(RemoteServers), this.server);
        }
    }
}
   
[RemoteObject(RemoteServers.C)]
class MyRemotableClass
{
}

class Test
{
    [STAThread]
    static void Main(string[] args)
    {
        Type type = typeof(MyRemotableClass);
        foreach (Attribute attr in type.GetCustomAttributes(true))
        {
            RemoteObjectAttribute remoteAttr = attr as RemoteObjectAttribute;
            if (null != remoteAttr)
            {
                Console.WriteLine(remoteAttr.Server);
            }
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Properties