public object Build(Type interfaceType, KeyedDescription description) { DialogTrace.WriteLine("Building {0} for {1}", interfaceType.Name, description.Key ?? "-empty-"); if (!ShouldBuildDescription(description)) { DialogTrace.WriteLine("Skipping - not for this platform"); return(null); } TypedUserInterfaceBuilder typeBuilder; if (!_builderRegistry.TryGetValue(interfaceType, out typeBuilder)) { DialogTrace.WriteLine("No builder found for that {0}", interfaceType.Name); return(null); } var userInterfaceInstance = typeBuilder.Build(description); if (userInterfaceInstance == null) { DialogTrace.WriteLine("Builder returned NULL for {0}", interfaceType.Name); return(null); } FillProperties(userInterfaceInstance, description.Properties); FillBuildableProperties(description, userInterfaceInstance); return(userInterfaceInstance); }
public object Build(KeyedDescription description) { if (!ShouldBuildDescription(description)) { return(null); } var key = string.IsNullOrEmpty(description.Key) ? DefaultKey : description.Key; Type type; if (!KnownKeys.TryGetValue(key, out type)) { throw new KeyNotFoundException("Could not find class for " + description.Key); } var constructor = type.GetConstructors() .FirstOrDefault(c => c.GetParameters().All(p => p.IsOptional)); if (constructor == null) { throw new ArgumentException("No parameterless Constructor found for " + key); } // due to Mono and WP implementation issues, we don't use Type.Missing //var parameters = constructor.GetParameters().Select(p => (object)Type.Missing).ToArray(); var parameters = constructor.GetParameters().Select(p => p.DefaultValue).ToArray(); var instance = constructor.Invoke(null, parameters); return(instance); }
private static TResult LoadUserInterfaceFromDescription <TBuildable, TResult>( this IMvxAutoView view, KeyedDescription description) { var factory = Mvx.Resolve <IMvxUserInterfaceFactory>(); return(factory.Build <TBuildable, TResult>(view, description)); }
private void FillBuildableProperties(KeyedDescription description, object userInterfaceInstance) { var reservedPropertyNames = new[] { "Key", "Properties", "NotFor", "OnlyFor" }; var buildableProperties = from p in description.GetType().GetProperties() where !reservedPropertyNames.Contains(p.Name) select p; foreach (var buildablePropertyInfo in buildableProperties) { FillBuildableProperty(description, userInterfaceInstance, buildablePropertyInfo); } }
public TResult Build <TBuildable, TResult>(IMvxAutoView view, KeyedDescription description) { var bindingViewController = view as IMvxTouchView; if (bindingViewController == null) { throw new MvxException( "View passed to MvxTouchUserInterfaceFactory must be an IMvxBindingViewController - type {0}", view.GetType().Name); } var registry = Mvx.Resolve <IBuilderRegistry>(); var builder = new MvxTouchUserInterfaceBuilder(bindingViewController, view.ViewModel, registry); var root = (TResult)builder.Build(typeof(TBuildable), description); return(root); }
private void FillBuildableProperty(KeyedDescription description, object userInterfaceInstance, PropertyInfo buildablePropertyInfo) { var buildablePropertyValue = buildablePropertyInfo.GetValue(description, null); var userInterfacePropertyInfo = userInterfaceInstance.GetType().GetProperty(buildablePropertyInfo.Name); if (userInterfacePropertyInfo == null) { var props = userInterfaceInstance.GetType().GetProperties().Select(p => p.Name); var available = string.Join("'", props); DialogTrace.WriteLine("No User Interface member for description property {0} on {1}", buildablePropertyInfo.Name, available); return; } if (buildablePropertyInfo.PropertyType.GetTypeInfo().IsGenericType) { var genericPropertyType = buildablePropertyInfo.PropertyType.GetGenericTypeDefinition(); if (genericPropertyType == typeof(Dictionary <int, int>).GetGenericTypeDefinition()) { DialogTrace.WriteLine("Filling Dictionary {0}", buildablePropertyInfo.Name); FillDictionary(buildablePropertyInfo, buildablePropertyValue, userInterfacePropertyInfo, userInterfaceInstance); } else if (genericPropertyType == typeof(List <int>).GetGenericTypeDefinition()) { DialogTrace.WriteLine("Filling List {0}", buildablePropertyInfo.Name); FillList(buildablePropertyInfo, buildablePropertyValue, userInterfacePropertyInfo, userInterfaceInstance); } else { throw new Exception("Unexpected Generic Property Type " + buildablePropertyInfo.PropertyType); } } else { DialogTrace.WriteLine("Filling Element {0}", buildablePropertyInfo.Name); FillUserInterfaceElement(buildablePropertyInfo, buildablePropertyValue, userInterfacePropertyInfo, userInterfaceInstance); } }
public TResult Build <TBuildable, TResult>(IMvxAutoView view, KeyedDescription description) { var bindingActivity = view as IMvxBindingContextOwner; if (bindingActivity == null) { throw new MvxException( "Activity passed to MvxAndroidUserInterfaceFactory must be an IMvxAndroidBindingContext - type {0}", view.GetType().Name); } var registry = Mvx.Resolve <IBuilderRegistry>(); var builder = new MvxAndroidUserInterfaceBuilder((IMvxAndroidBindingContext)bindingActivity.BindingContext, view.ViewModel, registry); var root = (TResult)builder.Build(typeof(TBuildable), description); return(root); }
public void Fill(KeyedDescription keyedDescription) { base.Fill(keyedDescription); keyedDescription.Key = Key; }