Example #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();
     }
 }
Example #2
0
        public bool TrySerializeNonPrimitiveObject(Type type, out IValueMemberInfo[] output)
        {
            if (!this.GetCache.TryGetValue(type, out output))
            {
                //reflection on type
                output = TypeSerializerUtils.GetterValueFactory(type);
                if (type.Name.IndexOf("AnonymousType", StringComparison.Ordinal) == -1)
                {
                    //cache type
                    this.GetCache.Add(type, output);
                }
            }

            return(output != null);
        }
Example #3
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));
        }
Example #4
0
 public void WritePropertyName(string value, bool encode)
 {
     WritePropertyNameFast(TypeSerializerUtils.BuildPropertyName(value, _options.TextCase, encode));
 }