Attribute in class inheritance : Attribute : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Attribute »

 

Attribute in class inheritance








    
 
using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;

public class Starter {
    public static void Main() {
        GenericIdentity g = new GenericIdentity("Person1");
        GenericPrincipal p = new GenericPrincipal(g,new string[] { "Manager" });
        Thread.CurrentPrincipal = p;
        MyClass.MethodA();
        YClass.MethodA();
    }
}

[PrincipalPermission(SecurityAction.Demand, Role = "Manager")]
public class MyClass {
    static public void MethodA() {
        Console.WriteLine("MyClass.MethodA");
    }
}

[PrincipalPermission(SecurityAction.Demand,Role = "Accountant")]
public class YClass : MyClass {

    static public void MethodB() {
        Console.WriteLine("MyClass.MethodB");
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Attribute