using System.Collections.Generic; using RethinkDb.Driver.Ast; namespace RethinkDb.Driver.Model { /// /// Dictionary of string,ReqlAst /// public class OptArgs : Dictionary { /// /// Fluent helper for setting dictionary[key] = value. /// public virtual OptArgs With(string key, object value) { if( key != null ) { this[key] = Util.ToReqlAst(value); } return this; } internal OptArgs with(string key, object value) { return With(key, value); } /// /// Fluent helper for setting dictionary[key] = List. /// public virtual OptArgs With(string key, IList value) { if( key != null ) { this[key] = Util.ToReqlAst(value); } return this; } internal virtual OptArgs with(string key, IList value) { return With(key, value); } /// /// Fluent helper for setting dictionary[key] = value multiple times /// for each Property=Value in the anonType. /// public virtual OptArgs With(object anonType) { var anonDict = PropertyHelper.ObjectToDictionary(anonType); foreach( var kvp in anonDict ) { this.with(kvp.Key, kvp.Value); } return this; } internal virtual OptArgs with(object anonType) { return With(anonType); } /// /// Fluent helper to copy all key value pairs from /// public virtual OptArgs With(OptArgs args) { foreach( var kvp in args ) this.with(kvp.Key, kvp.Value); return this; } /// /// Creates a new OptArg from all key value pairs in /// public static OptArgs FromMap(IDictionary map) { OptArgs oa = new OptArgs(); foreach( var kvp in map ) oa.Add(kvp.Key, kvp.Value); return oa; } /// /// Creates a new OptArg from all Property = Value pairs in anonymous type. /// public static OptArgs FromAnonType(object anonType) { OptArgs oa = new OptArgs(); oa.with(anonType); return oa; } } }