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 static void RemoveAttributesFromViewModels(ICommonAssembly assembly) { var viewModelBaseType = assembly.GetCommonType(KnownTypeNames.ViewModelBase); var viewModelTypes = assembly.GetInheritanceCommonTypesFromThisAssembly(viewModelBaseType).ToArray(); foreach (var viewModelType in viewModelTypes.Select(type => type.Load())) { viewModelType.MonoCecil.RemoveAttributes <PatchingViewModelAttribute>(); viewModelType.MonoCecil.RemoveAttributes <NotPatchingViewModelAttribute>(); foreach (var property in viewModelType.Fields) { property.MonoCecil.RemoveAttributes <ConnectFieldToPropertyAttribute>(); } foreach (var property in viewModelType.Properties) { property.MonoCecil.RemoveAttributes <NotUseSearchByNameAttribute>(); property.MonoCecil.RemoveAttributes <PatchingPropertyAttribute>(); property.MonoCecil.RemoveAttributes <NotPatchingPropertyAttribute>(); property.MonoCecil.RemoveAttributes <ConnectPropertyToFieldAttribute>(); property.MonoCecil.RemoveAttributes <ConnectPropertyToMethodAttribute>(); } foreach (var property in viewModelType.Methods) { property.MonoCecil.RemoveAttributes <NotUseSearchByNameAttribute>(); property.MonoCecil.RemoveAttributes <PatchingCommandAttribute>(); property.MonoCecil.RemoveAttributes <NotPatchingCommandAttribute>(); property.MonoCecil.RemoveAttributes <ConnectMethodToMethodAttribute>(); property.MonoCecil.RemoveAttributes <ConnectMethodToPropertyAttribute>(); } } }
public override PatchResult Patch(ICommonAssembly assembly) { log.Info("Patching view model types..."); var selectingType = assembly.GetReflectionAttribute <SelectingViewModelAttribute>()?.SelectingType ?? applicationPatcherWpfConfiguration.DefaultViewModelSelectingType; log.Info($"View model selecting type: '{selectingType}'"); var viewModelBaseType = assembly.GetCommonType(KnownTypeNames.ViewModelBase, true).Load(); CheckAssembly(assembly, viewModelBaseType); var viewModelTypes = assembly.GetInheritanceCommonTypesFromThisAssembly(viewModelBaseType).ToArray(); if (!viewModelTypes.Any()) { log.Info("Not found view model types"); return(PatchResult.Continue); } log.Debug("View model types found:", viewModelTypes.Select(viewModel => viewModel.FullName).OrderBy(fullName => fullName)); var patchingViewModelTypes = viewModelTypes .Where(viewModelType => viewModelType.NotContainsReflectionAttribute <NotPatchingViewModelAttribute>() && (selectingType == ViewModelSelectingType.All || viewModelType.ContainsReflectionAttribute <PatchingViewModelAttribute>())) .ToArray(); if (!patchingViewModelTypes.Any()) { log.Info("Not found patching view model types"); return(PatchResult.Continue); } log.Debug("Patching view model types:", patchingViewModelTypes.Select(viewModel => viewModel.FullName).OrderBy(fullName => fullName)); foreach (var viewModelType in patchingViewModelTypes) { log.Info($"Patching type '{viewModelType.FullName}'..."); if (PatchViewModel(assembly, viewModelBaseType, viewModelType) == PatchResult.Cancel) { return(PatchResult.Cancel); } log.Info($"Type '{viewModelType.FullName}' was patched"); } log.Info("View model types was patched"); return(PatchResult.Continue); }
public override PatchResult Patch(ICommonAssembly assembly) { log.Info("Patching framework element types..."); var selectingType = assembly.GetReflectionAttribute <SelectingFrameworkElementAttribute>()?.SelectingType ?? applicationPatcherWpfConfiguration.DefaultFrameworkElementSelectingType; log.Info($"Framework element selecting type: '{selectingType}'"); var frameworkElementBaseType = assembly.GetCommonType(KnownTypeNames.FrameworkElement, true).Load(); CheckAssembly(assembly, frameworkElementBaseType); var frameworkElementTypes = assembly.GetInheritanceCommonTypesFromThisAssembly(frameworkElementBaseType).ToArray(); if (!frameworkElementTypes.Any()) { log.Info("Not found framework element types"); return(PatchResult.Continue); } log.Debug("Framework element types found:", frameworkElementTypes.Select(frameworkElement => frameworkElement.FullName).OrderBy(fullName => fullName)); var patchingFrameworkElementTypes = frameworkElementTypes .Where(frameworkElementType => frameworkElementType.NotContainsReflectionAttribute <NotPatchingFrameworkElementAttribute>() && (selectingType == FrameworkElementSelectingType.All || frameworkElementType.ContainsReflectionAttribute <PatchingFrameworkElementAttribute>())) .ToArray(); if (!patchingFrameworkElementTypes.Any()) { log.Info("Not found patching framework element types"); return(PatchResult.Continue); } log.Debug("Patching framework element types:", patchingFrameworkElementTypes.Select(frameworkElement => frameworkElement.FullName).OrderBy(fullName => fullName)); foreach (var frameworkElementType in patchingFrameworkElementTypes) { log.Info($"Patching type '{frameworkElementType.FullName}'..."); if (PatchFrameworkElement(assembly, frameworkElementType) == PatchResult.Cancel) { return(PatchResult.Cancel); } log.Info($"Type '{frameworkElementType.FullName}' was patched"); } log.Info("Framework element types was patched"); return(PatchResult.Continue); }
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 DependencyGroup[] GetGroups(ICommonAssembly assembly, ICommonType frameworkElementType, FrameworkElementPatchingType patchingType) { var dependencyPropertyType = assembly.GetCommonType(KnownTypeNames.DependencyProperty, true); CheckFrameworkElement(frameworkElementType, dependencyPropertyType); var patchingProperties = GetPatchingProperties(frameworkElementType, patchingType); CheckPatchingPropertyNames(patchingProperties); var patchingDependencyGroups = GetPatchingDependencyGroups(patchingProperties, frameworkElementType); CheckPatchingPropertyGroups(patchingDependencyGroups, dependencyPropertyType); return(patchingDependencyGroups.Select(group => new DependencyGroup(group.Fields.SingleOrDefault(), group.Property)).ToArray()); }
public override PatchResult Patch(ICommonAssembly assembly) { log.Info("Add assembly patched attribute..."); if (!assembly.NotContainsReflectionAttribute <AssemblyPatchedAttribute>()) { log.Info("Assembly patched attribute already exists"); return(PatchResult.Continue); } var assemblyPatchedAttributeConstructor = assembly.GetCommonType(typeof(AssemblyPatchedAttribute), true).Load().GetConstructor(true); assembly.MonoCecil.CustomAttributes.Add(new CustomAttribute(assembly.MonoCecil.MainModule.ImportReference(assemblyPatchedAttributeConstructor.MonoCecil))); log.Info("Assembly patched attribute was added"); return(PatchResult.Continue); }
private static void RemoveAttributesFromFrameworkElements(ICommonAssembly assembly) { var frameworkElementBaseType = assembly.GetCommonType(KnownTypeNames.FrameworkElement, true); var frameworkElementTypes = assembly.GetInheritanceCommonTypesFromThisAssembly(frameworkElementBaseType).ToArray(); foreach (var frameworkElementType in frameworkElementTypes.Select(type => type.Load())) { frameworkElementType.MonoCecil.RemoveAttributes <PatchingFrameworkElementAttribute>(); frameworkElementType.MonoCecil.RemoveAttributes <NotPatchingFrameworkElementAttribute>(); foreach (var property in frameworkElementType.Fields) { property.MonoCecil.RemoveAttributes <ConnectFieldToPropertyAttribute>(); } foreach (var property in frameworkElementType.Properties) { property.MonoCecil.RemoveAttributes <NotUseSearchByNameAttribute>(); property.MonoCecil.RemoveAttributes <PatchingPropertyAttribute>(); property.MonoCecil.RemoveAttributes <NotPatchingPropertyAttribute>(); property.MonoCecil.RemoveAttributes <ConnectPropertyToFieldAttribute>(); } } }