Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CreateAttribute
- {
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
- public class AuthorAttribute : Attribute
- {
- public AuthorAttribute(string name)
- {
- this.Name = name;
- }
- public string Name { get; set; }
- }
- }
- //
- using System.Reflection;
- using System.Linq;
- using System;
- namespace CodingTracker
- {
- public class Tracker
- {
- public void PrintMethodsByAuthor(string author)
- {
- var types = Assembly.GetExecutingAssembly().GetTypes(); // types
- foreach (var type in types)
- {
- var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Instance
- | BindingFlags.Public | BindingFlags.NonPublic); // methods
- foreach (var method in methods)
- {
- var atributes = method.GetCustomAttributes<AuthorAttribute>(); // atributes
- if (atributes.Any(m => m.Name == author))
- {
- Console.WriteLine(method);
- }
- }
- }
- }
- }
- }
- //
- using CodingTracker;
- namespace CreateAttribute
- {
- [Author("Ventsi")]
- class StartUp
- {
- [Author("Gosho")]
- static void Main(string[] args)
- {
- var tracker = new Tracker();
- tracker.PrintMethodsByAuthor("Gosho");
- }
- }
- }
Add Comment
Please, Sign In to add comment