public JsonType GetCommonType(JsonType type2)
        {
            

            var commonType = GetCommonTypeEnum(this.Type, type2);

            if (commonType == JsonTypeEnum.Array)
            {
                if (type2.Type == JsonTypeEnum.NullableSomething) return this;
                if (this.Type == JsonTypeEnum.NullableSomething) return type2;

                JsonType commonInternalType;
                if (InternalType == null && type2.InternalType != null) // Handling the case Test_4 where the first array is an empty object
                    commonInternalType = type2.InternalType;
                else commonInternalType = InternalType.GetCommonType(type2.InternalType).MaybeMakeNullable(generator);

                if (commonInternalType != InternalType) return new JsonType(generator, JsonTypeEnum.Array) { InternalType = commonInternalType };
            }


            //if (commonType == JsonTypeEnum.Dictionary)
            //{
            //    var commonInternalType = InternalType.GetCommonType(type2.InternalType);
            //    if (commonInternalType != InternalType) return new JsonType(JsonTypeEnum.Dictionary) { InternalType = commonInternalType };
            //}


            if (this.Type == commonType) return this;
            return new JsonType(generator, commonType).MaybeMakeNullable(generator);
        }
        public JsonType GetCommonType(JsonType type2)
        {
            var commonType = GetCommonTypeEnum(this.Type, type2.Type);

            if (commonType == JsonTypeEnum.Array)
            {
                if (type2.Type == JsonTypeEnum.NullableSomething)
                {
                    return(this);
                }

                if (this.Type == JsonTypeEnum.NullableSomething)
                {
                    return(type2);
                }

                var commonInternalType = InternalType.GetCommonType(type2.InternalType).MaybeMakeNullable(_generator);

                if (commonInternalType != InternalType)
                {
                    return(new JsonType(_generator, JsonTypeEnum.Array)
                    {
                        InternalType = commonInternalType
                    });
                }
            }

            return(this.Type == commonType ? this : new JsonType(_generator, commonType).MaybeMakeNullable(_generator));
        }
Пример #3
0
        public JsonType GetCommonType(JsonType type2)
        {
            var commonType = GetCommonTypeEnum(this.Type, type2.Type);

            if (commonType == JsonTypeEnum.Array)
            {
                if (type2.Type == JsonTypeEnum.NullableSomething)
                {
                    return(this);
                }
                if (this.Type == JsonTypeEnum.NullableSomething)
                {
                    return(type2);
                }
                var commonInternalType = InternalType.GetCommonType(type2.InternalType).MaybeMakeNullable(generator);
                if (commonInternalType != InternalType)
                {
                    return new JsonType(generator, JsonTypeEnum.Array)
                           {
                               InternalType = commonInternalType
                           }
                }
                ;
            }
            //if (commonType == JsonTypeEnum.Dictionary)
            //{
            //    var commonInternalType = InternalType.GetCommonType(type2.InternalType);
            //    if (commonInternalType != InternalType) return new JsonType(JsonTypeEnum.Dictionary) { InternalType = commonInternalType };
            //}
            if (this.Type == commonType)
            {
                return(this);
            }
            return(new JsonType(generator, commonType).MaybeMakeNullable(generator));
        }