Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- Test t = new Test();
- string name = t.callMe();
- Console.WriteLine(name);
- }
- }
- [MyName("Reni")]
- public class Test {
- public string callMe () {
- return GetAttribute(typeof(Test));
- }
- public string GetAttribute(Type t) {
- MyName myname = (MyName) Attribute.GetCustomAttribute(t, typeof(MyName));
- return myname.Name;
- }
- }
- public class MyName : System.Attribute {
- public string Name { get; private set; }
- public MyName (string name) {
- this.Name = name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement