예제 #1
0
 public ValueMemberInfo(Type type)
 {
     this.ObjectType = type;
     this.Code       = TypeSerializerUtils.GetTypeCode(type);
     this.IsType     = type != typeof(object);// && this.Code != TypeSerializerUtils.TypeCode.NotSetObject;
     WriteDelegate   = JsonWriter.GetWriteObjectDelegate(Code);
     if (this.IsType)
     {
         CheckForExtendedValueInfo();
     }
 }
예제 #2
0
        private void CheckForExtendedValueInfo()
        {
            var code = this.Code;

            if (!TypeSerializerUtils.HasExtendedValueInformation(code))
            {
                return;
            }

            Type type = null;

            //array?
            if (code == TypeSerializerUtils.TypeCode.Array)
            {
                type = ObjectType.GetElementType();
            }
#if !NETCOREAPP1_0
            else if (ObjectType.IsGenericType)
#else
            else if (ObjectType.GetTypeInfo().IsGenericType)
#endif
            {
                //generic list / dictionary
                var args = ObjectType.GetGenericArguments();
                var len  = args.Length;
                if (len == 2)
                {
                    //key value pair
                    //need to check if key is string
                    var keyCodeType = TypeSerializerUtils.GetTypeCode(args[0]);
                    if (keyCodeType != TypeSerializerUtils.TypeCode.String)
                    {
                        _errored = true;
                        return;
                    }

                    type = args[1];
                }
                else if (len == 1)
                {
                    //value only
                    type = args[0];
                }
            }

            ExtendedValueInfo = new ValueMemberInfo(type ?? typeof(object));
        }