Get Serializable Fields - CSharp System.Reflection

CSharp examples for System.Reflection:FieldInfo

Description

Get Serializable Fields

Demo Code


using System.Reflection;
using System.Collections.Generic;
using System;/* w  w w .j  av a2  s .  c  o  m*/

public class Main{
        public static List<FieldInfo> GetSerializableFields(Type type)
        {
            List<FieldInfo> fields = new List<FieldInfo>(10);
            fields.AddRange(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly));
            RemoveNonSerializableFields(fields);
            if (type.BaseType != null && type.GetCustomAttributes(_includeBaseAttributeType, false).Length > 0)
            {
                fields.AddRange(GetSerializableFields(type.BaseType));
            }
            return fields;
        }
}

Related Tutorials