1

This could be very basic..

I have a class

[Version("2"), Caching(false)]
class Sample 
{
.....
}

How can i access the values of the attributes Version and Caching in C#?

4

3 に答える 3

1

Have a look at Accessing Attributes by Using Reflection (C# and Visual Basic)

于 2012-05-11T04:14:32.447 に答える
1

Actually isn't that basic. The way to do this is through reflection.

Here is a microsoft tutorial at how to do it.

Reflection an interesting new technology that allows you to see a class as if from the side -> getting access to private and protected fields and functions, as well as attributes.

于 2012-05-11T04:14:51.980 に答える
0

これを行うには、fasterflectAPIを使用できます。それはあなたの記述のようなリフレクションタスクを簡単にする拡張メソッドを提供します。

http://fasterflect.codeplex.com/

于 2012-05-11T04:25:38.450 に答える