/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.ComponentModel.Composition; using dnSpy.Contracts.Settings; using ICSharpCode.Decompiler; namespace dnSpy.Decompiler.ILSpy.Settings { [Export] sealed class DecompilerSettingsImpl : DecompilerSettings { static readonly Guid SETTINGS_GUID = new Guid("6745457F-254B-4B7B-90F1-F948F0721C3B"); readonly ISettingsService settingsService; [ImportingConstructor] DecompilerSettingsImpl(ISettingsService settingsService) { this.settingsService = settingsService; disableSave = true; var sect = settingsService.GetOrCreateSection(SETTINGS_GUID); // Only read those settings that can be changed in the dialog box DecompilationObject0 = sect.Attribute(nameof(DecompilationObject0)) ?? DecompilationObject0; DecompilationObject1 = sect.Attribute(nameof(DecompilationObject1)) ?? DecompilationObject1; DecompilationObject2 = sect.Attribute(nameof(DecompilationObject2)) ?? DecompilationObject2; DecompilationObject3 = sect.Attribute(nameof(DecompilationObject3)) ?? DecompilationObject3; DecompilationObject4 = sect.Attribute(nameof(DecompilationObject4)) ?? DecompilationObject4; AnonymousMethods = sect.Attribute(nameof(AnonymousMethods)) ?? AnonymousMethods; ExpressionTrees = sect.Attribute(nameof(ExpressionTrees)) ?? ExpressionTrees; YieldReturn = sect.Attribute(nameof(YieldReturn)) ?? YieldReturn; AsyncAwait = sect.Attribute(nameof(AsyncAwait)) ?? AsyncAwait; //AutomaticProperties = sect.Attribute(nameof(AutomaticProperties)) ?? AutomaticProperties; //AutomaticEvents = sect.Attribute(nameof(AutomaticEvents)) ?? AutomaticEvents; //UsingStatement = sect.Attribute(nameof(UsingStatement)) ?? UsingStatement; //ForEachStatement = sect.Attribute(nameof(ForEachStatement)) ?? ForEachStatement; //LockStatement = sect.Attribute(nameof(LockStatement)) ?? LockStatement; //SwitchStatementOnString = sect.Attribute(nameof(SwitchStatementOnString)) ?? SwitchStatementOnString; //UsingDeclarations = sect.Attribute(nameof(UsingDeclarations)) ?? UsingDeclarations; QueryExpressions = sect.Attribute(nameof(QueryExpressions)) ?? QueryExpressions; FullyQualifyAmbiguousTypeNames = sect.Attribute(nameof(FullyQualifyAmbiguousTypeNames)) ?? FullyQualifyAmbiguousTypeNames; FullyQualifyAllTypes = sect.Attribute(nameof(FullyQualifyAllTypes)) ?? FullyQualifyAllTypes; UseDebugSymbols = sect.Attribute(nameof(UseDebugSymbols)) ?? UseDebugSymbols; //ObjectOrCollectionInitializers = sect.Attribute(nameof(ObjectOrCollectionInitializers)) ?? ObjectOrCollectionInitializers; ShowXmlDocumentation = sect.Attribute(nameof(ShowXmlDocumentation)) ?? ShowXmlDocumentation; RemoveEmptyDefaultConstructors = sect.Attribute(nameof(RemoveEmptyDefaultConstructors)) ?? RemoveEmptyDefaultConstructors; //IntroduceIncrementAndDecrement = sect.Attribute(nameof(IntroduceIncrementAndDecrement)) ?? IntroduceIncrementAndDecrement; //MakeAssignmentExpressions = sect.Attribute(nameof(MakeAssignmentExpressions)) ?? MakeAssignmentExpressions; //AlwaysGenerateExceptionVariableForCatchBlocksUnlessTypeIsObject = sect.Attribute(nameof(AlwaysGenerateExceptionVariableForCatchBlocksUnlessTypeIsObject)) ?? AlwaysGenerateExceptionVariableForCatchBlocksUnlessTypeIsObject; ShowTokenAndRvaComments = sect.Attribute(nameof(ShowTokenAndRvaComments)) ?? ShowTokenAndRvaComments; SortMembers = sect.Attribute(nameof(SortMembers)) ?? SortMembers; ForceShowAllMembers = sect.Attribute(nameof(ForceShowAllMembers)) ?? ForceShowAllMembers; SortSystemUsingStatementsFirst = sect.Attribute(nameof(SortSystemUsingStatementsFirst)) ?? SortSystemUsingStatementsFirst; //MaxArrayElements = sect.Attribute(nameof(MaxArrayElements)) ?? MaxArrayElements; SortCustomAttributes = sect.Attribute(nameof(SortCustomAttributes)) ?? SortCustomAttributes; UseSourceCodeOrder = sect.Attribute(nameof(UseSourceCodeOrder)) ?? UseSourceCodeOrder; AllowFieldInitializers = sect.Attribute(nameof(AllowFieldInitializers)) ?? AllowFieldInitializers; OneCustomAttributePerLine = sect.Attribute(nameof(OneCustomAttributePerLine)) ?? OneCustomAttributePerLine; TypeAddInternalModifier = sect.Attribute(nameof(TypeAddInternalModifier)) ?? TypeAddInternalModifier; MemberAddPrivateModifier = sect.Attribute(nameof(MemberAddPrivateModifier)) ?? MemberAddPrivateModifier; //RemoveNewDelegateClass = sect.Attribute(nameof(RemoveNewDelegateClass)) ?? RemoveNewDelegateClass; HexadecimalNumbers = sect.Attribute(nameof(HexadecimalNumbers)) ?? HexadecimalNumbers; //TODO: CSharpFormattingOptions disableSave = false; } readonly bool disableSave; protected override void OnModified() { if (disableSave) return; var sect = settingsService.RecreateSection(SETTINGS_GUID); // Only save those settings that can be changed in the dialog box sect.Attribute(nameof(DecompilationObject0), DecompilationObject0); sect.Attribute(nameof(DecompilationObject1), DecompilationObject1); sect.Attribute(nameof(DecompilationObject2), DecompilationObject2); sect.Attribute(nameof(DecompilationObject3), DecompilationObject3); sect.Attribute(nameof(DecompilationObject4), DecompilationObject4); sect.Attribute(nameof(AnonymousMethods), AnonymousMethods); sect.Attribute(nameof(ExpressionTrees), ExpressionTrees); sect.Attribute(nameof(YieldReturn), YieldReturn); sect.Attribute(nameof(AsyncAwait), AsyncAwait); //sect.Attribute(nameof(AutomaticProperties), AutomaticProperties); //sect.Attribute(nameof(AutomaticEvents), AutomaticEvents); //sect.Attribute(nameof(UsingStatement), UsingStatement); //sect.Attribute(nameof(ForEachStatement), ForEachStatement); //sect.Attribute(nameof(LockStatement), LockStatement); //sect.Attribute(nameof(SwitchStatementOnString), SwitchStatementOnString); //sect.Attribute(nameof(UsingDeclarations), UsingDeclarations); sect.Attribute(nameof(QueryExpressions), QueryExpressions); sect.Attribute(nameof(FullyQualifyAmbiguousTypeNames), FullyQualifyAmbiguousTypeNames); sect.Attribute(nameof(FullyQualifyAllTypes), FullyQualifyAllTypes); sect.Attribute(nameof(UseDebugSymbols), UseDebugSymbols); //sect.Attribute(nameof(ObjectOrCollectionInitializers), ObjectOrCollectionInitializers); sect.Attribute(nameof(ShowXmlDocumentation), ShowXmlDocumentation); sect.Attribute(nameof(RemoveEmptyDefaultConstructors), RemoveEmptyDefaultConstructors); //sect.Attribute(nameof(IntroduceIncrementAndDecrement), IntroduceIncrementAndDecrement); //sect.Attribute(nameof(MakeAssignmentExpressions), MakeAssignmentExpressions); //sect.Attribute(nameof(AlwaysGenerateExceptionVariableForCatchBlocksUnlessTypeIsObject), AlwaysGenerateExceptionVariableForCatchBlocksUnlessTypeIsObject); sect.Attribute(nameof(ShowTokenAndRvaComments), ShowTokenAndRvaComments); sect.Attribute(nameof(SortMembers), SortMembers); sect.Attribute(nameof(ForceShowAllMembers), ForceShowAllMembers); sect.Attribute(nameof(SortSystemUsingStatementsFirst), SortSystemUsingStatementsFirst); //sect.Attribute(nameof(MaxArrayElements), MaxArrayElements); sect.Attribute(nameof(SortCustomAttributes), SortCustomAttributes); sect.Attribute(nameof(UseSourceCodeOrder), UseSourceCodeOrder); sect.Attribute(nameof(AllowFieldInitializers), AllowFieldInitializers); sect.Attribute(nameof(OneCustomAttributePerLine), OneCustomAttributePerLine); sect.Attribute(nameof(TypeAddInternalModifier), TypeAddInternalModifier); sect.Attribute(nameof(MemberAddPrivateModifier), MemberAddPrivateModifier); //sect.Attribute(nameof(RemoveNewDelegateClass), RemoveNewDelegateClass); sect.Attribute(nameof(HexadecimalNumbers), HexadecimalNumbers); //TODO: CSharpFormattingOptions } } }