System.Type.GetFields C# (CSharp) Method

GetFields() public method

When overridden in a derived class, searches for the fields defined for the current T:System.Type, using the specified binding constraints.
public GetFields ( BindingFlags bindingAttr ) : FieldInfo[]
bindingAttr BindingFlags A bitmask comprised of one or more that specify how the search is conducted.-or- Zero, to return null.
return FieldInfo[]
        public FieldInfo[] GetFields(BindingFlags bindingAttr)
        {
            return fields.ToArray();
        }

Same methods

Type::GetFields ( ) : FieldInfo[]

Usage Example

 private static MemberInfo[] GetSerializableMembers2(Type type)
 {
     // get the list of all fields
     FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     int countProper = 0;
     for (int i = 0; i < fields.Length; i++)
     {
         if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
             continue;
         countProper++;
     }
     if (countProper != fields.Length)
     {
         FieldInfo[] properFields = new FieldInfo[countProper];
         countProper = 0;
         for (int i = 0; i < fields.Length; i++)
         {
             if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
                 continue;
             properFields[countProper] = fields[i];
             countProper++;
         }
         return properFields;
     }
     else
         return fields;
 }
All Usage Examples Of System.Type::GetFields