private ICommonMethod[] GetPatchingMethods(IHasMethods viewModelType, ViewModelPatchingType patchingType) { return(viewModelType.Methods .Where(method => method.NotContainsAttribute <NotPatchingCommandAttribute>() && method.ReturnType == typeof(void) && !method.ParameterTypes.Any() && (!applicationPatcherWpfConfiguration.SkipConnectingByNameIfNameIsInvalid || nameRulesService.IsNameValid(method.Name, UseNameRulesFor.CommandExecuteMethod)) && ( patchingType == ViewModelPatchingType.All || method.ContainsAttribute <PatchingCommandAttribute>() || method.ContainsAttribute <ConnectMethodToMethodAttribute>() || method.ContainsAttribute <ConnectMethodToPropertyAttribute>())) .ToArray()); }
private CommonProperty[] GetCommonCommandProperties(CommonType viewModel, ViewModelPatchingType viewModelPatchingType) { switch (viewModelPatchingType) { case ViewModelPatchingType.All: return(viewModel.Properties .Where(property => property.Attributes.NotContains(typeof(NotCombineWithMethodAttribute)) && (property.Attributes.Contains(typeof(CombineWithMethodAttribute)) || property.IsInheritedFrom(typeof(ICommand)))) .ToArray()); case ViewModelPatchingType.Selectively: return(viewModel.Properties .Where(property => property.Attributes.Contains(typeof(CombineWithMethodAttribute))) .ToArray()); default: log.Error($"Not implement patching for commands with {nameof(ViewModelPatchingType)} = {viewModelPatchingType}"); throw new ArgumentOutOfRangeException(nameof(viewModelPatchingType), viewModelPatchingType, null); } }
private CommonMethod[] GetCommonCommandMethods(CommonType viewModel, ViewModelPatchingType viewModelPatchingType) { switch (viewModelPatchingType) { case ViewModelPatchingType.All: return(viewModel.Methods .Where(method => method.Attributes.NotContains(typeof(NotPatchingToCommandAttribute)) && (method.Attributes.Contains(typeof(PatchingToCommandAttribute)) || method.IsPublic)) .ToArray()); case ViewModelPatchingType.Selectively: return(viewModel.Methods .Where(method => method.Attributes.NotContains(typeof(NotPatchingToCommandAttribute))) .ToArray()); default: log.Error($"Not implement patching for commands with {nameof(ViewModelPatchingType)} = {viewModelPatchingType}"); throw new ArgumentOutOfRangeException(nameof(viewModelPatchingType), viewModelPatchingType, null); } }
public void Patch(MonoCecilAssembly monoCecilAssembly, CommonType viewModelBase, CommonType viewModel, ViewModelPatchingType viewModelPatchingType) { log.Info($"Patching {viewModel.FullName} commands..."); var commandMethods = GetCommonCommandMethods(viewModel, viewModelPatchingType); var commandProperties = GetCommonCommandProperties(viewModel, viewModelPatchingType); var commandsMembers = JoinMembers(commandMethods, commandProperties); }
public abstract PatchResult Patch(ICommonAssembly assembly, ICommonType viewModelBaseType, ICommonType viewModelType, ViewModelPatchingType patchingType);
public PatchingViewModelAttribute(ViewModelPatchingType patchingType = ViewModelPatchingType.All) { PatchingType = patchingType; }
protected void CheckValidViewModel(ICommonType viewModelType, ViewModelPatchingType viewModelPatchingType, params (string PropertyName, string FieldName)[] expectedGroups)
public PropertyGroup[] GetGroups(ICommonAssembly assembly, ICommonType viewModelType, ViewModelPatchingType patchingType) { var commandType = assembly.GetCommonType(KnownTypeNames.ICommand, true); CheckViewModel(commandType, viewModelType); var patchingProperties = GetPatchingProperties(viewModelType, commandType, patchingType); CheckPatchingPropertyNames(patchingProperties); var patchingPropertyGroups = GetPatchingPropertyGroups(patchingProperties, viewModelType, commandType); CheckPatchingPropertyGroups(patchingPropertyGroups); return(patchingPropertyGroups .Select(group => { var patchingPropertyAttribute = group.Property.GetCastedAttribute <PatchingPropertyAttribute>(); return new PropertyGroup( group.Fields.SingleOrDefault(), group.Property, GetCalledMethod(viewModelType, patchingPropertyAttribute?.CalledMethodNameBeforeGetProperty), GetCalledMethod(viewModelType, patchingPropertyAttribute?.CalledMethodNameBeforeSetProperty), GetCalledMethod(viewModelType, patchingPropertyAttribute?.CalledMethodNameAfterSuccessSetProperty), GetCalledMethod(viewModelType, patchingPropertyAttribute?.CalledMethodNameAfterSetProperty)); }) .ToArray()); }
private ICommonProperty[] GetPatchingProperties(IHasProperties viewModelType, IHasType commandType, ViewModelPatchingType patchingType) { return(viewModelType.Properties .Select(property => property) .Where(property => property.NotContainsAttribute <NotPatchingPropertyAttribute>() && (!applicationPatcherWpfConfiguration.SkipConnectingByNameIfNameIsInvalid || nameRulesService.IsNameValid(property.Name, UseNameRulesFor.Property)) && ( patchingType == ViewModelPatchingType.All && property.IsNotInheritedFrom(commandType) || property.ContainsAttribute <PatchingPropertyAttribute>() || property.ContainsAttribute <ConnectPropertyToFieldAttribute>())) .ToArray()); }
public CommandGroup[] GetGroups(ICommonAssembly assembly, ICommonType viewModelType, ViewModelPatchingType patchingType) { var commandType = assembly.GetCommonType(KnownTypeNames.ICommand, true); CheckViewModel(commandType, viewModelType); var patchingMethods = GetPatchingMethods(viewModelType, patchingType); CheckPatchingMethodNames(patchingMethods); var patchingCommandGroups = GetPatchingCommandGroups(patchingMethods, viewModelType, commandType); CheckPatchingCommandGroups(patchingCommandGroups); return(patchingCommandGroups.Select(group => new CommandGroup(group.Fields.SingleOrDefault(), group.Properties.SingleOrDefault(), group.ExecuteMethod, group.CanExecuteMethods.SingleOrDefault())).ToArray()); }
public void Patch(MonoCecilAssembly monoCecilAssembly, CommonType viewModelBase, CommonType viewModel, ViewModelPatchingType viewModelPatchingType) { log.Info($"Patching {viewModel.FullName} properties..."); var properties = GetCommonProperties(viewModel, viewModelPatchingType); if (!properties.Any()) { log.Info("Not found properties"); return; } log.Debug("Properties found:", properties.Select(property => property.FullName)); foreach (var property in properties) { log.Info($"Patching {property.FullName}..."); PatchProprty(monoCecilAssembly, viewModelBase, viewModel, property); log.Info($"{property.FullName} was patched"); } log.Info($"Properties {viewModel.FullName} was patched"); }
public override PatchResult Patch(ICommonAssembly assembly, ICommonType viewModelBaseType, ICommonType viewModelType, ViewModelPatchingType patchingType) { log.Info("Patching command groups..."); var commandGroups = commandGrouperService.GetGroups(assembly, viewModelType, patchingType); if (!commandGroups.Any()) { log.Info("Not found command groups"); return(PatchResult.Continue); } log.Debug("Command groups found:", commandGroups.Select(group => $"Execute method: '{group.CommandExecuteMethod.Name}', " + $"can execute method: '{group.CommandCanExecuteMethod?.Name}', " + $"property: '{group.CommandProperty?.Name}', " + $"field: '{group.CommandField?.Name}'")); foreach (var group in commandGroups) { log.Info("Patch group: " + $"Execute method: '{group.CommandExecuteMethod.Name}', " + $"can execute method: '{group.CommandCanExecuteMethod?.Name}', " + $"property: '{group.CommandProperty?.Name}', " + $"field: '{group.CommandField?.Name}'..."); PatchGroup(assembly, viewModelType, group); log.Info("Group was patched"); } log.Info("Command groups was patched"); return(PatchResult.Continue); }
public PatchingViewModelAttribute(ViewModelPatchingType viewModelPatchingType = ViewModelPatchingType.All) { ViewModelPatchingType = viewModelPatchingType; }
public override PatchResult Patch(ICommonAssembly assembly, ICommonType viewModelBaseType, ICommonType viewModelType, ViewModelPatchingType patchingType) { log.Info("Patching property groups..."); var propertyGroups = propertyGrouperService.GetGroups(assembly, viewModelType, patchingType); if (!propertyGroups.Any()) { log.Info("Not found property groups"); return(PatchResult.Continue); } log.Debug("Property groups found:", propertyGroups.Select(group => $"Property: '{group.Property.Name}', field: '{group.Field?.Name}'")); foreach (var group in propertyGroups) { log.Info($"Patch group: property: '{group.Property.Name}', field: '{group.Field?.Name}'..."); PatchGroup(assembly, viewModelBaseType, viewModelType, group); log.Info("Group was patched"); } log.Info("Property groups was patched"); return(PatchResult.Continue); }