Inheritance: DynamicMetaObjectBinder
Exemplo n.º 1
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            if (indexes.Length >= 1)
                dictionary[indexes[0].ToString()] = value;

            return true;
        }
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     // The indexed property is always named "Item" in C#
     IProperty prop = GetIndexProperty();
     prop.SetValue(RealObject, value, indexes);
     return true;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Tries the index of the set.
        /// </summary>
        /// <param name="binder">The binder.</param>
        /// <param name="indexes">The indexes.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value)
        {
            object outTemp;
            var    tCombinedArgs = indexes.Concat(new[] { value }).ToArray();

            return(RemoteInvoke(new Invocation(InvocationKind.GetIndex, Invocation.IndexBinderName, Util.NameArgsIfNecessary(binder.CallInfo, tCombinedArgs)), out outTemp));
        }
Exemplo n.º 4
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) {
     string key = GetKey(indexes);
     if (!String.IsNullOrEmpty(key)) {
         _values[key] = Json.WrapObject(value);
     }
     return true;
 }
Exemplo n.º 5
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;
            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull))
            {
                List<ParameterExpression> temps = new List<ParameterExpression>();
                List<Expression> initTemps = new List<Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref indexes, temps, initTemps);
                isByRef = isByRef.AddLast(false);

                // Convert the value to the target type
                DynamicMetaObject updatedValue = new DynamicMetaObject(value.CastOrConvertMethodArgument(
                                value.LimitType,
                                name,
                                "SetIndex",
                                temps,
                                initTemps), value.Restrictions);

                var result = BindComInvoke(method, indexes.AddLast(updatedValue), binder.CallInfo, isByRef, temps, initTemps);

                // Make sure to return the value; some languages need it.
                return new DynamicMetaObject(
                    Expression.Block(result.Expression, Expression.Convert(value.Expression, typeof(object))),
                    result.Restrictions
                );
            }

            return base.BindSetIndex(binder, indexes, value);
        }
Exemplo n.º 6
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
            //
            // Demand Full Trust to proceed with the binding.
            //

            new PermissionSet(PermissionState.Unrestricted).Demand();

            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;
            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                isByRef = isByRef.AddLast(false);
                var result = BindComInvoke(method, indexes.AddLast(value), binder.CallInfo, isByRef);

                // Make sure to return the value; some languages need it.
                return new DynamicMetaObject(
                    Expression.Block(result.Expression, Expression.Convert(value.Expression, typeof(object))),
                    result.Restrictions
                );
            }

            return base.BindSetIndex(binder, indexes, value);
        }
Exemplo n.º 7
0
        // Set the property value by index.
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) {
            if (typeof(long).IsAssignableFrom(indexes[0].GetType())) {
                Values[(long)indexes[0]] = SConvert.ToSettings(value);
                return true;
            }

            return false;
        }
            public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
            {
                if (indexes.Length == 1 && indexes[0] is string)
                {
                    return this.TrySetMember((string)indexes[0], value);
                }

                return base.TrySetIndex(binder, indexes, value);
            }
Exemplo n.º 9
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     if (indexes == null)
         throw new ArgumentNullException("indexes");
     if (indexes.Length != 1)
         throw new ArgumentException("Only support a single indexer parameter", "indexes");
     _dictionary[indexes[0]] = value;
     return true;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Tries the index of the set.
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="indexes">The indexes.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value)
 {
     if (base.TrySetIndex(binder, indexes, value))
     {
         var tCombinedArgs = indexes.Concat(new[] { value }).ToArray();
         this.Recording.Add(new Invocation(InvocationKind.GetIndex, Invocation.IndexBinderName, Util.NameArgsIfNecessary(binder.CallInfo, tCombinedArgs)));
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            if (!(indexes[0] is string))
            {
                return false;
            }

            _members[indexes[0] as string] = new MemberDescription(indexes[0] as string, value, new Type[] { });
            return true;
        }
		public bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value, TrySetIndexDelegate baseTrySetIndex)
		{
			if (indexes.Length > 1 || !(indexes[0] is string))
				return baseTrySetIndex(binder, indexes, value);

			var propertyName = (string)indexes[0];

			if (!accessor.TrySetProperty(propertyName, value))
				return baseTrySetIndex(binder, indexes, value);

			return true;
		}
Exemplo n.º 13
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            if (indexes == null || indexes.Length != 1)
            {
                throw new ArgumentException("Invalid number of indexes");
            }

            object index = indexes[0];
            // This cast should always succeed assuming TValue is dynamic.
            this[(string)index] = value;
            return true;
        }
Exemplo n.º 14
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     if (indexes[0] is string)
       {
     var key = indexes[0] as string;
     UpdateDictionary(key, value);
     return true;
       }
       else
       {
     return base.TrySetIndex(binder, indexes, value);
       }
 }
Exemplo n.º 15
0
        public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value)
        {
            int index = (int)indexes[0];

            try
            {
                list[index] = "" + (value);
                return(true);
            }catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
        }
Exemplo n.º 16
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     var token = JToken.FromObject(value);
     var i = (int)indexes[0];
     if (i >= array.Count)
     {
         while (array.Count != i)
             array.Add(null);
         array.Add(token);
     }
     else
         array[i] = token;
     return true;
 }
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            string index = ((string)indexes[0]).ToLower();
            Logger.Debug("TrySetIndex For " + index);

            if (_dictionary.ContainsKey(index))
            {
                _dictionary[index] = value;
            }
            else
            {
                _dictionary.Add(index, value);
            }

            return true;
        }
Exemplo n.º 18
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;
            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                isByRef = isByRef.AddLast(false);
                return BindComInvoke(method, indexes.AddLast(value), binder.CallInfo, isByRef);
            }

            return base.BindSetIndex(binder, indexes, value);
        }
Exemplo n.º 19
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) {
            if (indexes.Count() != 1) {
                return base.TrySetIndex(binder, indexes, value);
            }

            var index = indexes.Single();

            // try to access an existing member
            var strinIndex = index as string;

            if (strinIndex != null && TrySetMemberImpl(strinIndex, value)) {
                return true;
            }

            _props[indexes.Single()] = value;
            return true;
        }
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) {
            if (indexes == null || indexes.Length != 1) {
                throw new ArgumentException(WebPageResources.DynamicDictionary_InvalidNumberOfIndexes);
            }

            string key = indexes[0] as string;
            if (key != null) {
                _state[key] = value;
                return true;
            }
            else {
                // HttpApplicationState only supports keys of type string when setting values, so any attempt 
                // to use other types will result in an error. We throw an exception here to explain to the user what is wrong.
                // Returning false will instead cause a runtime binder error which might be confusing to the user.
                throw new ArgumentException(WebPageResources.DynamicHttpApplicationState_UseOnlyStringToSet);
            }
        }
Exemplo n.º 21
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
            if (indexes.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
                return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, indexes.AddLast(value), true);
            }

            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            if (target.TryGetPropertySetter(name, out method, value.LimitType) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType)) {

                return BindComInvoke(method, indexes.AddLast(value), binder.Arguments);
            }

            return base.BindSetIndex(binder, indexes, value);
        }
Exemplo n.º 22
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;
            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull)) {

                IList<ArgumentInfo> argInfos = binder.Arguments;
                ComBinderHelpers.ProcessArgumentsForCom(ref indexes, ref argInfos);
                // add an arginfo for the value
                argInfos = argInfos.AddLast(Expression.PositionalArg(argInfos.Count));

                return BindComInvoke(method, indexes.AddLast(value), argInfos);
            }

            return base.BindSetIndex(binder, indexes, value);
        }
Exemplo n.º 23
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            var index = indexes.FirstOrDefault();

            if (index == null)
                return false;

            Attempt attempt;
            var s = index as string;
            if (s != null)
            {
                attempt = Attempt.Do(() => _row[s] = value);
            }
            else
            {
                var isInt = index.AttemptGet(Convert.ToInt32);
                if (isInt.Succeeded)
                    attempt = Attempt.Do(() => _row[isInt.Value] = value);
                else return false;
            }

            return attempt.Succeeded;
        }
Exemplo n.º 24
0
 public virtual bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) {
     return false;
 }
Exemplo n.º 25
0
        public static bool TryBindSetIndex(SetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, DynamicMetaObject value, out DynamicMetaObject result) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");
            ContractUtils.RequiresNotNull(value, "value");

            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindSetIndex(binder, args, value);
                return true;
            } else {
                result = null;
                return false;
            }
        }
Exemplo n.º 26
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     object[] args = DynamicFriendlyOperationUtility.AddSetterValue(indexes, value);
     _appVar[GetIndexAccessOperation(indexes.Length)](args);
     return true;
 }
 public virtual new bool TrySetIndex(SetIndexBinder binder, Object[] indexes, Object value)
 {
   return default(bool);
 }
Exemplo n.º 28
0
		public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
		{
			//--- Debbuger Break --- //
			if(System.Diagnostics.Debugger.IsAttached)
				System.Diagnostics.Debugger.Break();
			//--- Debbuger Break --- //

			return base.TrySetIndex(binder, indexes, value);
		}
Exemplo n.º 29
0
 public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     var key = ConvertFromDynamicForKey(indexes[0]);
     if (value is DynamicYamlEmpty)
         node.Children.Remove(key);
     else
         node.Children[key] = ConvertFromDynamic(value);
     return true;
 }
Exemplo n.º 30
0
 public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value)
 {
     return(TrySetProperty(indexes[0] as string, value));
 }
Exemplo n.º 31
0
 public virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
 /// <summary>
 /// Performs the binding of the dynamic set index operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="SetIndexBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="indexes">An array of <see cref="DynamicMetaObject"/> instances - indexes for the set index operation.</param>
 /// <param name="value">The <see cref="DynamicMetaObject"/> representing the value for the set index operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
 {
     ArgumentNullException.ThrowIfNull(binder);
     return(binder.FallbackSetIndex(this, indexes, value));
 }
Exemplo n.º 33
0
 public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value)
 {
     return(base.TrySetIndex(binder, indexes, value));
 }
Exemplo n.º 34
0
            public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
                if (IsOverridden("TrySetIndex")) {
                    return CallMethodReturnLast("TrySetIndex", binder, DynamicMetaObject.GetExpressions(indexes), value.Expression, (e) => binder.FallbackSetIndex(this, indexes, value, e));
                }

                return base.BindSetIndex(binder, indexes, value);
            }
 public virtual new bool TrySetIndex(SetIndexBinder binder, Object[] indexes, Object value)
 {
     return(default(bool));
 }
        /// <summary>
        /// Sets a member in script, through an indexer. Corresponds to indexer setter syntax in the front-end language.
        /// </summary>
        /// <param name="binder">The binder provided by the call site.</param>
        /// <param name="indexes">The indexes to be used.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>true - We never defer behavior to the call site, and throw if invalid access is attempted.</returns>
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            if (indexes == null)
            {
                throw new ArgumentNullException("indexes");
            }

            if (indexes.Length != 1)
            {
                throw new ArgumentException("indexes", HRESULT.DISP_E_BADPARAMCOUNT.GetException());
            }

            object index = indexes[0];
            if (index == null)
            {
                throw new ArgumentOutOfRangeException("indexes");
            }

            // We don't cache resolved DISPIDs for indexers as they have the potential to be used for dynamic resolution
            // of a bunch of members, e.g. when indexing into arrays. This would flood the cache, likely for just a one-
            // time access. So we just don't cache in this case.
            object result = InvokeAndReturn(index.ToString(), NativeMethods.DISPATCH_PROPERTYPUT, false /* no DISPID caching */,
                                new object[] { value });

            return true;
        }
 public virtual bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
 {
     return(false);
 }
Exemplo n.º 38
0
 public virtual bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) => false;
Exemplo n.º 39
0
 public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackSetIndex(UnwrapSelf(), indexes, value);
 }
 public virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackSetIndex(this, indexes, value));
 }
Exemplo n.º 41
0
		public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
		{
			return accessor.TrySetIndex(binder, indexes, value, base.TrySetIndex);
		}
Exemplo n.º 42
0
        public virtual new System.Dynamic.DynamicMetaObject BindSetIndex(SetIndexBinder binder, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject value)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }