public bool TryCreateBinding(object source, MvxPropertyToken propertyToken, List<MvxPropertyToken> remainingTokens, out IMvxSourceBinding result) { var observable = source as IObservable<object>; if (observable != null) { var list = new List<MvxPropertyToken>(); if (!(propertyToken is MvxEmptyPropertyToken)) list.Add(propertyToken); list.AddRange(remainingTokens); result = new ObservableMvxSourceBinding(observable, list); return true; } result = null; return false; }
public bool TryCreateBinding(object source, MvxPropertyToken currentToken, List<MvxPropertyToken> remainingTokens, out IMvxSourceBinding result) { if (source != null) { Type bindingSourceType = null; Type bindingTypeParameter = null; if (currentToken is MvxEmptyPropertyToken) { var observable = source as IObservable<object>; if (observable != null) { result = new ObservableMvxSourceBinding<object>(observable, typeof(object), this._mainThreadDispatcher, remainingTokens); return true; } var implementedInterface = source .GetType() .GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(iface => ((iface.IsConstructedGenericType) && (iface.GetGenericTypeDefinition() == typeof(IObservable<>)))); if (implementedInterface != null) bindingSourceType = bindingTypeParameter = implementedInterface.GenericTypeArguments[0]; } else { var propertyNameToken = currentToken as MvxPropertyNamePropertyToken; if (propertyNameToken != null) { var propertyInfo = this.FindPropertyInfo(source, propertyNameToken.PropertyName); if (propertyInfo != null) { var propertyTypeInfo = propertyInfo.PropertyType.GetTypeInfo(); if ((propertyTypeInfo.IsGenericType) && (propertyTypeInfo.GetGenericTypeDefinition() == typeof(IObservable<>))) { source = propertyInfo.GetValue(source, ObservableMvxPropertySourceBindingFactoryExtension.EmptyObjectArray); if (source != null) { bindingSourceType = propertyTypeInfo.GenericTypeArguments[0]; bindingTypeParameter = (bindingSourceType.GetTypeInfo().IsValueType) ? bindingSourceType : typeof(object); } } } } } if (bindingTypeParameter != null) { result = (IMvxSourceBinding)Activator.CreateInstance( typeof(ObservableMvxSourceBinding<>).MakeGenericType(bindingTypeParameter), source, bindingSourceType, this._mainThreadDispatcher, remainingTokens); return true; } } result = null; return false; }
public bool TryCreateBinding(object source, MvxPropertyToken currentToken, List <MvxPropertyToken> remainingTokens, out IMvxSourceBinding result) { if (source != null) { Type bindingSourceType = null; Type bindingTypeParameter = null; if (currentToken is MvxEmptyPropertyToken) { var observable = source as IObservable <object>; if (observable != null) { result = new ObservableMvxSourceBinding <object>(observable, typeof(object), this._mainThreadDispatcher, remainingTokens); return(true); } var implementedInterface = source .GetType() .GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(iface => ((iface.IsConstructedGenericType) && (iface.GetGenericTypeDefinition() == typeof(IObservable <>)))); if (implementedInterface != null) { bindingSourceType = bindingTypeParameter = implementedInterface.GenericTypeArguments[0]; } } else { var propertyNameToken = currentToken as MvxPropertyNamePropertyToken; if (propertyNameToken != null) { var propertyInfo = this.FindPropertyInfo(source, propertyNameToken.PropertyName); if (propertyInfo != null) { var propertyTypeInfo = propertyInfo.PropertyType.GetTypeInfo(); if ((propertyTypeInfo.IsGenericType) && (propertyTypeInfo.GetGenericTypeDefinition() == typeof(IObservable <>))) { source = propertyInfo.GetValue(source, ObservableMvxPropertySourceBindingFactoryExtension.EmptyObjectArray); if (source != null) { bindingSourceType = propertyTypeInfo.GenericTypeArguments[0]; bindingTypeParameter = (bindingSourceType.GetTypeInfo().IsValueType) ? bindingSourceType : typeof(object); } } } } } if (bindingTypeParameter != null) { result = (IMvxSourceBinding)Activator.CreateInstance( typeof(ObservableMvxSourceBinding <>).MakeGenericType(bindingTypeParameter), source, bindingSourceType, this._mainThreadDispatcher, remainingTokens); return(true); } } result = null; return(false); }