Hi all
I'm writing an application using reflection feature of .NET Framework.
My applicaiton need to accept a assembly name as input parameter and then
must populate all methods and property from all class in this.
I'm trying to use BindingFlags with GetMethods and GetProperties from
System.Type class but i can't apply correct BindingFlags.
I only need to get public property and public and static method.
Anyone can help me?
Many thanks.
------
Here is my sample code:
public static void GetAssembly(string sAssemblyName)
{
List<MethodInfomethodList = new List<MethodInfo>();
List<PropertyInfopropertyList = new List<PropertyInfo>();
Assembly asm = Assembly.LoadFrom(Environment.CurrentDirectory +
"\\" +sAssemblyName);
Type[] types = asm.GetTypes();
foreach (Type type in types)
{
MethodInfo[] methods =
type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public);
for (int i = 0; i < methods.Length; i++)
{
if (methods[i].IsPublic && methods[i].IsStatic &&
!methods[i].Name.StartsWith("Can"))
{
methodList.Add(methods[i]);
}
}
PropertyInfo[] properties =
type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public);
for (int i = 0; i < properties.Length; i++)
{
}
MemberInfo[] members = type.FindMembers(MemberTypes.Method,
BindingFlags.Default, Type.FilterName, "Get*");
}
}