Пример #1
0
        public bool Evaluate(IDataDescriptor source, out IDataDescriptor result)
        {
            result = null;
            object value = source.Value;

            if (value == null)
            {
                return(false);
            }
            ParameterInfo[] indexerParams = IndexerDataDescriptor.GetIndexerTypes(value.GetType());
            object[]        convertedIndices;
            // Search indexer on source type
            if (indexerParams != null && ReflectionHelper.ConsumeParameters(_indices,
                                                                            indexerParams, false, out convertedIndices))
            { // Index on Item property
                result = new IndexerDataDescriptor(value, convertedIndices);
                return(true);
            }
            if (ReflectionHelper.ConvertTypes(_indices, new Type[] { typeof(int) },
                                              out convertedIndices))
            { // Collection index
                if (!ReflectionHelper.GetEnumerationEntryByIndex(value, (int)convertedIndices[0], out result))
                {
                    throw new XamlBindingException("Index '{0}' cannot be applied on '{1}'",
                                                   ToString(), value);
                }
                return(true);
            }
            return(false);
        }