/// <summary> /// Catch a set member invocation /// </summary> /// <param name="binder"></param> /// <param name="value"></param> /// <returns></returns> public override bool TrySetMember(SetMemberBinder binder, object value) { var memberName = binder.Name; if (value is ElasticExpandoObject) { var eobj = value as ElasticExpandoObject; eobj.parent = this; if (!elements.Contains(eobj)) { this.elements.Add(eobj); } } else { if (!attributes.ContainsKey(memberName)) { attributes[memberName] = new ElasticExpandoObject(value, this, memberName); } else { attributes[memberName].InternalValue = value; } } OnPropertyChanged(memberName); return(true); }
/// <summary> /// Catch a binary operation /// </summary> /// <param name="binder"></param> /// <param name="arg"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) { if (binder.Operation == ExpressionType.And) { this.InternalContent = arg; result = this; return(true); } if (binder.Operation == ExpressionType.LeftShift) { if (arg is string) { var exp = new ElasticExpandoObject(null, this, arg as string); elements.Add(exp); result = exp; return(true); } else if (arg is ExpandoObject) { var eobj = arg as ElasticExpandoObject; eobj.parent = this; if (!elements.Contains(eobj)) { this.elements.Add(eobj); } result = eobj; return(true); } } return(base.TryBinaryOperation(binder, arg, out result)); }
public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result) { var obj = new ElasticExpandoObject(null, this, binder.Name); this.elements.Add(obj); result = obj; return(true); //return base.TryInvokeMember(binder, args, out result); }
/// <summary> /// Add a member to this element, with the specified value /// </summary> /// <param name="memberName"></param> /// <param name="value"></param> /// <returns></returns> internal ElasticExpandoObject CreateOrGetAttribute(string memberName, object value) { if (!attributes.ContainsKey(memberName)) { attributes[memberName] = new ElasticExpandoObject(value, this, memberName); return(attributes[memberName]); } else { return(attributes[memberName]); } }
/// <summary> /// Catch a get member invocation /// </summary> /// <param name="binder"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryGetMember(GetMemberBinder binder, out object result) { if (attributes.ContainsKey(binder.Name)) { result = attributes[binder.Name].value; } else { var obj = elements.FirstOrDefault(item => item.InternalName == binder.Name); if (obj != null) { result = obj; } else { var exp = new ElasticExpandoObject(null, this, binder.Name); elements.Add(exp); result = exp; } } return(true); }
public ElasticExpandoObject(object value, ElasticExpandoObject parent, string name) : this(name) { InternalValue = value; this.parent = parent; }
public ElasticExpandoObject(object value, ElasticExpandoObject parent, string name) : this(name) { InternalValue = value; this.parent = parent; }
/// <summary> /// Add a member to this element, with the specified value /// </summary> /// <param name="memberName"></param> /// <param name="value"></param> /// <returns></returns> internal ElasticExpandoObject CreateOrGetAttribute(string memberName, object value) { if (!attributes.ContainsKey(memberName)) { attributes[memberName] = new ElasticExpandoObject(value, this,memberName); return attributes[memberName]; } else { return attributes[memberName]; } }
/// <summary> /// Catch a set member invocation /// </summary> /// <param name="binder"></param> /// <param name="value"></param> /// <returns></returns> public override bool TrySetMember(SetMemberBinder binder, object value) { var memberName = binder.Name; if (value is ElasticExpandoObject) { var eobj=value as ElasticExpandoObject; eobj.parent = this; if (!elements.Contains(eobj)) this.elements.Add(eobj); } else { if (!attributes.ContainsKey(memberName)) { attributes[memberName] = new ElasticExpandoObject(value, this, memberName); } else { attributes[memberName].InternalValue = value; } } OnPropertyChanged(memberName); return true; }
public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result) { var obj = new ElasticExpandoObject(null, this, binder.Name); this.elements.Add(obj); result = obj; return true; //return base.TryInvokeMember(binder, args, out result); }
/// <summary> /// Catch a get member invocation /// </summary> /// <param name="binder"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryGetMember(GetMemberBinder binder, out object result) { if (attributes.ContainsKey(binder.Name)) { result = attributes[binder.Name].value; } else { var obj = elements.FirstOrDefault(item => item.InternalName == binder.Name); if (obj != null) { result = obj; } else { var exp = new ElasticExpandoObject(null, this, binder.Name); elements.Add(exp); result = exp; } } return true; }
/// <summary> /// Catch a binary operation /// </summary> /// <param name="binder"></param> /// <param name="arg"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) { if (binder.Operation == ExpressionType.And) { this.InternalContent = arg; result = this; return true; } if (binder.Operation == ExpressionType.LeftShift) { if (arg is string) { var exp = new ElasticExpandoObject(null, this, arg as string); elements.Add(exp); result = exp; return true; } else if (arg is ExpandoObject) { var eobj = arg as ElasticExpandoObject; eobj.parent = this; if (!elements.Contains(eobj)) this.elements.Add(eobj); result = eobj; return true; } } return base.TryBinaryOperation(binder, arg, out result); }