public override PropertyTreeMetaObject Bind(PropertyTreeMetaObject target, PropertyTreeNavigator navigator, IServiceProvider serviceProvider) { if (target == null) { throw new ArgumentNullException("target"); } if (navigator == null) { throw new ArgumentNullException("navigator"); } if (navigator.IsProperty) { var textValue = navigator.Value as string; if (textValue != null) { return(BindInitializeValue( target, navigator, serviceProvider, () => target.BindInitializeValue(textValue, serviceProvider))); } var exprValue = navigator.Value as Expression; if (exprValue != null) { var exprContext = ExpressionContext.Compose( CurrentExpressionContext, ExpressionContext.FromNameScope(FindNameScope(target)) ); exprValue = ExpressionUtility.LiftToCall(exprValue, exprContext); return(BindInitializeValue( target, navigator, serviceProvider, () => target.BindInitializer(exprValue, exprContext, serviceProvider))); } throw new NotImplementedException(); } var children = SelectChildren(navigator); return(BindChildNodes(target, navigator, NodeList.Create(children))); }
public override PropertyTreeMetaObject Bind(PropertyTreeMetaObject target, PropertyTreeNavigator navigator, IServiceProvider serviceProvider) { if (target == null) throw new ArgumentNullException("target"); if (navigator == null) throw new ArgumentNullException("navigator"); if (navigator.IsProperty) { string value = Convert.ToString(navigator.Value); var sp = ServiceProvider.Compose(ServiceProvider.FromValue(navigator), serviceProvider, this); var xml = (IXmlNamespaceResolver) sp.GetService(typeof(IXmlNamespaceResolver)); try { return target.BindInitializeValue(value, sp); } catch (Exception ex) { // Throw critical exceptions if they originate within PT; otherwise, allow // callback to decide how to handle them. if (ex.IsCriticalException()) throw; var descriptor = serviceProvider.GetService<ITypeDescriptorContext>(); string property; Type componentType; if (descriptor == null || descriptor.PropertyDescriptor == null) { property = navigator.QualifiedName.ToString(); componentType = descriptor.Instance.GetType(); } else { property = descriptor.PropertyDescriptor.Name; componentType = descriptor.PropertyDescriptor.ComponentType; } FileLocation loc = navigator.FileLocation; try { Callback.OnConversionException(property, value, ex); } catch (Exception ex2) { if (Require.IsCriticalException(ex2)) throw; throw PropertyTreesFailure.BinderConversionError(value, property, componentType, ex2, loc); } } } var children = SelectChildren(navigator); return BindChildNodes(target, navigator, NodeList.Create(children)); }