public override bool TrySetMember(SetMemberBinder binder, object value) { _Builder[_Table, binder.Name] = value; _Builder = null; return true; }
internal RecordBuilderResolver(RecordBuilder builder, string table) { _Builder = builder; _Table = table; }
public override bool TrySetMember(SetMemberBinder binder, object value) { _Builder[_Table, binder.Name] = value; _Builder = null; return(true); }
/// <summary> /// Creates a new record parsing the collection of dynamic lambda expressions provided, /// each with the 'x => x.Table.Column = Value' or 'x => x.Column = Value' forms. /// <para>The new record carries its own ad-hoc schema and clones of the values given.</para> /// </summary> /// <param name="caseSensitiveNames">Whether the table and column names of the schema of /// the new record are case sensitive or not.</param> /// <param name="specs">The collectoin of dynamic lambda expressions that specify the /// contents and schema of the new record.</param> /// <returns>A new record.</returns> public static IRecord Create(bool caseSensitiveNames, params Func <dynamic, object>[] specs) { if (specs == null) { throw new ArgumentNullException("specs", "List of specifications cannot be null."); } if (specs.Length == 0) { throw new ArgumentException("List of specifications cannot be empty."); } var builder = new RecordBuilder(caseSensitiveNames); for (int i = 0; i < specs.Length; i++) { var spec = specs[i]; if (spec == null) { throw new ArgumentNullException("Specification #{0} cannot be null.".FormatWith(i)); } var parser = DynamicParser.Parse(spec); var result = parser.Result; if (result == null) { throw new ArgumentNullException("Specification #{0}: '{1}' cannot resolve to null.".FormatWith(i, parser)); } if (result is DynamicNode.SetMember) // The assignation syntax... { var node = (DynamicNode.SetMember)result; if (node.Host is DynamicNode.Argument) // x.Column = value; { builder[node.Name] = node.Value; continue; } if (node.Host is DynamicNode.GetMember) // x.Table.Column = value; { var host = (DynamicNode.GetMember)node.Host; builder[host.Name, node.Name] = node.Value; continue; } } if (result is DynamicNode.Binary) { var node = (DynamicNode.Binary)result; if (node.Operation == ExpressionType.Equal) { var host = (DynamicNode.GetMember)node.Left; if (host.Host is DynamicNode.Argument) // x.Column == value; { builder[host.Name] = node.Right; continue; } if (host.Host is DynamicNode.GetMember) // x.Table.Column == value; { var member = (DynamicNode.GetMember)host.Host; if (member.Host is DynamicNode.Argument) { builder[member.Name, host.Name] = node.Right; continue; } } } } throw new ArgumentException("Specification #{0}: '{1}' is invalid.".FormatWith(i, parser)); } var record = builder.Create(); builder.Dispose(); return(record); }