/// <summary> /// Get all members in the given type /// </summary> /// <param name="type"></param> /// <returns></returns> public ObservableCollection <BindableObjectExtended> GetMembers(NetBaseType type) { ObservableCollection <BindableObjectExtended> list = new ObservableCollection <BindableObjectExtended>(); TypeDefinition modulType = (TypeDefinition)type.Tag; ProcessCecilMethod(modulType.Constructors, type); ProcessCecilMethod(modulType.Methods, type); foreach (MethodDefinition constructorType in modulType.Constructors) { list.Add(AddMethod(MethodType.Constructor, constructorType)); } foreach (MethodDefinition methodType in modulType.Methods) { list.Add(new NetMethod(MethodType.Method, methodType) { Name = methodType.Name }); } return(list); }
/// <summary> /// Loop through a cecil methods collection /// </summary> /// <param name="cecilMethods"></param> /// <param name="classTyp"></param> private void ProcessCecilMethod(CollectionBase cecilMethods, NetBaseType classTyp) { foreach (MethodDefinition def in cecilMethods) { if (!RefreshMethod(classTyp.Children, def)) { if (cecilMethods.GetType() == typeof(ConstructorCollection)) { AddMethod(MethodType.Constructor, def); } if (cecilMethods.GetType() == typeof(MethodDefinitionCollection)) { AddMethod(MethodType.Method, def); } if (cecilMethods.GetType() == typeof(PropertyDefinitionCollection)) { AddMethod(MethodType.Property, def); } if (cecilMethods.GetType() == typeof(EventDefinitionCollection)) { AddMethod(MethodType.Event, def); } if (cecilMethods.GetType() == typeof(FieldDefinitionCollection)) { AddMethod(MethodType.Field, def); } if (cecilMethods.GetType() == typeof(InterfaceCollection)) { AddMethod(MethodType.Interface, def); } //process nested types //if (cecilMethods.GetType() == typeof(NestedTypeCollection)) } } }
/// <summary> /// Refresh a assembly element and all subtypes if loaded /// </summary> /// <param name="node"></param> public void RefreshNode(NetBaseType node) { }
/// <summary> /// Get all members in the given type /// </summary> /// <param name="type"></param> /// <returns></returns> public ObservableCollection <BindableObjectExtended> GetMembers(NetBaseType type) { BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; ObservableCollection <BindableObjectExtended> list = new ObservableCollection <BindableObjectExtended>(); ConstructorInfo[] cinfo = ((Type)type.Tag).GetConstructors(flags); foreach (ConstructorInfo mi in cinfo) { list.Add(new NetMethod(MethodType.Constructor, mi) { Name = mi.Name }); } //MemberInfo[] memberinfo = ((Type)type.Tag).GetMembers(flags); //foreach (MemberInfo mi in memberinfo) //{ // list.Add(new NetMethod(mi) { Name = mi.Name }); //} FieldInfo[] fieldinfo = ((Type)type.Tag).GetFields(flags); foreach (FieldInfo mi in fieldinfo) { list.Add(new NetMethod(MethodType.Field, mi) { Name = mi.Name }); } PropertyInfo[] propinfo = ((Type)type.Tag).GetProperties(flags); foreach (PropertyInfo mi in propinfo) { list.Add(new NetMethod(MethodType.Property, mi) { Name = mi.Name }); } MethodInfo[] methodinfo = ((Type)type.Tag).GetMethods(flags); foreach (MethodInfo mi in methodinfo) { if (!mi.Name.Contains("get_") && !mi.Name.Contains("set_")) { list.Add(new NetMethod(MethodType.Method, mi) { Name = mi.Name }); } } Type[] inter = ((Type)type.Tag).GetInterfaces(); foreach (Type mi in inter) { list.Add(new NetMethod(MethodType.Interface, mi) { Name = mi.Name }); } EventInfo[] eventinfo = ((Type)type.Tag).GetEvents(); foreach (EventInfo mi in eventinfo) { list.Add(new NetMethod(MethodType.Event, mi) { Name = mi.Name }); } return(list); }