Exemplo n.º 1
0
        protected virtual ChainedSourceBinding CreateChainedBinding(object source, PropertyToken propertyToken,
                                                                    List <PropertyToken> remainingTokens)
        {
            if (propertyToken is IndexerPropertyToken indexPropertyToken)
            {
                var itemPropertyInfo = FindPropertyInfo(source);
                if (itemPropertyInfo == null)
                {
                    return(null);
                }

                return(new IndexerChainedSourceBinding(source, itemPropertyInfo, indexPropertyToken,
                                                       remainingTokens));
            }

            if (propertyToken is PropertyNamePropertyToken propertyNameToken)
            {
                var propertyInfo = FindPropertyInfo(source, propertyNameToken.PropertyName);

                if (propertyInfo == null)
                {
                    return(null);
                }

                return(new SimpleChainedSourceBinding(source, propertyInfo,
                                                      remainingTokens));
            }

            throw new BindingException("Unexpected property chaining - seen token type {0}",
                                       propertyToken.GetType().FullName);
        }
Exemplo n.º 2
0
        protected virtual ISourceBinding CreateLeafBinding(object source, PropertyToken propertyToken)
        {
            if (propertyToken is IndexerPropertyToken indexPropertyToken)
            {
                var itemPropertyInfo = FindPropertyInfo(source);
                if (itemPropertyInfo == null)
                {
                    return(null);
                }
                return(new IndexerLeafPropertyInfoSourceBinding(source, itemPropertyInfo, indexPropertyToken));
            }

            if (propertyToken is PropertyNamePropertyToken propertyNameToken)
            {
                var propertyInfo = FindPropertyInfo(source, propertyNameToken.PropertyName);
                if (propertyInfo == null)
                {
                    return(null);
                }
                return(new SimpleLeafPropertyInfoSourceBinding(source, propertyInfo));
            }

            if (propertyToken is EmptyPropertyToken)
            {
                return(new DirectToSourceBinding(source));
            }

            throw new BindingException("Unexpected property source - seen token type {0}", propertyToken.GetType().FullName);
        }