You could as the others said Iterate the ExecutingAssembly.
If you only want the name just use this call
static void Main()
{
CProjectReflector reflector = new CProjectReflector();
Console.WriteLine(reflector.ToString());
Console.ReadLine();
}
You have to create two classes though.
In the CProjectReflector class you have to add this to the top of your file
using System.Reflection;
If you want to know more what reflection is you could visit the MSDN
With reflection you can do lots more and its really worth reading.
In short its about this
Reflection provides objects (of type Type) that describe assemblies,
modules and types.
CProjectReflector.cs:
class CProjectReflector
{
private List<CProjectObject> _projectObjects;
public List<CProjectObject> ProjectObjects
{
get { return _projectObjects; }
set { _projectObjects = value; }
}
public CProjectReflector()
{
_projectObjects = new List<CProjectObject>();
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
CProjectObject obj = CProjectObject.CreateProjectObjectWithName(type.Name);
FillProperties(type, obj);
FillFields(type, obj);
FillMethods(type, obj);
FillMembers(type, obj);
FillEvents(type, obj);
_projectObjects.Add(obj);
}
}
private static void FillEvents(Type type, CProjectObject obj)
{
foreach (EventInfo eventInfo in type.GetEvents())
{
obj.Events.Add(eventInfo.Name);
}
}
private static void FillMembers(Type type, CProjectObject obj)
{
foreach (MemberInfo memberInfo in type.GetMembers())
{
obj.Members.Add(memberInfo.Name);
}
}
private static void FillMethods(Type type, CProjectObject obj)
{
foreach (MethodInfo methodInfo in type.GetMethods())
{
obj.Methods.Add(methodInfo.Name);
}
}
private static void FillFields(Type type, CProjectObject obj)
{
foreach (FieldInfo fieldInfo in type.GetFields())
{
obj.Fields.Add(fieldInfo.Name);
}
}
private static void FillProperties(Type type, CProjectObject obj)
{
foreach (PropertyInfo propertyInfo in type.GetProperties())
{
obj.Properties.Add(propertyInfo.Name);
}
}
public override string ToString()
{
StringBuilder builder = new StringBuilder();
foreach (CProjectObject obj in _projectObjects)
{
builder.AppendLine(obj.ToString());
}
return builder.ToString();
}
}
and CProjectObject.cs
class CProjectObject
{
private String _name;
public String Name
{
get { return _name; }
set { _name = value; }
}
private List<String> _methods;
public List<String> Methods
{
get { return _methods; }
set { _methods = value; }
}
private List<String> _properties;
public List<String> Properties
{
get { return _properties; }
set { _properties = value; }
}
private List<String> _fields;
public List<String> Fields
{
get { return _fields; }
set { _fields = value; }
}
private List<String> _members;
public List<String> Members
{
get { return _members; }
set { _members = value; }
}
private List<String> _events;
public List<String> Events
{
get { return _events; }
set { _events = value; }
}
public CProjectObject()
{
_name = "Anonym";
_fields = new List<string>();
_properties = new List<string>();
_methods = new List<string>();
_members = new List<string>();
_events = new List<string>();
}
private CProjectObject(String name) : this()
{
_name = name;
}
public static CProjectObject CreateProjectObjectWithName(String name)
{
return new CProjectObject(name);
}
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("ObjectName:" + _name);
builder.AppendLine("-Contains the following fields");
foreach (String str in Fields)
{
builder.AppendLine("\tField:" + str);
}
builder.AppendLine("-Contains the following properties");
foreach (String str in Properties)
{
builder.AppendLine("\tProperty:" + str);
}
builder.AppendLine("-Contains the following methods");
foreach (String str in Methods)
{
builder.AppendLine("\tMethod:" + str);
}
builder.AppendLine("-Contains the following members");
foreach (String str in Members)
{
builder.AppendLine("\tMember:" + str);
}
builder.AppendLine("-Contains the following events");
foreach (String str in Events)
{
builder.AppendLine("\tEvent:" + str);
}
return builder.ToString();
}
}