Example #1
0
        public PropertyConverter(PropertyInfo propertyInfo, IJsonConverter valueConverter)
        {
            var instance  = Expression.Parameter(Typeof <TObject> .Raw, "instance");
            var converter = Expression.Constant(valueConverter, valueConverter.GetType());

            Deserialize = BuildDeserializeMethod(instance, propertyInfo, converter);
            Read        = BuildReadMethod(instance, propertyInfo, converter);
            Serialize   = BuildSerializeMethod(instance, propertyInfo, converter);
            Write       = BuildWriteMethod(instance, propertyInfo, converter);
        }
Example #2
0
        public PropertyConverter(PropertyInfo property, IJsonConverter valueConverter)
        {
            var instance  = Expression.Parameter(Typeof <TOwner> .Raw, "instance");
            var converter = Expression.Constant(valueConverter, valueConverter.GetType());

            _serialize = SerializationUtils.BuildSerialize <Action <TOwner, TextWriter> >(instance, property, converter);
            _write     = SerializationUtils.BuildWrite <Action <TOwner, JsonObject> >(instance, property, converter);

            if (property.CanWrite)
            {
                _deserialize = SerializationUtils.BuildDeserialize <Action <JsonTokenizer, TOwner> >(instance, property, converter);
                _read        = SerializationUtils.BuildRead <Action <JsonObject, TOwner> >(instance, property, converter);
            }
            else
            {
                _deserialize = ReadonlyProperty;
                _read        = ReadonlyProperty;
            }
        }
Example #3
0
        public StructPropertyConverter(Type owner, PropertyInfo property, IJsonConverter valueConverter)
        {
            var instance  = Expression.Parameter(owner.MakeByRefType());
            var converter = Expression.Constant(valueConverter, valueConverter.GetType());

            Serialize = SerializationUtils.BuildSerialize <SerializeDelegate>(instance, property, converter);
            Write     = SerializationUtils.BuildWrite <WriteDelegate>(instance, property, converter);

            if (property.CanWrite)
            {
                Deserialize = SerializationUtils.BuildDeserialize <DeserializeDelegate>(instance, property, converter);
                Read        = SerializationUtils.BuildRead <ReadDelegate>(instance, property, converter);
            }
            else
            {
                Deserialize = ReadonlyProperty;
                Read        = ReadonlyProperty;
            }
        }