Represents the dynamic get index operation at the call site, providing the binding semantic and the details about the operation.
Inheritance: DynamicMetaObjectBinder
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes == null || indexes.Length != 1)
            {
                throw new ArgumentException(WebPageResources.DynamicDictionary_InvalidNumberOfIndexes);
            }

            result = null;
            string key = indexes[0] as string;
            if (key != null)
            {
                result = _state[key];
            }
            else if (indexes[0] is int)
            {
                result = _state[(int)indexes[0]];
            }
            else
            {
                // HttpApplicationState only supports keys of type string and int when getting 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 exception which might be confusing to the user.
                throw new ArgumentException(WebPageResources.DynamicHttpApplicationState_UseOnlyStringOrIntToGet);
            }
            return true;
        }
Esempio n. 2
0
 // Get the property value by index.
 public override bool TryGetIndex(
     GetIndexBinder binder, object[] indexes, out object result)
 {
     var key = (string)indexes[0];
     result = this[key];
     return true;
 }
Esempio n. 3
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            result = null;
            var index = indexes.FirstOrDefault();

            if (index == null)
                return false;

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

            result = attempt.Value;
            return attempt.Succeeded;
        }
Esempio n. 4
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Count() != 1)
            {
                return base.TryGetIndex(binder, indexes, out result);
            }

            var index = indexes.Single();

            if (_props.Contains(index))
            {
                result = _props[index];
                return true;
            }

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

            if (strinIndex != null && TryGetMemberImpl(strinIndex, out result))
            {
                return true;
            }

            return base.TryGetIndex(binder, indexes, out result);
        }
Esempio n. 5
0
 public override bool TryGetIndex(GetIndexBinder binder,
     object[] indexes, out object result)
 {
     var ndx = (int)indexes[0];
     result = new DynamicXml(_elements[ndx]);
     return true;
 }
Esempio n. 6
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Length > 1)
            {
                result = null;
                return false;
            }

            try
            {
                if (indexes[0] is int)
                {
                    result = GetMember(_record.GetName((int)indexes[0]));
                    return true;
                }
                else if (indexes[0] is string)
                {
                    result = GetMember((string)indexes[0]);
                    return true;
                }
                else
                {
                    result = null;
                    return false;
                }
            }
            catch
            {
                result = null;
                return false;
            }
        }
Esempio n. 7
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            result = PySharp.PyZero;
            if (indexes.Length != 1 && indexes.Length != 2)
                return false;

            var pyType = GetPyType();
            if (indexes.Length == 2 && indexes[1] is PyType)
                pyType = (PyType) indexes[1];

            if (pyType == PyType.DictType)
            {
                if (indexes[0] is int)
                    result = DictionaryItem((int) indexes[0]);
                if (indexes[0] is long)
                    result = DictionaryItem((long) indexes[0]);
                if (indexes[0] is string)
                    result = DictionaryItem((string) indexes[0]);
                if (indexes[0] is PyObject)
                    result = DictionaryItem((PyObject) indexes[0]);
            }
            else
            {
                // First index has be an int
                if (!(indexes[0] is int))
                    return false;

                var index = (int) indexes[0];
                if (pyType == PyType.TupleType || pyType == PyType.DerivedTupleType)
                    result = Item(index, pyType);
                else
                    result = Item(index);
            }
            return true;
        }
Esempio n. 8
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Length == 0)
                throw new Exception("Missing index");

            return dictionary.TryGetValue(indexes[0].ToString(), out result);
        }
Esempio n. 9
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            var index = indexes[0];
            try
            {
                int i = Int32.Parse(((string)index));
                var str_index = i.ToString();
                if (i > length)
                {
                    result = undefined;
                    return true;
                }
                result = Fields[str_index];
                return true;
            }
            catch { }

            try
            {
                int i = (int)index;
                if (i > length)
                {
                    result = undefined;
                    return true;
                }
                result = Fields[i.ToString()];
                return true;

            }
            catch
            {
                result = undefined;
                return true;
            }
        }
        public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            // X:\jsc.svn\examples\javascript\test\TestDynamicGetIndex\TestDynamicGetIndex\Application.cs

            result = default(object);

            return default(bool);
        }
Esempio n. 11
0
        /// <summary>
        /// 子オブジェクトから取得プロパティを検索しそれを呼びます。
        /// </summary>
        public override bool TryGetIndex(GetIndexBinder binder,
                                         object[] indexes,
                                         out object result)
        {
            var name = indexes[0] as string;

            return TryGetValue(name, out result);
        }
Esempio n. 12
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     if(indexes.Length == 1 && indexes[0].GetType() == typeof(HttpResponseHeader)) {
         result = _responseHeaders[(HttpResponseHeader)indexes[0]];
         return true;
     }
     return base.TryGetIndex(binder, indexes, out result);
 }
Esempio n. 13
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) {
     string key = GetKey(indexes);
     result = null;
     if (!String.IsNullOrEmpty(key)) {
         result = GetValue(key);
     }
     return true;
 }
Esempio n. 14
0
 public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
 {
     int index = (int)indexes[0];
     result = _list[index];
     if (result is IDictionary<string, object>)
         result = new DynamicJson(result as IDictionary<string, object>);
     return true;
 }
Esempio n. 15
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
			var innerResult = _inner.TryGetIndex(binder, indexes, out result);
			//special case, we need to check if the result is of a non-legacy dynamic type because if it is, we need 
			//to return the legacy type
			result = LegacyConverter.ConvertToLegacy(result);
			return innerResult;
        }
            public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
            {
                if (indexes.Length == 1 && indexes[0] is string)
                {
                    return this.TryGetMember((string)indexes[0], out result);
                }

                return base.TryGetIndex(binder, indexes, out result);
            }
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     if (indexes == null)
         throw new ArgumentNullException("indexes");
     if (indexes.Length != 1)
         throw new ArgumentException("Only support a single indexer parameter", "indexes");
     result = dictionary[indexes[0]];
     return dictionary.Contains(indexes[0]);
 }
Esempio n. 18
0
 /// <summary>
 /// Tries the index of the get.
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="indexes">The indexes.</param>
 /// <param name="result">The result.</param>
 /// <returns></returns>
 public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
 {
     if (base.TryGetIndex(binder, indexes, out result))
     {
         this.Recording.Add(new Invocation(InvocationKind.GetIndex, Invocation.IndexBinderName, Util.NameArgsIfNecessary(binder.CallInfo, indexes)));
         return(true);
     }
     return(false);
 }
Esempio n. 19
0
 public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
 {
     var index = (int)indexes[0];
     result = _list[index];
     var objects = result as IDictionary<string, object>;
     if (objects != null)
         result = new DynamicJson(objects);
     return true;
 }
Esempio n. 20
0
        // Get the property value by index.
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) {
            if (typeof(long).IsAssignableFrom(indexes[0].GetType())) {
                result = SConvert.ToObject(Values[(long)indexes[0]]);
                return true;
            }

            result = null;
            return false;
        }
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Length == 1 && indexes[0] is string)
            {
                result = GetValue((string)indexes[0]);
                return true;
            }

            return base.TryGetIndex(binder, indexes, out result);
        }
Esempio n. 22
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Length == 1) {
                XElement element = _elements[Convert.ToInt32(indexes[0])];
                result = new XmlNode(element);
                return true;
            }

            return base.TryGetIndex(binder, indexes, out result);
        }
Esempio n. 23
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     var index = indexes[0];
     result =
           (index is string) ? record[(string)index]
         : (index is int) ? record[(int)index]
         : null;
     if (result.Equals(DBNull.Value)) result = null;
     return true;
 }
Esempio n. 24
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     if (_element.HasElements) {
         new XmlNodeList(new[] { _element }).TryGetIndex(binder, indexes, out result);
     }
     else {
         result = _element.Value;
     }
     return true;
 }
Esempio n. 25
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     if (indexes.Length != 1 || indexes[0] is string == false)
     {
         result = null;
         return false;
     }
     result = GetValue((string)indexes[0]);
     return true;
 }
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes[0] is string)
            {
                return TryGetFieldFromName(indexes[0] as string, out result);
            }

            result = null;
            return false;
        }
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            // The indexed property is always named "Item" in C#
            IProperty prop = GetIndexProperty();
            result = prop.GetValue(RealObject, indexes);

            // Wrap the sub object if necessary. This allows nested anonymous objects to work.
            result = WrapObjectIfNeeded(result);

            return true;
        }
Esempio n. 28
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            var key = GetSingleIndexOrNull(indexes);

            if (!TryGetValue(key, out result) && _throwErrorOnMissingMethod)
                throw new MissingMemberException(String.Format(@"Member ""{0}"" was not found in the body of the JSON posted.", key));

            result = WrapObjectIfNessisary(result);

            return true;
        }
Esempio n. 29
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes == null || indexes.Length != 1)
            {
                throw new ArgumentException("Invalid number of indexes");
            }

            object index = indexes[0];
            result = this[(string)index];
            return true;
        }
Esempio n. 30
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     int index = 0;
     if (indexes.Length > 0)
     {
         index = (int)indexes[0];
         result = new DynamicXml(this.BaseElement.Elements().ToList()[index]);
         return true;
     }
     return base.TryGetIndex(binder, indexes, out result);
 }
Esempio n. 31
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Length != 1) {
                result = null;
                return false;
            }

            string header = indexes[0] as String;

            result = GetValue(header);
            return result != null;
        }
Esempio n. 32
0
        /// <summary>
        /// Attempts to get an index of the instance.
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="indexes"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
        {
            string name = indexes[0].ToString();

            Item item = _package.GetByName(name);

            if (item == null)
            {
                result = null;
                // DominicCronin: Not sure if this return value is intentional.... leaving it alone for now.
                return(true);
            }

            result = GetDynamicItemFromTridionPackageItem(item);
            return(true);
        }
Esempio n. 33
0
        public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
        {
            int index = (int)indexes[0];

            try
            {
                result = list[index];
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            result = null;
            return(false);
        }
Esempio n. 34
0
 public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[]
                                  indexes, out object result)
 {
     result = "test";
     return(true);
 }
Esempio n. 35
0
 /// <summary>
 /// Tries the index of the get.
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="indexes">The indexes.</param>
 /// <param name="result">The result.</param>
 /// <returns></returns>
 public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
 {
     return(RemoteInvoke(new Invocation(InvocationKind.GetIndex, Invocation.IndexBinderName, Util.NameArgsIfNecessary(binder.CallInfo, indexes)), out result));
 }
Esempio n. 36
0
 public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     result = null;
     return(false);
 }
Esempio n. 37
0
        public virtual new System.Dynamic.DynamicMetaObject BindGetIndex(GetIndexBinder binder, System.Dynamic.DynamicMetaObject[] indexes)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }
 public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
 {
     return(storedValues.TryGetValue((string)indexes[0], out result));
 }
Esempio n. 39
0
 /// <summary>
 /// Performs the binding of the dynamic get index operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetIndexBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="indexes">An array of <see cref="DynamicMetaObject"/> instances - indexes for the get index operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackGetIndex(this, indexes));
 }
Esempio n. 40
0
 public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result)
 {
     return(TryGetProperty(indexes[0] as string, out result));
 }
        public virtual new bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }
 //
 // Summary:
 //     Provides the implementation for operations that get a value by index. Classes
 //     derived from the System.Dynamic.DynamicObject class can override this method
 //     to specify dynamic behavior for indexing operations.
 //
 // Parameters:
 //   binder:
 //     Provides information about the operation.
 //
 //   indexes:
 //     The indexes that are used in the operation. For example, for the sampleObject[3]
 //     operation in C# (sampleObject(3) in Visual Basic), where sampleObject is derived
 //     from the DynamicObject class, indexes[0] is equal to 3.
 //
 //   result:
 //     The result of the index operation.
 //
 // Returns:
 //     true if the operation is successful; otherwise, false. If this method returns
 //     false, the run-time binder of the language determines the behavior. (In most
 //     cases, a run-time exception is thrown.)
 public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result);