public TypeDetailsInformation(TypeCode typeCode,
                               UnderlyingTypeInformation underlyingTypeInformation,
                               UnderlyingTypeInformation underlyingKeyTypeInformation,
                               Type type)
 {
     TypeCode = typeCode;
     UnderlyingTypeInformation    = underlyingTypeInformation;
     UnderlyingKeyTypeInformation = underlyingKeyTypeInformation;
     Type = type;
 }
Example #2
0
        private TypeDetailsInformation GetBaseTypeInformation(Type type, IMemberInfoWrapper memberInfoWrapper)
        {
            if (!IsNullableType(type) && TypeCodeMap.TryGetValue(type, out var typeCode))
            {
                return(new TypeDetailsInformation(typeCode, new UnderlyingTypeInformation(typeCode, false, type), null, memberInfoWrapper.GetMemberType()));
            }

            if (IsDictionaryType(type))
            {
                var underlyingGenericTypeKey   = type.GenericTypeArguments[0];
                var underlyingGenericTypeValue = type.GenericTypeArguments[1];

                var genericKeyTypeCode   = GetBaseTypeInformation(underlyingGenericTypeKey, memberInfoWrapper);
                var genericValueTypeCode = GetBaseTypeInformation(underlyingGenericTypeValue, memberInfoWrapper);

                var underlyingKeyTypeInformation = new UnderlyingTypeInformation(genericKeyTypeCode.TypeCode, genericKeyTypeCode.UnderlyingTypeInformation.IsEnum, genericKeyTypeCode.UnderlyingTypeInformation.Type);
                var underlyingTypeInformation    = new UnderlyingTypeInformation(genericValueTypeCode.TypeCode, genericValueTypeCode.UnderlyingTypeInformation.IsEnum, genericValueTypeCode.UnderlyingTypeInformation.Type);

                return(new TypeDetailsInformation(TypeCode.Dictionary, underlyingTypeInformation, underlyingKeyTypeInformation, memberInfoWrapper.GetMemberType()));
            }

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                var underlyingGenericType = type.GenericTypeArguments[0];
                var genericTypeCode       = GetBaseTypeInformation(underlyingGenericType, memberInfoWrapper);

                return(new TypeDetailsInformation(TypeCode.Enumerable,
                                                  new UnderlyingTypeInformation(
                                                      genericTypeCode.TypeCode,
                                                      genericTypeCode.UnderlyingTypeInformation.IsEnum,
                                                      genericTypeCode.UnderlyingTypeInformation.Type),
                                                  null,
                                                  memberInfoWrapper.GetMemberType()));
            }

            if (type.IsEnum)
            {
                var underlyingType         = Enum.GetUnderlyingType(type);
                var typeDetailsInformation = GetBaseTypeInformation(underlyingType, memberInfoWrapper);

                return(new TypeDetailsInformation(typeDetailsInformation.TypeCode,
                                                  new UnderlyingTypeInformation(TypeCode.Empty,
                                                                                true,
                                                                                type),
                                                  null,
                                                  memberInfoWrapper.GetMemberType()));
            }

            var nullable = Nullable.GetUnderlyingType(type);

            if (nullable == null)
            {
                return(new TypeDetailsInformation(TypeCode.ComplexObject,
                                                  new UnderlyingTypeInformation(TypeCode.Empty,
                                                                                false,
                                                                                type),
                                                  null,
                                                  memberInfoWrapper.GetMemberType()));
            }

            if (nullable.IsEnum)
            {
                var nullableUnderlyingType = Enum.GetUnderlyingType(nullable);
                var underlyingType         = GetBaseTypeInformation(nullableUnderlyingType, memberInfoWrapper);

                return(new TypeDetailsInformation(underlyingType.TypeCode,
                                                  new UnderlyingTypeInformation(TypeCode.Empty,
                                                                                true,
                                                                                nullableUnderlyingType),
                                                  null,
                                                  nullable));
            }

            return(new TypeDetailsInformation(TypeCode.Nullable,
                                              new UnderlyingTypeInformation(TypeCode.Empty,
                                                                            false,
                                                                            nullable),
                                              null,
                                              nullable));
        }