dynamically finding what functions have a specific attribute

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a WinForm application that we would like to add security to. We would
also like to set up a configuration utility that would make it easier to
assign or remove rights.

When using code access security is there a way to create a list of
functions/classes that have a security attribute assigned to them?

i.e a new module is added. In the assembly there are certain items that can
be added or removed from specific groups. What are they?

Is there a code sample out there to show this?

Thanks!
 
you should write a custom attribute to apply to a specific
function.more information about it.plz refer to MSDN.

Here is a sample demo to show how to find a specific attribute.

using System;

[Developer("Joan Smith", "42", Reviewed = true)]
class MainApp
{
public static void Main()
{
//Call function to get and display the attribute.
GetAttribute(typeof(MainApp));
}

public static void GetAttribute(Type t)
{


//Get instance of the attribute.
DeveloperAttribute MyAttribute = (DeveloperAttribute)
Attribute.GetCustomAttribute(t, typeof (DeveloperAttribute));

if(null == MyAttribute)
{
Console.WriteLine("The attribute was not found.");
}
else
{
//Get the Name value.
Console.WriteLine("The Name Attribute is: {0}." ,
MyAttribute.Name);
//Get the Level value.
Console.WriteLine("The Level Attribute is: {0}." ,
MyAttribute.Level);
//Get the Reviewed value.
Console.WriteLine("The Reviewed Attribute is: {0}." ,
MyAttribute.Reviewed);
}
}
}

Sincerely,
simida

Stedak 写é“:
 
Back
Top