private async Task ExecuteFunction(ObjectProxy instance, MethodInfo method, string methodName) { var parameters = method.GetParameters(); var parameterValueStores = parameters .Select(p => new SelfcontainedValueStore { Identifier = p.GetCustomAttribute <TitleAttribute>()?.Title ?? ObjectDisplay.Nicely(p), Value = ((p.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault) ? p.DefaultValue : p.ParameterType == typeof(DateTime) ? (object)DateTime.Today : null, ValueType = p.ParameterType, CustomView = p.GetCustomAttribute <CustomViewAttribute>()?.ResourceKey, }).ToList <IValueStore>(); var parameterValueStoresWithoutObservableCollections = parameterValueStores .Where(vs => IsObservableCollection(vs.ValueType) == false) .ToList(); var propertiesViewModels = PropertiesViewModels.Of(parameterValueStoresWithoutObservableCollections, _Objects); if (parameterValueStoresWithoutObservableCollections.Any()) { MethodInvocationTitle = methodName; MethodInvocationParameters = propertiesViewModels; MethodInvocationContinuation = new Command(async() => await InvokeMethod(instance, method, parameterValueStores)); ShowMethodInvocationDialog(parameterValueStoresWithoutObservableCollections); } else { await InvokeMethod(instance, method, parameterValueStores); } }
IEnumerable <Tuple <string, Symbol, Command> > GetFunctions(ObjectProxy instance, MethodInfo[] methods) { return(from m in methods where m.DeclaringType != typeof(object) where m.IsSpecialName == false where m.Name != "ToString" select Tuple.Create( m.GetCustomAttribute <TitleAttribute>()?.Title ?? ObjectDisplay.Nicely(m), m.GetCustomAttribute <IconAttribute>()?.Icon ?? Symbol.Placeholder, new Command(async() => { var methodName = m.GetCustomAttribute <TitleAttribute>()?.Title ?? ObjectDisplay.Nicely(m); var requireConfirmation = m.GetCustomAttribute <RequiresConfirmationAttribute>() != null; if (requireConfirmation) { await Show.Message(methodName + "?", onYes: async() => { await ExecuteFunction(instance, m, methodName); }); } else { await ExecuteFunction(instance, m, methodName); } }))); }
private void UpdateMenu(ObservableCollection <Type> types) { MenuItems.Clear(); foreach (var type in types) { var menuItemVM = new MenuItemViewModel { Label = type.GetTypeInfo().GetCustomAttribute <TitleAttribute>()?.Title ?? ObjectDisplay.Nicely(type), Symbol = type.GetTypeInfo().GetCustomAttribute <IconAttribute>()?.Icon ?? Symbol.Placeholder, Tag = type }; MenuItems.Add(menuItemVM); } }