public static void Main() { try { MemberFilter myFilter = Type.FilterNameIgnoreCase; Type myType = typeof(System.String); MemberInfo[] myMemberinfo1 = myType.FindMembers(MemberTypes.Constructor | MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, myFilter, "C*"); foreach (MemberInfo myMemberinfo2 in myMemberinfo1) { Console.Write("\n" + myMemberinfo2.Name); MemberTypes Mymembertypes = myMemberinfo2.MemberType; Console.WriteLine(" is a " + Mymembertypes.ToString()); } } catch (ArgumentNullException e) { Console.Write("ArgumentNullException : " + e.Message); } catch (SecurityException e) { Console.Write("SecurityException : " + e.Message); } catch (Exception e) { Console.Write("Exception : " + e.Message); } }
public override MemberElement CreateMemberElement(TypeElement type, string memberName, string returnType, MemberTypes memberType, IncludeStatus includeStatus, VisibilityOverride visibilityOverride, SecurityTransparencyStatus securityTransparencyStatus) { // Identify the member by category (method/prop/field/event), name, and return type. These // strings are what matched by ModelSigFormatter string memberSig = memberType.ToString() + " : " + memberName; if (returnType != null) memberSig = memberSig + " : " + returnType; CodeMemberElement member = new CodeMemberElement(includeStatus, visibilityOverride, securityTransparencyStatus, memberSig, returnType, memberType, memberName); (type as CodeTypeElement).m_members.Add(memberSig, member); return member; }
public override MemberElement CreateMemberElement(TypeElement type, string memberName, string returnType, MemberTypes memberType, IncludeStatus includeStatus, VisibilityOverride visibilityOverride, SecurityTransparencyStatus securityTransparencyStatus) { // Identify the member by category (method/prop/field/event), name, and return type. These // strings are what matched by ModelSigFormatter string memberSig = memberType.ToString() + " : " + memberName; if (returnType != null) { memberSig = memberSig + " : " + returnType; } CodeMemberElement member = new CodeMemberElement(includeStatus, visibilityOverride, securityTransparencyStatus, memberSig, returnType, memberType, memberName); (type as CodeTypeElement).m_members.Add(memberSig, member); return(member); }
public static int Main() { Console.WriteLine("\nReflection.FieldInfo"); Myfield Myfield = new Myfield(); // Get the Type and FieldInfo. Type MyType = typeof(Myfield); FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.NonPublic | BindingFlags.Instance); // Get and display the MemberType. Console.Write("\n{0}.", MyType.FullName); Console.Write("{0} - ", Myfieldinfo.Name); Console.Write("{0};", Myfield.Field); MemberTypes Mymembertypes = Myfieldinfo.MemberType; Console.Write("MemberType is a {0}.", Mymembertypes.ToString()); return(0); }
static int GetImageIndex(MemberTypes type) { switch (type.ToString()) { case "Field": case "Property": return(2); case "Event": return(3); case "Method": case "Constructor": return(4); default: return(-1); } }
private void QueryColumnData(List <ColumnMetaInfo> colList, List <FKSpecification> fkList, object xag) { foreach (PropertyInfo pi in xag.GetType().GetProperties()) { MemberTypes mt = pi.MemberType; string val = mt.ToString(); PropertyAttributes patt = pi.Attributes; string nm = pi.PropertyType.Name; String name = pi.Name; Type rt = pi.GetMethod.ReturnType; string tName = GuessMainType(rt.FullName); FKSpecification fkSpec = null; bool hasFK = LookupFKForColumn(name, out fkSpec, fkList); ColumnMetaInfo cmi = new ColumnMetaInfo() { columnName = name, fkSpec = fkSpec, hasFK = hasFK, dbTypeName = tName }; colList.Add(cmi); } }
public MissingMember CreateMember(MemberInfo infoMono, MemberInfo infoMS) { MemberTypes mt = (infoMono != null) ? infoMono.MemberType : infoMS.MemberType; MissingMember mm; switch (mt) { case MemberTypes.Method: mm = new MissingMethod(infoMono, infoMS); break; case MemberTypes.Property: mm = new MissingProperty(infoMono, infoMS); break; case MemberTypes.Event: mm = new MissingEvent(infoMono, infoMS); break; case MemberTypes.Field: mm = new MissingField(infoMono, infoMS); break; case MemberTypes.Constructor: mm = new MissingConstructor(infoMono, infoMS); break; case MemberTypes.NestedType: mm = new MissingNestedType(infoMono, infoMS); break; default: throw new Exception("Unexpected MemberType: " + mt.ToString()); } mm.Analyze(); return(mm); }
private List <ColumnMetaInfo> QueryColumns(string connString, object ob, string tableName) { List <FKSpecification> fkList = ForeignKeyUtils.QueryForeignKeyRelationships(connString, tableName); List <ColumnMetaInfo> colList = new List <ColumnMetaInfo>(); foreach (PropertyInfo pi in ob.GetType().GetProperties()) { MemberTypes mt = pi.MemberType; string val = mt.ToString(); PropertyAttributes patt = pi.Attributes; string nm = pi.PropertyType.Name; String name = pi.Name; FKSpecification fkSpec = null; bool hasFK = LookupFKForColumn(name, out fkSpec, fkList); Type rt = pi.GetMethod.ReturnType; string tName = GuessMainType(rt.FullName); ColumnMetaInfo cmi = new ColumnMetaInfo() { columnName = name, fkSpec = fkSpec, hasFK = hasFK, dbTypeName = tName }; colList.Add(cmi); } return(colList); }
public static string FormatMemberType(MemberTypes memberType) { return(memberType.ToString().ToLower()); }
public MemberCollection GroupsMembersGetList(string groupId, int page, int perPage, MemberTypes memberType) { var dictionary = new Dictionary<string, string>(); dictionary.Add("method", "flickr.groups.members.getList"); dictionary.Add("group_id", groupId); if (page != 0) dictionary.Add("page", page.ToString(CultureInfo.InvariantCulture)); if (perPage != 0) dictionary.Add("per_page", perPage.ToString(CultureInfo.InvariantCulture)); if (memberType != MemberTypes.None) dictionary.Add("member_type", memberType.ToString().ToLower()); return GetResponse<MemberCollection>(dictionary); }
internal void CheckAccessibility(MemberInfo member) { bool flag; if (member == null) { throw new ArgumentNullException("member"); } MemberTypes memberType = member.MemberType; if (this.NonPublic) { return; } MemberTypes types2 = memberType; if (types2 <= MemberTypes.Method) { switch (types2) { case MemberTypes.Constructor: { ConstructorInfo info2 = (ConstructorInfo)member; flag = info2.IsPublic || ((info2.IsAssembly || info2.IsFamilyOrAssembly) && this.InternalsVisible(info2.DeclaringType.Assembly)); goto Label_01E6; } case MemberTypes.Field: { FieldInfo info = (FieldInfo)member; flag = info.IsPublic || ((info.IsAssembly || info.IsFamilyOrAssembly) && this.InternalsVisible(info.DeclaringType.Assembly)); goto Label_01E6; } case MemberTypes.Method: { MethodInfo info3 = (MethodInfo)member; flag = info3.IsPublic || ((info3.IsAssembly || info3.IsFamilyOrAssembly) && this.InternalsVisible(info3.DeclaringType.Assembly)); if (!flag && ((member is MethodBuilder) || (member.DeclaringType == this.MapType(typeof(TypeModel))))) { flag = true; } goto Label_01E6; } } } else { if (types2 == MemberTypes.Property) { flag = true; } else { Type type; if (types2 != MemberTypes.TypeInfo) { if (types2 == MemberTypes.NestedType) { type = (Type)member; do { flag = (type.IsNestedPublic || type.IsPublic) || ((((type.DeclaringType == null) || type.IsNestedAssembly) || type.IsNestedFamORAssem) && this.InternalsVisible(type.Assembly)); if (!flag) { break; } }while ((type = type.DeclaringType) != null); goto Label_01E6; } goto Label_01D5; } type = (Type)member; flag = type.IsPublic || this.InternalsVisible(type.Assembly); } goto Label_01E6; } Label_01D5: throw new NotSupportedException(memberType.ToString()); Label_01E6: if (!flag) { switch (memberType) { case (MemberTypes.TypeInfo & MemberTypes.NestedType): throw new InvalidOperationException("Non-public member cannot be used with full dll compilation: " + member.DeclaringType.FullName + "." + member.Name); } throw new InvalidOperationException("Non-public type cannot be used with full dll compilation: " + ((Type)member).FullName); } }
public ExpectedButGotException(MemberTypes[] expected, MemberTypes got) : this(expected.Select(e => e.ToString()).ToArray(), got.ToString()) { }
private static void AddMember(ref List <string> list, int longestMemberCategory, MemberTypes memberType, bool isPrivate, string memberName) { string memberCategory = (memberType.ToString() + ":").PadRight(longestMemberCategory + 1, ' '); list.Add(string.Format("[{0}] {1} {2}", isPrivate ? "-" : "+", memberCategory, memberName)); }
public object GetRealObject(StreamingContext context) { switch (_memberType) { case MemberTypes.Constructor: ConstructorInfo [] ctors; ctors = _reflectedType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); for (int i = 0; i < ctors.Length; i++) { if (ctors[i].ToString().Equals(_memberSignature)) { return(ctors[i]); } } throw new SerializationException("Failed to find serialized constructor"); case MemberTypes.Method: MethodInfo [] methods; methods = _reflectedType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); for (int i = 0; i < methods.Length; i++) { if ((methods[i]).ToString().Equals(_memberSignature)) { return(methods[i]); } } throw new SerializationException("Failed to find serialized method"); default: throw new SerializationException("Failed to get object for member type " + _memberType.ToString()); } }
internal void CheckAccessibility(MemberInfo member) { Type type; bool flag; bool flag1; Type declaringType; bool flag2; bool flag3; bool flag4; if (member == null) { throw new ArgumentNullException("member"); } MemberTypes memberType = member.MemberType; if (!this.NonPublic) { MemberTypes memberType1 = memberType; if (memberType1 <= MemberTypes.Method) { if (memberType1 == MemberTypes.Constructor) { ConstructorInfo constructorInfo = (ConstructorInfo)member; if (constructorInfo.IsPublic) { flag2 = true; } else { flag2 = (constructorInfo.IsAssembly || constructorInfo.IsFamilyOrAssembly ? this.InternalsVisible(constructorInfo.DeclaringType.Assembly) : false); } flag = flag2; } else if (memberType1 == MemberTypes.Field) { FieldInfo fieldInfo = (FieldInfo)member; if (fieldInfo.IsPublic) { flag3 = true; } else { flag3 = (fieldInfo.IsAssembly || fieldInfo.IsFamilyOrAssembly ? this.InternalsVisible(fieldInfo.DeclaringType.Assembly) : false); } flag = flag3; } else { if (memberType1 != MemberTypes.Method) { throw new NotSupportedException(memberType.ToString()); } MethodInfo methodInfo = (MethodInfo)member; if (methodInfo.IsPublic) { flag4 = true; } else { flag4 = (methodInfo.IsAssembly || methodInfo.IsFamilyOrAssembly ? this.InternalsVisible(methodInfo.DeclaringType.Assembly) : false); } flag = flag4; if (!flag && (member is MethodBuilder || member.DeclaringType == this.MapType(typeof(TypeModel)))) { flag = true; } } } else if (memberType1 == MemberTypes.Property) { flag = true; } else if (memberType1 == MemberTypes.TypeInfo) { type = (Type)member; flag = (type.IsPublic ? true : this.InternalsVisible(type.Assembly)); } else { if (memberType1 != MemberTypes.NestedType) { throw new NotSupportedException(memberType.ToString()); } type = (Type)member; do { if (type.IsNestedPublic || type.IsPublic) { flag1 = true; } else { flag1 = (type.DeclaringType == null || type.IsNestedAssembly || type.IsNestedFamORAssem ? this.InternalsVisible(type.Assembly) : false); } flag = flag1; if (!flag) { goto Label2; } declaringType = type.DeclaringType; type = declaringType; }while (declaringType != null); } Label2: if (!flag) { MemberTypes memberType2 = memberType; if (memberType2 == MemberTypes.TypeInfo || memberType2 == MemberTypes.NestedType) { throw new InvalidOperationException(string.Concat("Non-public type cannot be used with full dll compilation: ", ((Type)member).FullName)); } throw new InvalidOperationException(string.Concat("Non-public member cannot be used with full dll compilation: ", member.DeclaringType.FullName, ".", member.Name)); } } }
static bool HasEqualMemberType(MemberType commentMemberType, MemberTypes memberType) { return(commentMemberType.ToString().Equals(memberType.ToString(), StringComparison.OrdinalIgnoreCase)); }
public static void IsInMembertypeSet(MemberTypes value, string parameterName, MemberTypes enumFlagSet) { if ((value & enumFlagSet) != value || // Ensure the member is in the set (value & (value - 1)) != 0) // Ensure that there is only one flag in the value (i.e. value is a power of 2). { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ArgumentOutOfRange_InvalidEnumInSet, parameterName, value, enumFlagSet.ToString()), parameterName); } }
private string getPropiedades(Type tipo) { string codigo = ""; PropertyInfo[] propiedades; // Propiedades públicas codigo += this.SALTO; codigo += "//[PROPIEDADES PÚBLICAS]"; codigo += this.SALTO; propiedades = this.tipoDeClase.GetProperties(); foreach (PropertyInfo atributo in propiedades) { MethodInfo metodo = atributo.GetGetMethod(); // String ambito = metodo.GetMethodBody().GetILAsByteArray().ToString(); String ambito = ""; ambito = this.getAmbito(metodo); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + atributo.PropertyType + "},{\" + obj." + atributo.Name + " + \"},{\"" + atributo.GetValue(this.clase, null) + "\"}},\";"; } // Propiedades privadas y protegidas codigo += this.SALTO; codigo += "//[PROPIEDADES PRIVADAS Y PROTEGIDAS]"; codigo += this.SALTO; propiedades = this.tipoDeClase.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic); foreach (PropertyInfo atributo in propiedades) { String ambito = ""; if (atributo.GetGetMethod() != null) { ambito = this.getAmbito(atributo.GetGetMethod()); } codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + atributo.PropertyType + "},{\" + obj." + atributo.Name + " + \"},{\"" + atributo.GetValue(this.clase, null) + "\"}},\";"; } // Propiedades privadas estáticas codigo += this.SALTO; codigo += "//[PROPIEDADES PRIVADAS ESTÁTICAS]"; codigo += this.SALTO; // FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic); foreach (FieldInfo field in fieldInfos) { String ambito = this.getAmbitoField(field); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + field.FieldType + "},{\" + obj." + field.Name + " + \"},{\"" + field.GetValue(this.clase) + "\"}},\";"; } // Propiedades públicas estáticas codigo += this.SALTO; codigo += "//[PROPIEDADES PÚBLICAS ESTÁTICAS]"; codigo += this.SALTO; // FieldInfo[] fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); fieldInfos = this.tipoDeClase.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fieldInfos) { String ambito = this.getAmbitoField(field); codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{\"" + ambito + "\"}, {" + field.FieldType + "},{\" + obj." + field.Name + " + \"},{\"" + field.GetValue(this.clase) + "\"}},\";"; } // Otras propiedades complejas (OJO, aparecen también estáticas) codigo += this.SALTO; codigo += "[MIEMBROS]"; codigo += this.SALTO; MemberInfo[] miembros = this.tipoDeClase.GetMembers(); foreach (MemberInfo miembro in miembros) { if (miembro.MemberType.ToString() != "Method" && miembro.MemberType.ToString() != "Constructor" && miembro.MemberType.ToString() != "Property" // Ya estaban identificadas antes con PropertyInfo ) { codigo += this.SALTO + this.TAB + this.TAB; /* * Type tipo1 = Type.GetType(miembro.GetProperty("FieldType").ToString()); * codigo += "Tipo de miembro " + tipo1.ToString(); */ MemberTypes tipoDeMiembro = miembro.MemberType; if (tipoDeMiembro.ToString() == "NestedType") { if (tipoDeMiembro.GetType().IsEnum) { codigo += this.SALTO + this.TAB + this.TAB; codigo += "// A continuación se declara el tipo " + miembro.GetType().ReflectedType + " - " + miembro.Name + ""; codigo += Type.GetTypeCode(miembro.GetType()).ToString(); } } else { codigo += this.SALTO + this.TAB + this.TAB; codigo += "texto += \"{{" + miembro.MemberType.ToString() + "},{\" + obj." + miembro.Name + " + \"}},\";"; } /* codigo += miembro.ReflectedType; // Indica el tipo de miembro que es * codigo += this.SALTO; * codigo += miembro.DeclaringType; // Indica la clase de este miembro * codigo += this.SALTO; * codigo += miembro.GetType(); // Tipo de objeto del campo * codigo += this.SALTO; */ } } return(codigo); }