/// <summary>
 /// Sets the value of a property by name.
 /// </summary>
 /// <param name="name">The name of the property.</param>
 /// <param name="value">The value to set to the property.</param>
 /// <param name="indexArgs">Optional index arguments if the property has any.</param>
 public void SetProperty(string name, object value, params object[] indexArgs)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var prop = MockingUtil.ResolveProperty(this.type, name, false, indexArgs, this.instance != null, value, getter: false);
         ProfilerInterceptor.GuardExternal(() => SecuredReflectionMethods.SetProperty(prop, this.instance, value, indexArgs));
     });
 }
 /// <summary>
 /// Gets the value of a property by name.
 /// </summary>
 /// <param name="name">The name of the property.</param>
 /// <param name="indexArgs">Optional index arguments if the property has any.</param>
 /// <returns>The value of the property.</returns>
 public object GetProperty(string name, params object[] indexArgs)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var prop = MockingUtil.ResolveProperty(this.type, name, false, indexArgs, this.instance != null);
         return ProfilerInterceptor.GuardExternal(() => SecuredReflectionMethods.GetProperty(prop, this.instance, indexArgs));
     }));
 }
        private DynamicMetaObject DoBindSetMember(ExpressionContainer wrapper, Type returnType, string memberName, bool ignoreCase, DynamicMetaObject value)
        {
            var valueExpr = wrapper.Expression;
            var property  = MockingUtil.ResolveProperty(valueExpr.Type, memberName, ignoreCase, new object[0], !wrapper.IsStatic, value.Value, getter: false);

            if (property == null)
            {
                ThrowMissingMemberException(valueExpr.Type, memberName);
            }

            var memberExpr = Expression.Assign(Expression.Property(!wrapper.IsStatic ? valueExpr : null, property), FromArg(value));

            return(CreateRecorder(memberExpr, returnType, BindingRestrictions.GetInstanceRestriction(this.Expression, this.Value)));
        }
        private DynamicMetaObject DoBindGetMember(Type returnType, string memberName, bool ignoreCase)
        {
            var wrapper   = this.Value as ExpressionContainer;
            var valueExpr = wrapper.Expression;
            var property  = MockingUtil.ResolveProperty(valueExpr.Type, memberName, ignoreCase, new object[0], !wrapper.IsStatic);

            if (property == null)
            {
                ThrowMissingMemberException(valueExpr.Type, memberName);
            }

            var memberExpr = Expression.Property(!wrapper.IsStatic ? valueExpr : null, property);

            return(CreateRecorder(memberExpr, returnType));
        }
        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
        {
            var wrapper   = this.Value as ExpressionContainer;
            var valueExpr = wrapper.Expression;
            var property  = MockingUtil.ResolveProperty(valueExpr.Type, "Item", false,
                                                        indexes.Select(i => i.Value).ToArray(), !wrapper.IsStatic);

            if (property == null)
            {
                ThrowMissingMemberException(valueExpr.Type, "Item");
            }

            var memberExpr = Expression.MakeIndex(!wrapper.IsStatic ? valueExpr : null, property, indexes.Select(FromArg));

            return(CreateRecorder(memberExpr, binder.ReturnType, BindingRestrictions.GetInstanceRestriction(this.Expression, this.Value)));
        }
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            var wrapper   = this.Value as ExpressionContainer;
            var valueExpr = wrapper.Expression;
            var property  = MockingUtil.ResolveProperty(valueExpr.Type, "Item", false,
                                                        indexes.Select(i => i.Value).ToArray(), !wrapper.IsStatic, value.Value, getter: false);

            if (property == null)
            {
                ThrowMissingMemberException(valueExpr.Type, "Item");
            }

            var memberExpr = Expression.Assign(
                Expression.MakeIndex(!wrapper.IsStatic ? valueExpr : null, property, indexes.Select(FromArg)),
                FromArg(value));

            return(CreateRecorder(memberExpr, binder.ReturnType));
        }