コード例 #1
0
        public void When_serializing_method_call_expression_with_parameter_and_variable_argument_B()
        {
            var m = typeof(Math).GetMethod(nameof(Math.Pow), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
            var v = System.Linq.Expressions.Expression.Constant(new VariableQueryArgument(2.0, typeof(double)));
            var b = System.Linq.Expressions.Expression.Convert(
                System.Linq.Expressions.Expression.MakeMemberAccess(v, typeof(VariableQueryArgument).GetProperty(nameof(VariableQueryArgument.Value))),
                typeof(double));
            var pExp             = System.Linq.Expressions.Expression.Parameter(typeof(double), "exp");
            var c                = System.Linq.Expressions.Expression.Call(m, b, pExp);
            var l                = System.Linq.Expressions.Expression.Lambda(c, pExp);
            var r                = (double)l.Compile().DynamicInvoke(8);
            var remoteExpression = l.ToRemoteLinqExpression();

            // throws on deep clone
            Should.Throw <ProtoException>(remoteExpression.Serialize);

            var config = ProtoBufTypeModel.ConfigureRemoteLinq().Model;

            using var memorystream = new MemoryStream();

            // while serialization seems fine ...
            config.Serialize(memorystream, remoteExpression);

            memorystream.Position = 0;
            var schema = config.GetSchema(remoteExpression.GetType(), ProtoSyntax.Proto3);

            // ... actually throws on deserialize.
            Should.Throw <ProtoException>(() => config.Deserialize(memorystream, null, remoteExpression.GetType()));
        }
コード例 #2
0
        public void Should_serialize_property(Type type, object value)
        {
            SkipUnsupportedDataType(type, value);

            var property = new Property("p1", value);

            var config = ProtoBufTypeModel.ConfigureRemoteLinq(configureDefaultSystemTypes: false)
                         .AddDynamicPropertyType(TypeHelper.GetElementType(type) ?? type)
                         .Compile();
            var copy = property.Serialize(config);

            copy.Value.ShouldBe(value);
        }
コード例 #3
0
        private static TypeModel CreateTypeModel()
        {
            var configuration = ProtoBufTypeModel.ConfigureRemoteLinq();

            var testdatatypes = TestData.TestTypes
                                .Select(x => (Type)x[0])
                                .Select(x => x.AsNonNullableType())
                                .Distinct()
                                .ToArray();

            testdatatypes.ForEach(x => configuration.AddDynamicPropertyType(x));

            return(configuration);
        }
コード例 #4
0
        public static TypeModel CreateModelFor(Type type)
        {
            if (type.IsCollection())
            {
                type = TypeHelper.GetElementType(type);
            }

            if (type.IsEnum)
            {
                type = typeof(string);
            }

            return(ProtoBufTypeModel.ConfigureRemoteLinq()
                   .AddDynamicPropertyType(type)
                   .Compile());
        }
        public void Should_serialize_property_set_2(Type type, object value)
        {
            SkipUnsupportedDataType(type, value);

            var propertySet = new PropertySet
            {
                { "p1", value },
            };

            var config = ProtoBufTypeModel.ConfigureRemoteLinq(configureDefaultSystemTypes: false)
                         .AddDynamicPropertyType(TypeHelper.GetElementType(type))
                         .Compile();
            var copy = propertySet.Clone(config);

            copy["p1"].ShouldBe(value);
        }