Exemplo n.º 1
0
        internal void GenerateProperties()
        {
            Type baseType = Nullable.GetUnderlyingType(TypeGoInfo.Type);

            if (baseType == null)
            {
                baseType = TypeGoInfo.Type;
            }
            baseType = ReflectionHelper.GenerateTypeFromInterface(baseType, Options);

            List <System.Reflection.PropertyInfo> properties = ReflectionHelper.GetListOfProperties(baseType).ToList();

            Properties       = new BasePropertyGoInfo <TObject> [properties.Count];
            PropertiesLength = properties.Count;
            for (int i = 0; i < properties.Count; i++)
            {
                System.Reflection.PropertyInfo property     = properties[i];
                BasePropertyGoInfo <TObject>   propertyInfo = (BasePropertyGoInfo <TObject>)Activator.CreateInstance(typeof(PropertyGoInfo <,>)
                                                                                                                     .MakeGenericType(typeof(TObject), property.PropertyType), property, Options);
                TypeGoInfo.Properties[property.Name] = propertyInfo;
                propertyInfo.Index     = i;
                propertyInfo.Type      = property.PropertyType;
                propertyInfo.Name      = property.Name;
                propertyInfo.NameBytes = Options.Encoding.GetBytes(property.Name);
                Properties[i]          = propertyInfo;
            }
            for (int i = 0; i < Properties.Length; i++)
            {
                BasePropertyGoInfo <TObject> property = Properties[i];
                property.NameSerialized  = JsonConstantsString.Quotes.ToString();
                property.NameSerialized += property.Name;
                property.NameSerialized += JsonConstantsString.QuotesColon;
            }
        }
Exemplo n.º 2
0
        internal void RebuildProperties(List <MemberBinaryModelInfo> properties)
        {
            Properties       = new BasePropertyGoInfo <TObject> [TypeGoInfo.Properties.Count];
            PropertiesLength = TypeGoInfo.Properties.Count;
            int i = 0;

            foreach (KeyValuePair <string, BasePropertyGoInfo <TObject> > propertyKeyValue in TypeGoInfo.Properties)
            {
                BasePropertyGoInfo <TObject> property = propertyKeyValue.Value;
                property.Name      = propertyKeyValue.Key;
                property.NameBytes = Options.Encoding.GetBytes(property.Name);
                Properties[i]      = property;
                MemberBinaryModelInfo findProperty = properties.FirstOrDefault(x => x.Name == property.Name);
                property.Index = findProperty.Index;
                i++;
            }

            //order properties
            //re indexing properties because generation will set index of properties
            Properties = Properties.OrderBy(x => x.Index).ToArray();
            for (i = 0; i < Properties.Length; i++)
            {
                BasePropertyGoInfo <TObject> property = Properties[i];
                property.NameSerialized  = JsonConstantsString.Quotes.ToString();
                property.NameSerialized += property.Name;
                property.NameSerialized += JsonConstantsString.QuotesColon;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// json serialize
 /// </summary>
 /// <param name="handler"></param>
 /// <param name="value"></param>
 public void JsonSerialize(ref JsonSerializeHandler handler, ref TObject value)
 {
     handler.TextWriter.Write(JsonConstantsString.OpenBraket);
     for (int i = 0; i < Properties.Length; i++)
     {
         BasePropertyGoInfo <TObject> property = Properties[i];
         property.TypedJsonSerialize(ref handler, ref value);
         //object propertyValue = property.InternalGetValue(ref value);
         //if (propertyValue == null || propertyValue.Equals(property.DefaultValue))
         //    continue;
         //handler.TextWriter.Write(property.NameSerialized);
         //property.JsonSerialize(ref handler, ref propertyValue);
         //handler.TextWriter.Write(JsonConstantsString.Comma);
     }
     handler.TextWriter.RemoveLast(JsonConstantsString.Comma);
     handler.TextWriter.Write(JsonConstantsString.CloseBracket);
 }
        internal static void ExtractProperty(ref T instance, ref JsonDeserializer deserializer, BasePropertyGoInfo <T> basePropertyGo, ref JsonSpanReader json)
        {
            char character = json.Read();

            if (character == JsonConstantsString.Quotes)
            {
                basePropertyGo.JsonDeserializeString(ref instance, ref json);
                //return typeGo.JsonDeserialize(ref extract);
            }
            else if (character == JsonConstantsString.OpenBraket)
            {
                basePropertyGo.JsonDeserializeObject(ref instance, ref deserializer, ref json);
            }
            else if (character == JsonConstantsString.OpenSquareBrackets)
            {
                basePropertyGo.JsonDeserializeArray(ref instance, ref deserializer, ref json);
            }
            else
            {
                basePropertyGo.JsonDeserializeValue(ref instance, ref json);
                //var value = json.ExtractValue();
                //if (value[value.Length - 1] == JsonConstantsString.Comma)
                //    value = value.Slice(0, value.Length - 1);
                //if (typeGo == null || typeGo.JsonDeserialize == null)
                //{
                //    return new string(value);
                //}
                //return typeGo.JsonDeserialize(ref value);
            }
        }