Comment in the code below says it all
C#:
using System;
using System.Reflection;
namespace Sample
{
public class Valid : Attribute { }
public class Customer
{
#region Properties
public string firstname { get; set; }
public string lastname { get; set; }
#endregion
[Valid]
public void PrintFullName()
{
Console.WriteLine(this.firstname + " " + this.lastname);
}
public void PrintReverseName()
{
Console.WriteLine(this.lastname + " " + this.firstname);
}
}
public class Program
{
public static void Main(string[] args)
{
foreach(Type t in Assembly.GetExecutingAssembly().GetTypes())
{
if(t.Name == "Customer")
{
Type tt = Assembly.GetExecutingAssembly().GetType(t.FullName);
foreach (MethodInfo minfo in tt.GetMethods())
{
if(minfo.GetCustomAttributes() is Valid)
{
Console.WriteLine(minfo.Name); //i thought here it would print out the method name PrintFullName but it doesn't
}
}
}
}
}
}
}