//------------------------------------------------------ // // Constructors // //------------------------------------------------------ protected DefaultValueConverter(TypeConverter typeConverter, Type sourceType, Type targetType, bool shouldConvertFrom, bool shouldConvertTo, DataBindEngine engine) { _typeConverter = typeConverter; _sourceType = sourceType; _targetType = targetType; _shouldConvertFrom = shouldConvertFrom; _shouldConvertTo = shouldConvertTo; _engine = engine; }
private PropertyPathWorker(PropertyPath path, DataBindEngine engine) { _parent = path; _arySVS = new SourceValueState[path.Length]; _engine = engine; // initialize each level to NullDataItem, so that the first real // item will force a change for (int i=_arySVS.Length-1; i>=0; --i) { _arySVS[i].item = BindingExpression.CreateReference(BindingExpression.NullDataItem); } }
//----------------------------------------------------- // // Constructors // //----------------------------------------------------- internal ClrBindingWorker(BindingExpression b, DataBindEngine engine) : base(b) { PropertyPath path = ParentBinding.Path; if (ParentBinding.XPath != null) { path = PrepareXmlBinding(path); } if (path == null) { path = new PropertyPath(String.Empty); } if (ParentBinding.Path == null) { ParentBinding.UsePath(path); } _pathWorker = new PropertyPathWorker(path, this, IsDynamic, engine); _pathWorker.SetTreeContext(ParentBindingExpression.TargetElementReference); }
internal PropertyPathWorker(PropertyPath path, ClrBindingWorker host, bool isDynamic, DataBindEngine engine) : this(path, engine) { _host = host; _isDynamic = isDynamic; }
//------------------------------------------------------ // // Internal static API // //------------------------------------------------------ // static constructor - returns a ValueConverter suitable for converting between // the source and target. The flag indicates whether targetToSource // conversions are actually needed. // if no Converter is needed, return DefaultValueConverter.ValueConverterNotNeeded marker. // if unable to create a DefaultValueConverter, return null to indicate error. internal static IValueConverter Create(Type sourceType, Type targetType, bool targetToSource, DataBindEngine engine) { TypeConverter typeConverter; Type innerType; bool canConvertTo, canConvertFrom; bool sourceIsNullable = false; bool targetIsNullable = false; // sometimes, no conversion is necessary if (sourceType == targetType || (!targetToSource && targetType.IsAssignableFrom(sourceType))) { return ValueConverterNotNeeded; } // the type convert for System.Object is useless. It claims it can // convert from string, but then throws an exception when asked to do // so. So we work around it. if (targetType == typeof(object)) { // The sourceType here might be a Nullable type: consider using // NullableConverter when appropriate. (uncomment following lines) //Type innerType = Nullable.GetUnderlyingType(sourceType); //if (innerType != null) //{ // return new NullableConverter(new ObjectTargetConverter(innerType), // innerType, targetType, true, false); //} // return new ObjectTargetConverter(sourceType, engine); } else if (sourceType == typeof(object)) { // The targetType here might be a Nullable type: consider using // NullableConverter when appropriate. (uncomment following lines) //Type innerType = Nullable.GetUnderlyingType(targetType); // if (innerType != null) // { // return new NullableConverter(new ObjectSourceConverter(innerType), // sourceType, innerType, false, true); // } // return new ObjectSourceConverter(targetType, engine); } // use System.Convert for well-known base types if (SystemConvertConverter.CanConvert(sourceType, targetType)) { return new SystemConvertConverter(sourceType, targetType); } // Need to check for nullable types first, since NullableConverter is a bit over-eager; // TypeConverter for Nullable can convert e.g. Nullable<DateTime> to string // but it ends up doing a different conversion than the TypeConverter for the // generic's inner type, e.g. bug 1361977 innerType = Nullable.GetUnderlyingType(sourceType); if (innerType != null) { sourceType = innerType; sourceIsNullable = true; } innerType = Nullable.GetUnderlyingType(targetType); if (innerType != null) { targetType = innerType; targetIsNullable = true; } if (sourceIsNullable || targetIsNullable) { // single-level recursive call to try to find a converter for basic value types return Create(sourceType, targetType, targetToSource, engine); } // special case for converting IListSource to IList if (typeof(IListSource).IsAssignableFrom(sourceType) && targetType.IsAssignableFrom(typeof(IList))) { return new ListSourceConverter(); } // Interfaces are best handled on a per-instance basis. The type may // not implement the interface, but an instance of a derived type may. if (sourceType.IsInterface || targetType.IsInterface) { return new InterfaceConverter(sourceType, targetType); } // try using the source's type converter typeConverter = GetConverter(sourceType); canConvertTo = (typeConverter != null) ? typeConverter.CanConvertTo(targetType) : false; canConvertFrom = (typeConverter != null) ? typeConverter.CanConvertFrom(targetType) : false; if ((canConvertTo || targetType.IsAssignableFrom(sourceType)) && (!targetToSource || canConvertFrom || sourceType.IsAssignableFrom(targetType))) { return new SourceDefaultValueConverter(typeConverter, sourceType, targetType, targetToSource && canConvertFrom, canConvertTo, engine); } // if that doesn't work, try using the target's type converter typeConverter = GetConverter(targetType); canConvertTo = (typeConverter != null) ? typeConverter.CanConvertTo(sourceType) : false; canConvertFrom = (typeConverter != null) ? typeConverter.CanConvertFrom(sourceType) : false; if ((canConvertFrom || targetType.IsAssignableFrom(sourceType)) && (!targetToSource || canConvertTo || sourceType.IsAssignableFrom(targetType))) { return new TargetDefaultValueConverter(typeConverter, sourceType, targetType, canConvertFrom, targetToSource && canConvertTo, engine); } // nothing worked, give up return null; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ public ObjectSourceConverter(Type targetType, DataBindEngine engine) : base(null, typeof(object), targetType, true /* shouldConvertFrom */, false /* shouldConvertTo */, engine) { }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ public TargetDefaultValueConverter(TypeConverter typeConverter, Type sourceType, Type targetType, bool shouldConvertFrom, bool shouldConvertTo, DataBindEngine engine) : base(typeConverter, sourceType, targetType, shouldConvertFrom, shouldConvertTo, engine) { }
// listen for changes to a property internal void RegisterForChanges(object item, PropertyDescriptor pd, DataBindEngine engine) { // lazy creation of the cache if (_table == null) { _table = new HybridDictionary(); } ValueTableKey key = new ValueTableKey(item, pd); object value = _table[key]; if (value == null) { // new entry needed - add a listener INotifyPropertyChanged inpc = item as INotifyPropertyChanged; if (inpc != null) { PropertyChangedEventManager.AddHandler(inpc, OnPropertyChanged, pd.Name); } else { ValueChangedEventManager.AddHandler(item, OnValueChanged, pd); } } }
public DataBindEngineShutDownListener(DataBindEngine target) : base(target) { }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ public ObjectTargetConverter(Type sourceType, DataBindEngine engine) : base(null, sourceType, typeof(object), true /* shouldConvertFrom */, false /* shouldConvertTo */, engine) { }
internal override void OnShutDown(object target, object sender, EventArgs e) { DataBindEngine table = (DataBindEngine)target; table.OnShutDown(); }