protected override bool TryCreateProxy(object source, LuaExpressionSourceDescription description, out ISourceProxy proxy) { proxy = null; if (source == null && !description.IsStatic) { proxy = new EmptSourceProxy(description); return(true); } List <ISourceProxy> list = new List <ISourceProxy>(); if (!description.IsStatic) { List <Path> paths = FindPaths(description.Paths); foreach (Path path in paths) { ISourceProxy innerProxy = this.factory.CreateProxy(source, new ObjectSourceDescription() { Path = path }); if (innerProxy != null) { list.Add(innerProxy); } } } proxy = new LuaExpressionSourceProxy(source, description.Expression, list); return(true); }
protected override bool TryCreateProxy(object source, ExpressionSourceDescription description, out ISourceProxy proxy) { proxy = null; var expression = description.Expression; List <ISourceProxy> list = new List <ISourceProxy>(); List <Path> paths = this.pathFinder.FindPaths(expression); foreach (Path path in paths) { if (!path.IsStatic) { if (source == null) { continue;//ignore the path } MemberNode memberNode = path[0] as MemberNode; if (memberNode != null && memberNode.MemberInfo != null && !memberNode.MemberInfo.DeclaringType.IsAssignableFrom(source.GetType())) { continue;//ignore the path } } ISourceProxy innerProxy = this.factory.CreateProxy(source, new ObjectSourceDescription() { Path = path }); if (innerProxy != null) { list.Add(innerProxy); } } try { var del = expression.Compile(); Type returnType = del.ReturnType(); Type parameterType = del.ParameterType(); if (parameterType != null) { proxy = (ISourceProxy)Activator.CreateInstance(typeof(ExpressionSourceProxy <,>).MakeGenericType(parameterType, returnType), source, del, list); } else { proxy = (ISourceProxy)Activator.CreateInstance(typeof(ExpressionSourceProxy <>).MakeGenericType(returnType), del, list); } } catch (Exception) { //JIT Exception Func <object[], object> del = expression.DynamicCompile(); proxy = new ExpressionSourceProxy(description.IsStatic ? null : source, del, description.ReturnType, list); } if (proxy != null) { return(true); } return(false); }
protected void CreateSourceProxy(object source, SourceDescription description) { Debug.LogError("CreateSourceProxy"); this.sourceProxy = this.sourceProxyFactory.CreateProxy(source, description); if (this.sourceProxy is INotifiable) { this.sourceValueChangedHandler = (sender, args) => this.UpdateTargetFromSource(); (this.sourceProxy as INotifiable).ValueChanged += this.sourceValueChangedHandler; } }
protected void CreateSourceProxy(object source, SourceDescription description) { this.DisposeSourceProxy(); this.sourceProxy = this.sourceProxyFactory.CreateProxy(description.IsStatic ? null : source, description); if (this.IsSubscribeSourceValueChanged(this.BindingMode) && this.sourceProxy is INotifiable) { this.sourceValueChangedHandler = (sender, args) => this.UpdateTargetFromSource(); (this.sourceProxy as INotifiable).ValueChanged += this.sourceValueChangedHandler; } }
protected override bool TryCreateProxy(object source, ExpressionSourceDescription description, out ISourceProxy proxy) { proxy = null; var expression = description.Expression; List <ISourceProxy> list = new List <ISourceProxy>(); if (!description.IsStatic) { List <Path> paths = this.pathFinder.FindPaths(expression); foreach (Path path in paths) { ISourceProxy innerProxy = this.factory.CreateProxy(source, new ObjectSourceDescription() { Path = path }); if (innerProxy != null) { list.Add(innerProxy); } } } #if UNITY_IOS Func <object[], object> del = expression.DynamicCompile(); proxy = new ExpressionSourceProxy(description.IsStatic ? null : source, del, description.ReturnType, list); #else try { var del = expression.Compile(); Type returnType = del.ReturnType(); Type parameterType = del.ParameterType(); if (parameterType != null) { proxy = (ISourceProxy)Activator.CreateInstance(typeof(ExpressionSourceProxy <,>).MakeGenericType(parameterType, returnType), source, del, list); } else { proxy = (ISourceProxy)Activator.CreateInstance(typeof(ExpressionSourceProxy <>).MakeGenericType(returnType), del); } } catch (Exception) { //JIT Exception Func <object[], object> del = expression.DynamicCompile(); proxy = new ExpressionSourceProxy(description.IsStatic ? null : source, del, description.ReturnType, list); } #endif if (proxy != null) { return(true); } return(false); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { this.Handler = null; if (this.proxy != null) { this.proxy.Dispose(); } this.proxy = null; this.Token = null; disposedValue = true; } }
public ISourceProxy CreateProxy(object source, SourceDescription description) { if (!IsSupported(description)) { return(null); } ISourceProxy proxy = null; if (TryCreateProxy(source, (T)description, out proxy)) { return(proxy); } return(proxy); }
public ISourceProxy CreateProxy(object source, SourceDescription description) { if (!description.IsStatic && source == null) { return(new EmptSourceProxy(description)); } ISourceProxy proxy = null; if (TryCreateProxy(source, description, out proxy)) { return(proxy); } throw new BindingException("Unable to bind: \"{0}\"", description.ToString()); }
public ISourceProxy CreateProxy(object source, SourceDescription description) { try { ISourceProxy proxy = null; if (TryCreateProxy(source, description, out proxy)) { return(proxy); } throw new NotSupportedException("Not found available proxy factory"); } catch (Exception e) { throw e; } }
protected void DisposeSourceProxy() { try { if (this.sourceProxy != null) { if (this.sourceValueChangedHandler != null) { (this.sourceProxy as INotifiable).ValueChanged -= this.sourceValueChangedHandler; this.sourceValueChangedHandler = null; } this.sourceProxy.Dispose(); this.sourceProxy = null; } } catch (Exception) { } }
public virtual ISourceProxy Create(object source, PathToken token) { ISourceProxy proxy = null; foreach (PriorityFactoryPair pair in this.factories) { var factory = pair.factory; if (factory == null) { continue; } proxy = factory.Create(source, token); if (proxy != null) { return(proxy); } } return(proxy); }
public ISourceProxy CreateProxy(object source, SourceDescription description) { try { if (!description.IsStatic && source == null) { return(new EmptSourceProxy(description)); } ISourceProxy proxy = null; if (TryCreateProxy(source, description, out proxy)) { return(proxy); } throw new NotSupportedException("Not found available proxy factory."); } catch (Exception e) { throw new ProxyException(e, "An exception occurred while creating a proxy for the \"{0}\".", description.ToString()); } }
private bool TryCreateProxy(object source, SourceDescription description, out ISourceProxy proxy) { proxy = null; return(false); }
public ProxyEntry(ISourceProxy proxy, PathToken token) { this.Proxy = proxy; this.Token = token; }
void Bind(object source, PathToken token) { int index = token.Index; ISourceProxy proxy = factory.Create(source, token); if (proxy == null) { var node = token.Current; if (node is MemberNode) { var memberNode = node as MemberNode; string typeName = source != null?source.GetType().Name : memberNode.Type.Name; throw new Exception(string.Format("Not found the member named '{0}' in the '{1}' type", memberNode.Name, typeName)); } throw new Exception("proxy is null."); } ProxyEntry entry = new ProxyEntry(proxy, token); proxies[index] = entry; if (token.HasNext()) { if (proxy is INotifiable) { entry.Handler = (sender, args) => { lock (_lock) { try { var proxyEntry = proxies[index]; if (proxyEntry == null || sender != proxyEntry.Proxy) { return; } Rebind(index); } catch (Exception e) { if (log.IsErrorEnabled) { log.ErrorFormat("{0}", e); } } } }; } var child = (proxy as IObtainable).GetValue(); if (child != null) { Bind(child, token.NextToken()); } else { this.RaiseValueChanged(); } } else { if (proxy is INotifiable) { entry.Handler = (sender, args) => { this.RaiseValueChanged(); } } ; this.RaiseValueChanged(); } } void Rebind(int index) { for (int i = proxies.Length - 1; i > index; i--) { ProxyEntry proxyEntry = proxies[i]; if (proxyEntry == null) { continue; } var proxy = proxyEntry.Proxy; proxyEntry.Proxy = null; if (proxy != null) { proxy.Dispose(); } } ProxyEntry entry = proxies[index]; var obtainable = entry.Proxy as IObtainable; if (obtainable == null) { this.RaiseValueChanged(); return; } var source = obtainable.GetValue(); if (source == null) { this.RaiseValueChanged(); return; } Bind(source, entry.Token.NextToken()); } void Unbind() { for (int i = proxies.Length - 1; i <= 0; i--) { ProxyEntry proxyEntry = proxies[i]; if (proxyEntry == null) { continue; } proxyEntry.Dispose(); proxies[i] = null; } }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { throw new ProxyException("The path nodes of the ObjectSourceDescription \"{0}\" is empty.", description.ToString()); } PathToken token = path.AsPathToken(); if (path.Count == 1) { proxy = this.Create(source, token); if (proxy != null) { return(true); } return(false); } proxy = new ChainedObjectSourceProxy(source, token, this); return(true); }
protected override bool TryCreateProxy(object source, LiteralSourceDescription description, out ISourceProxy proxy) { var value = description.Literal; if (value != null && value is IObservableProperty) { proxy = new ObservableLiteralSourceProxy(value as IObservableProperty); } else { proxy = new LiteralSourceProxy(value); } return(true); }
protected virtual bool TryCreateProxy(object source, SourceDescription description, out ISourceProxy proxy) { proxy = null; foreach (PriorityFactoryPair pair in this.factories) { var factory = pair.factory; if (factory == null) { continue; } try { proxy = factory.CreateProxy(source, description); if (proxy != null) { return(true); } } catch (MissingMemberException e) { throw e; } catch (NullReferenceException e) { throw e; } catch (Exception e) { if (log.IsWarnEnabled) { log.WarnFormat("An exception occurred when using the \"{0}\" factory to create a proxy for the \"{1}\";exception:{2}", factory.GetType().Name, description.ToString(), e); } } } proxy = null; return(false); }
protected override bool TryCreateProxy(object source, LiteralSourceDescription description, out ISourceProxy proxy) { proxy = new LiteralSourceProxy(description.Literal); return(true); }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { if (log.IsWarnEnabled) { log.Warn("Unable to bind: an empty path node list!."); } return(false); } if (path.IsStatic && path.Count < 2) { if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: the \"{0}\" path be unsupported.", path.ToString()); } return(false); } PathToken token = description.Path.AsPathToken(); proxy = CreateProxy(source, token); if (proxy != null) { return(true); } return(false); }
protected abstract bool TryCreateProxy(object source, T description, out ISourceProxy proxy);
protected virtual bool TryCreateProxy(object source, SourceDescription description, out ISourceProxy proxy) { proxy = null; foreach (PriorityFactoryPair pair in this.factories) { try { var factory = pair.factory; if (factory == null) { continue; } proxy = factory.CreateProxy(source, description); if (proxy != null) { return(true); } } catch (Exception e) { if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: \"{0}\";exception:{1}", description.ToString(), e); } } } proxy = null; return(false); }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { if (log.IsWarnEnabled) { log.Warn("Unable to bind: an empty path node list!."); } return(false); } PathToken token = path.AsPathToken(); if (path.Count == 1) { proxy = this.Create(source, token); if (proxy != null) { return(true); } return(false); } proxy = new ChainedObjectSourceProxy(source, token, this); return(true); }