Exemplo n.º 1
0
        internal static void Reset()
        {
            Headers = new List <string>();

            PropertyGetters = new List <Func <T, object> >();
            var isDataContract = typeof(T).GetCustomAttributes(typeof(DataContractAttribute), false).Any();

            foreach (var propertyInfo in TypeConfig <T> .Properties)
            {
                if (!propertyInfo.CanRead || propertyInfo.GetGetMethod() == null)
                {
                    continue;
                }
                if (!TypeSerializer.CanCreateFromString(propertyInfo.PropertyType))
                {
                    continue;
                }

                PropertyGetters.Add(propertyInfo.GetValueGetter <T>());
                var propertyName = propertyInfo.Name;
                if (isDataContract)
                {
                    var dcsDataMember = propertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), false).FirstOrDefault() as DataMemberAttribute;
                    if (dcsDataMember != null && dcsDataMember.Name != null)
                    {
                        propertyName = dcsDataMember.Name;
                    }
                }
                Headers.Add(propertyName);
            }
        }
Exemplo n.º 2
0
            public RecordTypePropertyData(IEnumerable <T> records)
            {
                this.Headers = new List <string>();
                this.Rows    = new List <List <string> >();

                if (records == null)
                {
                    return;
                }

                var recordType = typeof(T);

                if (recordType.IsValueType || recordType == typeof(string))
                {
                    WriteSingleRow(records, recordType);
                    return;
                }

                var propertyGetters = new List <MethodInfo>();

                foreach (var propertyInfo in recordType.GetProperties())
                {
                    if (!propertyInfo.CanRead || propertyInfo.GetGetMethod() == null)
                    {
                        continue;
                    }
                    if (!TypeSerializer.CanCreateFromString(propertyInfo.PropertyType))
                    {
                        continue;
                    }
                    //if (propertyInfo.PropertyType.FindInterfaces((x, criteria) => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>), null).Length > 0) continue;

                    propertyGetters.Add(propertyInfo.GetGetMethod());
                    this.Headers.Add(propertyInfo.Name);
                }

                foreach (var record in records)
                {
                    var row = new List <string>();
                    foreach (var propertyGetter in propertyGetters)
                    {
                        var value = propertyGetter.Invoke(record, new object[0]) ?? "";

                        var strValue = value.GetType() == typeof(string)
                                                                ? (string)value
                                                                : TypeSerializer.SerializeToString(value);

                        row.Add(strValue);
                    }
                    this.Rows.Add(row);
                }
            }
Exemplo n.º 3
0
        internal static void Reset()
        {
            Headers = new List <string>();

            PropertyGetters = new List <Func <T, object> >();
            foreach (var propertyInfo in TypeConfig <T> .Properties)
            {
                if (!propertyInfo.CanRead || propertyInfo.GetGetMethod() == null)
                {
                    continue;
                }
                if (!TypeSerializer.CanCreateFromString(propertyInfo.PropertyType))
                {
                    continue;
                }

                PropertyGetters.Add(propertyInfo.GetValueGetter <T>());
                Headers.Add(propertyInfo.Name);
            }
        }