/// <summary> /// Initializes a new instance of the <see cref="TypeResolverNodeFactory"/> class. /// </summary> /// <param name="expectedTypes">The expected types.</param> /// <param name="factorySettings">The factory settings to use.</param> /// <exception cref="System.ArgumentNullException">expectedTypes</exception> public TypeResolverNodeFactory(IEnumerable<Type> expectedTypes, FactorySettings factorySettings = null) : base(factorySettings) { if (expectedTypes == null) throw new ArgumentNullException("expectedTypes"); _expectedTypes = expectedTypes.ToArray(); }
public ExpressionSerializer(ISerializer serializer, FactorySettings factorySettings = null) { if (serializer == null) throw new ArgumentNullException("serializer"); _serializer = serializer; _factorySettings = factorySettings; }
protected virtual INodeFactory CreateFactory(Expression expression, FactorySettings factorySettings) { var lambda = expression as LambdaExpression; if(lambda != null) return new DefaultNodeFactory(lambda.Parameters.Select(p => p.Type), factorySettings); return new NodeFactory(factorySettings); }
/// <summary> /// Initializes a new instance of the <see cref="TypeResolverNodeFactory"/> class. /// </summary> /// <param name="expectedTypes">The expected types.</param> /// <param name="factorySettings">The factory settings to use.</param> /// <exception cref="System.ArgumentNullException">expectedTypes</exception> public TypeResolverNodeFactory(IEnumerable <Type> expectedTypes, FactorySettings factorySettings = null) : base(factorySettings) { if (expectedTypes == null) { throw new ArgumentNullException("expectedTypes"); } _expectedTypes = expectedTypes.ToArray(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultNodeFactory"/> class. /// </summary> /// <param name="types">The types.</param> /// <param name="factorySettings">The factory settings to use.</param> /// <exception cref="System.ArgumentNullException">types</exception> /// <exception cref="System.ArgumentException">types</exception> public DefaultNodeFactory(IEnumerable<Type> types, FactorySettings factorySettings = null) { if(types == null) throw new ArgumentNullException("types"); _types = types.ToArray(); if(_types.Any(t => t == null)) throw new ArgumentException("types"); _factorySettings = factorySettings ?? new FactorySettings(); _innerFactory = this.CreateFactory(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultNodeFactory"/> class. /// </summary> /// <param name="types">The types.</param> /// <param name="factorySettings">The factory settings to use.</param> /// <exception cref="System.ArgumentNullException">types</exception> /// <exception cref="System.ArgumentException">types</exception> public DefaultNodeFactory(IEnumerable <Type> types, FactorySettings factorySettings = null) { if (types == null) { throw new ArgumentNullException(nameof(types)); } _types = types.ToArray(); if (_types.Any(t => t == null)) { throw new ArgumentException("All types must be non-null.", nameof(types)); } Settings = factorySettings ?? new FactorySettings(); _innerFactory = CreateFactory(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultNodeFactory"/> class. /// </summary> /// <param name="types">The types.</param> /// <param name="factorySettings">The factory settings to use.</param> /// <exception cref="System.ArgumentNullException">types</exception> /// <exception cref="System.ArgumentException">types</exception> public DefaultNodeFactory(IEnumerable <Type> types, FactorySettings factorySettings = null) { if (types == null) { throw new ArgumentNullException("types"); } _types = types.ToArray(); if (_types.Any(t => t == null)) { throw new ArgumentException("types"); } _factorySettings = factorySettings ?? new FactorySettings(); _innerFactory = this.CreateFactory(); }
private void TestExpression(Expression<Func<Test, bool>> expression, ReadFieldOn readFieldOn) { var initialValue = 42; var actualValue = -1; // Initialize fields SetFields(initialValue); // Serialize expression var settings = new FactorySettings { AllowPrivateFieldAccess = true }; var serializer = new ExpressionSerializer(new JsonSerializer()); var value = serializer.SerializeText(expression, settings); // Modify fields SetFields(actualValue); // Deserialize expression var actualExpression = (Expression<Func<Test, bool>>)serializer.DeserializeText(value, new ExpressionContext { AllowPrivateFieldAccess = true }); var func = actualExpression.Compile(); // Set expected value. int expectedValue = readFieldOn == ReadFieldOn.Serialization ? initialValue : actualValue; // Assert Assert.IsTrue(func(new Test { IntProperty = expectedValue })); }
/// <summary> /// Initializes a new instance of the <see cref="NodeFactory"/> class. /// </summary> /// <param name="factorySettings">The factory settings to use.</param> public NodeFactory(FactorySettings factorySettings) { _factorySettings = factorySettings ?? new FactorySettings(); }
public byte[] SerializeBinary(Expression expression, FactorySettings factorySettings = null) { return this.BinarySerializer.Serialize(this.Convert(expression, factorySettings ?? _factorySettings)); }
public string SerializeText(Expression expression, FactorySettings factorySettings = null) { return this.TextSerializer.Serialize(this.Convert(expression, factorySettings ?? _factorySettings)); }
public void Serialize(Stream stream, Expression expression, FactorySettings factorySettings = null) { if (stream == null) throw new ArgumentNullException("stream"); _serializer.Serialize(stream, this.Convert(expression, factorySettings ?? _factorySettings)); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultNodeFactory"/> class. /// </summary> /// <param name="type">The type.</param> /// <param name="factorySettings">The factory settings to use.</param> public DefaultNodeFactory(Type type, FactorySettings factorySettings = null) : this(new [] { type }, factorySettings) { }
public ExpressionNode Convert(Expression expression, FactorySettings factorySettings = null) { var factory = this.CreateFactory(expression); return factory.Create(expression); }