/// <summary> /// Gets all the fields WITHOUT ANY of the specified attributes. /// </summary> public static FieldInfoCollection GetFieldsWithOutAttributes(Type type, params Type[] types) { FieldInfoCollection fields = new FieldInfoCollection(); bool match; foreach (FieldInfo field in type.GetFields()) { match = true; foreach (Type attType in types) { if (field.GetCustomAttributes(attType, true).Length != 0) match = false; } if (match) fields.Add(field); } return fields; }
/// <summary> /// Gets all the fields from the object's type with specified attribute /// </summary> public static FieldInfoCollection GetFieldsWithAttribute(Type type, Type attribute) { FieldInfoCollection fields = new FieldInfoCollection(); foreach (FieldInfo field in type.GetFields()) { if (field.GetCustomAttributes(attribute, true).Length > 0) fields.Add(field); } return fields; }