Пример #1
0
        public bool TryCreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory, out IObjectSourceProxy proxy)
        {
            proxy = null;
            if (source == null || token.HasNext() || !(token.Current is MemberNode))
            {
                return(false);
            }

            MemberInfo memberInfo = token.GetMemberInfo(source);

            if (memberInfo == null)
            {
                return(false);
            }

            var fieldInfo = memberInfo as FieldInfo;

            if (fieldInfo != null && typeof(IInteractionRequest).IsAssignableFrom(fieldInfo.FieldType))
            {
                proxy = new InteractionRequestFieldObjectSourceProxy(source, fieldInfo);
                return(true);
            }

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null && typeof(IInteractionRequest).IsAssignableFrom(propertyInfo.PropertyType))
            {
                proxy = new InteractionRequestPropertyObjectSourceProxy(source, propertyInfo);
                return(true);
            }

            return(false);
        }
Пример #2
0
        public bool TryCreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory, out IObjectSourceProxy proxy)
        {
            proxy = null;
            IPathNode node = token.Current;

            if (node is TypeNode)
            {
                TypeNode typeNode = (node as TypeNode);
                Type     type     = typeNode.Type;
                if (type == null)
                {
                    type = TypeFinderUtils.FindType(typeNode.Name);
                }

                if (type == null || !token.HasNext())
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Unable to bind: not found the \"{0}\" type.", typeNode.Name);
                    }

                    return(false);
                }

                proxy = CreateStaticProxy(type, token.NextToken(), factory);
                if (proxy != null)
                {
                    return(true);
                }
            }
            else
            {
                proxy = CreateProxy(source, token, factory);
                if (proxy != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        protected virtual IObjectSourceProxy CreateChainedProxy(object source, IPathNode node, PathToken nextToken, IObjectSourceProxyFactory factory)
        {
            var indexedNode = node as IndexedNode;

            if (indexedNode != null)
            {
                var itemPropertyInfo = this.FindItemPropertyInfo(source.GetType());
                if (itemPropertyInfo == null)
                {
                    return(null);
                }

                return(new ChainedItemObjectSourceProxy(source, itemPropertyInfo, nextToken, factory, indexedNode.Value));
            }

            var memberNode = node as MemberNode;

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

            var memberInfo = memberNode.MemberInfo;

            if (memberInfo == null)
            {
                memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name);
            }

            if (memberInfo == null || memberInfo.IsStatic())
            {
                return(null);
            }

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null)
            {
                var propertyType = propertyInfo.PropertyType;

                if (typeof(IObservableProperty).IsAssignableFrom(propertyType))
                {
                    IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy();
                    object             observableValue   = proxyPropertyInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ChainedObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue, nextToken, factory));
                }
                else
                {
                    return(new ChainedPropertyObjectSourceProxy(source, propertyInfo, nextToken, factory));
                }
            }

            var fieldInfo = memberInfo as FieldInfo;

            if (fieldInfo != null)
            {
                var fieldType = fieldInfo.FieldType;

                if (typeof(IObservableProperty).IsAssignableFrom(fieldType))
                {
                    IProxyFieldInfo proxyFieldInfo  = fieldInfo.AsProxy();
                    object          observableValue = proxyFieldInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ChainedObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue, nextToken, factory));
                }
                else
                {
                    return(new ChainedFieldObjectSourceProxy(source, fieldInfo, nextToken, factory));
                }
            }
            return(null);
        }
Пример #4
0
        public virtual IObjectSourceProxy CreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory)
        {
            if (source == null)
            {
                return(new EmptyObjectSourceProxy());
            }

            var node  = token.Current;
            var proxy = token.HasNext() ? this.CreateChainedProxy(source, node, token.NextToken(), factory) : this.CreateLeafProxy(source, node);

            if (proxy != null)
            {
                return(proxy);
            }

            if (log.IsWarnEnabled)
            {
                log.WarnFormat("Unable to bind: Not found the \"{0}\" member on the \"{1}\" type.", (node as MemberNode).Name, source.GetType().Name);
            }

            return(null);
        }
Пример #5
0
        public virtual IObjectSourceProxy CreateStaticProxy(Type type, PathToken token, IObjectSourceProxyFactory factory)
        {
            var node  = token.Current;
            var proxy = token.HasNext() ? this.CreateStaticChainedProxy(type, node, token.NextToken(), factory) : this.CreateStaticLeafProxy(type, node);

            if (proxy != null)
            {
                return(proxy);
            }

            if (log.IsWarnEnabled)
            {
                log.WarnFormat("Unable to bind: Not found the \"{0}\" member on the \"{1}\" type.", (node as MemberNode).Name, type.Name);
            }

            return(null);
        }
Пример #6
0
        protected virtual IObjectSourceProxy CreateStaticChainedProxy(Type type, IPathNode node, PathToken nextToken, IObjectSourceProxyFactory factory)
        {
            var memberNode = node as MemberNode;

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

            var memberInfo = memberNode.MemberInfo;

            if (memberInfo == null)
            {
                memberInfo = this.FindStaticMemberInfo(type, memberNode.Name);
            }

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

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null)
            {
                var propertyType = propertyInfo.PropertyType;

                if (typeof(IObservableProperty).IsAssignableFrom(propertyType))
                {
                    IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy();
                    object             observableValue   = proxyPropertyInfo.GetValue(null);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ChainedObservablePropertyObjectSourceProxy((IObservableProperty)observableValue, nextToken, factory));
                }
                else
                {
                    return(new ChainedPropertyObjectSourceProxy(propertyInfo, nextToken, factory));
                }
            }

            var fieldInfo = memberInfo as FieldInfo;

            if (fieldInfo != null)
            {
                var fieldType = fieldInfo.FieldType;

                if (typeof(IObservableProperty).IsAssignableFrom(fieldType))
                {
                    IProxyFieldInfo proxyFieldInfo  = fieldInfo.AsProxy();
                    object          observableValue = proxyFieldInfo.GetValue(null);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ChainedObservablePropertyObjectSourceProxy((IObservableProperty)observableValue, nextToken, factory));
                }
                else
                {
                    return(new ChainedFieldObjectSourceProxy(fieldInfo, nextToken, factory));
                }
            }
            return(null);
        }
Пример #7
0
 public AbstractChainedPropertyObjectSourceProxy(object source, PropertyInfo propertyInfo, PathToken nextToken, IObjectSourceProxyFactory factory) : base(source, propertyInfo)
 {
     this.nextToken = nextToken;
     this.factory   = factory;
 }
Пример #8
0
        public ChainedItemObjectSourceProxy(object source, PropertyInfo propertyInfo, PathToken nextToken, IObjectSourceProxyFactory factory, object key) : base(source, propertyInfo, nextToken, factory)
        {
            this._key = key;

            if (this.Source is INotifyCollectionChanged)
            {
                var sourceCollection = this.Source as INotifyCollectionChanged;
                sourceCollection.CollectionChanged += OnCollectionChanged;
            }

            this.UpdateChildProxy();
        }
Пример #9
0
 public ChainedPropertyObjectSourceProxy(object source, PropertyInfo propertyInfo, PathToken nextToken, IObjectSourceProxyFactory factory) : base(source, propertyInfo, nextToken, factory)
 {
     this.UpdateChildProxy();
 }
Пример #10
0
 public ChainedPropertyObjectSourceProxy(PropertyInfo propertyInfo, PathToken nextToken, IObjectSourceProxyFactory factory) : this(null, propertyInfo, nextToken, factory)
 {
 }
Пример #11
0
 public ChainedFieldObjectSourceProxy(object source, FieldInfo fieldInfo, PathToken nextToken, IObjectSourceProxyFactory factory) : base(source, fieldInfo)
 {
     this.nextToken = nextToken;
     this.factory   = factory;
     this.UpdateChildProxy();
 }
Пример #12
0
 public ChainedFieldObjectSourceProxy(FieldInfo fieldInfo, PathToken nextToken, IObjectSourceProxyFactory factory) : this(null, fieldInfo, nextToken, factory)
 {
 }
 public ChainedObservablePropertyObjectSourceProxy(object source, IObservableProperty observableProperty, PathToken nextToken, IObjectSourceProxyFactory factory) : base(source, observableProperty)
 {
     this.nextToken = nextToken;
     this.factory   = factory;
     this.UpdateChildProxy();
 }
 public ChainedObservablePropertyObjectSourceProxy(IObservableProperty observableProperty, PathToken nextToken, IObjectSourceProxyFactory factory) : this(null, observableProperty, nextToken, factory)
 {
 }