Esempio n. 1
0
        private void CollectEnum(Type type)
        {
            var info = new EnumSerializationInfo
            {
                Name           = type.Name,
                Namespace      = type.Namespace,
                FullName       = type.FullName,
                UnderlyingType = type.GetEnumUnderlyingType().FullName,
                Attributes     = NeutralAttributeData.FromCustomAttributeArray(type.GetCustomAttributes())
            };

            this.collectedEnumInfo.Add(info);
        }
Esempio n. 2
0
        private ObjectSerializationInfo GetObjectInfo(Type type)
        {
            var isClass = !type.IsValueType;
            var members = new List <MemberSerializationInfo>();
            // Only KeyAttribute members
            var searchFirst  = true;
            var hiddenIntKey = 0;

            foreach (PropertyInfo item in type.GetProperties())
            {
                var member = new MemberSerializationInfo
                {
                    IsReadable    = (item.GetMethod != null) && item.GetMethod.IsPublic,
                    IsWritable    = (item.SetMethod != null) && item.SetMethod.IsPublic,
                    IsProperty    = true,
                    IsField       = false,
                    Name          = item.Name,
                    Type          = item.PropertyType.FullName,
                    ShortTypeName = item.PropertyType.Name,
                    Attributes    = NeutralAttributeData.FromCustomAttributeArray(item.GetCustomAttributes())
                };
                if (!member.IsReadable && !member.IsWritable)
                {
                    continue;
                }

                if (searchFirst)
                {
                    searchFirst = false;
                }

                members.Add(member);
                this.CollectCore(item.PropertyType); // recursive collect
            }

            foreach (FieldInfo item in type.GetFields())
            {
                var member = new MemberSerializationInfo
                {
                    IsReadable    = item.IsPublic && !item.IsStatic,
                    IsWritable    = item.IsPublic && !item.IsInitOnly && !item.IsStatic,
                    IsProperty    = true,
                    IsField       = false,
                    Name          = item.Name,
                    Type          = item.FieldType.FullName,
                    ShortTypeName = item.FieldType.Name,
                };
                if (!member.IsReadable && !member.IsWritable)
                {
                    continue;
                }

                if (searchFirst)
                {
                    searchFirst = false;
                }

                members.Add(member);
                this.CollectCore(item.FieldType); // recursive collect
            }

            var info = new ObjectSerializationInfo
            {
                IsClass = isClass,
                ConstructorParameters = null,
                Members    = members.ToArray(),
                Name       = GetMinimallyQualifiedClassName(type),
                FullName   = type.FullName,
                Namespace  = type.Namespace,
                Attributes = NeutralAttributeData.FromCustomAttributeArray(type.GetCustomAttributes())
            };

            return(info);
        }