├── .gitattributes
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── pr-verification.yml
│ └── release.yml
├── .gitignore
├── LICENSE
├── MappingGenerator
├── .editorconfig
├── MappingGenerator.sln
├── MappingGenerator.sln.DotSettings
├── MappingGenerator
│ ├── MappingGenerator.Test
│ │ ├── EmptyInitializationBlock
│ │ │ ├── EmptyInitializationBlockTestCases.Designer.cs
│ │ │ ├── EmptyInitializationBlockTestCases.resx
│ │ │ ├── EmptyInitializationBlockTests.cs
│ │ │ └── TestCasesData
│ │ │ │ ├── 001_CompleteInitializationBlockWithLocals.txt
│ │ │ │ ├── 001_CompleteInitializationBlockWithLocals_FIXED.txt
│ │ │ │ ├── 002_CompleteInitializationBlockWithLambdaParameter.txt
│ │ │ │ ├── 002_CompleteInitializationBlockWithLambdaParameter_FIXED.txt
│ │ │ │ ├── 003_CompleteInitializationBlockWithSompleLambdaParameter.txt
│ │ │ │ ├── 003_CompleteInitializationBlockWithSompleLambdaParameter_FIXED.txt
│ │ │ │ ├── 004_CompleteInitializationBlockWithSampleDataRecursiveType.txt
│ │ │ │ ├── 004_CompleteInitializationBlockWithSampleDataRecursiveType_FIXED.txt
│ │ │ │ ├── 005_CompleteInitializationBlockWithSampleDatComplexType.txt
│ │ │ │ ├── 005_CompleteInitializationBlockWithSampleDatComplexType_FIXED.txt
│ │ │ │ ├── 006_SelectInSimpleLinq.txt
│ │ │ │ ├── 006_SelectInSimpleLinqFixed.txt
│ │ │ │ ├── 007_SelectWithLetInLinq.txt
│ │ │ │ ├── 007_SelectWithLetInLinq_FiIXED.txt
│ │ │ │ ├── 008_JoinInLinq.txt
│ │ │ │ ├── 008_JoinInLinq_FiIXED.txt
│ │ │ │ ├── 009_QueryContinuationInLinq.txt
│ │ │ │ ├── 009_QueryContinuationInLinq_FIXED.txt
│ │ │ │ ├── 010_GroupByInLinq.txt
│ │ │ │ ├── 010_GroupByInLinq.txt_FIXED.txt
│ │ │ │ ├── 011_CompleteInitializationBlockWithLocals.txt
│ │ │ │ ├── 011_CompleteInitializationBlockWithLocals_FIXED.txt
│ │ │ │ ├── 012_ScaffoldingWithNonNullable.txt
│ │ │ │ └── 012_ScaffoldingWithNonNullable_FIXED.txt
│ │ ├── ExplicitConversions
│ │ │ ├── ExplicitConversionTestCases.Designer.cs
│ │ │ ├── ExplicitConversionTestCases.resx
│ │ │ ├── ExplicitConversionTests.cs
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_ExplicitConversionForInvalidAssigment.txt
│ │ │ │ ├── 001_ExplicitConversionForInvalidAssigment_FIXED.txt
│ │ │ │ ├── 002_ExplicitConversionForInvalidReturn.txt
│ │ │ │ ├── 002_ExplicitConversionForInvalidReturn_FIXED.txt
│ │ │ │ ├── 003_ExplicitConversionForInvalidYield.txt
│ │ │ │ ├── 003_ExplicitConversionForInvalidYield_FIXED.txt
│ │ │ │ ├── 004_ExplicitConversionForInvalidAssigmentInInitBlock.txt
│ │ │ │ ├── 004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt
│ │ │ │ ├── 005_ExplicitConversionReUseInstance.txt
│ │ │ │ ├── 005_ExplicitConversionReUseInstance_FIXED.txt
│ │ │ │ ├── 006_ExplicitConversionForInvalidAssigmentInInitBlockReuseInstance.txt
│ │ │ │ ├── 006_ExplicitConversionForInvalidAssigmentInInitBlockReuseInstance_FIXED.txt
│ │ │ │ ├── 007_ExplicitConversionForValueCollection.txt
│ │ │ │ └── 007_ExplicitConversionForValueCollection_FIXED.txt
│ │ ├── ImplementCloneMethod
│ │ │ ├── ImplementCloneMethodTestCases.Designer.cs
│ │ │ ├── ImplementCloneMethodTestCases.resx
│ │ │ ├── ImplementCloneMethodTests.cs
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_DeepClone.txt
│ │ │ │ ├── 001_DeepClone_FIXED.txt
│ │ │ │ ├── 002_DetecCloneOnMembers.txt
│ │ │ │ ├── 002_DetecCloneOnMembers_FIXED.txt
│ │ │ │ ├── 003_ImplementCloneMethodBody.txt
│ │ │ │ └── 003_ImplementCloneMethodBody_FIXED.txt
│ │ ├── InvocationScaffolding
│ │ │ ├── InvocationScaffoldingTestCases.Designer.cs
│ │ │ ├── InvocationScaffoldingTestCases.resx
│ │ │ ├── InvocationScaffoldingTests.cs
│ │ │ └── TestData
│ │ │ │ ├── 001_MethodInvocationScaffolding_With_RegularArguments.txt
│ │ │ │ ├── 001_MethodInvocationScaffolding_With_RegularArguments_FIXED.txt
│ │ │ │ ├── 002_MethodInvocationScaffolding_With_NamedArguments.txt
│ │ │ │ ├── 002_MethodInvocationScaffolding_With_NamedArguments_FIXED.txt
│ │ │ │ ├── 003_ConstructorInvocationScaffolding_With_RegularArguments.txt
│ │ │ │ ├── 003_ConstructorInvocationScaffolding_With_RegularArguments_FIXED.txt
│ │ │ │ ├── 004_ConstructorInvocationScaffolding_With_NamedArguments.txt
│ │ │ │ └── 004_ConstructorInvocationScaffolding_With_NamedArguments_FIXED.txt
│ │ ├── MappingGenerator.Test.csproj
│ │ ├── MappingGenerator
│ │ │ ├── MappingGeneratorForBrokenCodeTests.cs
│ │ │ ├── MappingGeneratorTestCases.Designer.cs
│ │ │ ├── MappingGeneratorTestCases.resx
│ │ │ ├── MappingGeneratorTests.cs
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_PureMappingMethod.txt
│ │ │ │ ├── 001_PureMappingMethod_FIXED.txt
│ │ │ │ ├── 002_PureMappingMethodWithGenerics.txt
│ │ │ │ ├── 002_PureMappingMethodWithGenerics_FIXED.txt
│ │ │ │ ├── 003_MappingFromOneToAnotherParameter.txt
│ │ │ │ ├── 003_MappingFromOneToAnotherParameter_FIXED.txt
│ │ │ │ ├── 004_UpdateThisObjectWithSingleParameterDecomposition.txt
│ │ │ │ ├── 004_UpdateThisObjectWithSingleParameterDecomposition_FIXED.txt
│ │ │ │ ├── 005_UpdateThisObjectWithMultipleParameters.txt
│ │ │ │ ├── 005_UpdateThisObjectWithMultipleParameters_FIXED.txt
│ │ │ │ ├── 005_UpdateThisObjectWithTwoParameters.txt
│ │ │ │ ├── 005_UpdateThisObjectWithTwoParameters_FIXED.txt
│ │ │ │ ├── 006_ConstructorWithSingleParameterDecomposition.txt
│ │ │ │ ├── 006_ConstructorWithSingleParameterDecomposition_FIXED.txt
│ │ │ │ ├── 007_ConstructorWithMultipleParameters.txt
│ │ │ │ ├── 007_ConstructorWithMultipleParameters_FIXED.txt
│ │ │ │ ├── 008_StopRecursingMapping.txt
│ │ │ │ ├── 008_StopRecursingMapping_Fixed.txt
│ │ │ │ ├── 009_IdentityFunctionMapping.txt
│ │ │ │ ├── 009_IdentityFunctionMapping_FIXED.txt
│ │ │ │ ├── 010_IdentityFunctionMappingForSimpleType.txt
│ │ │ │ ├── 010_IdentityFunctionMappingForSimpleType_FIXED.txt
│ │ │ │ ├── 011_IdentityFunctionMappingForCollection.txt
│ │ │ │ ├── 011_IdentityFunctionMappingForCollection_FIXED.txt
│ │ │ │ ├── 012_CollectionMappingWithSingularLambdaParameterName.txt
│ │ │ │ ├── 012_CollectionMappingWithSingularLambdaParameterName_FIXED.txt
│ │ │ │ ├── 013_CollectionMappingWithPrefixedLambdaParameterName.txt
│ │ │ │ ├── 013_CollectionMappingWithPrefixedLambdaParameterName_FIXED..txt
│ │ │ │ ├── 014_CollectionMappingWithGenericName.txt
│ │ │ │ ├── 014_CollectionMappingWithGenericName_FIXED.txt
│ │ │ │ ├── 015_CollectionMappingWithPostfixGenericName.txt
│ │ │ │ ├── 015_CollectionMappingWithPostfixGenericName_FIXED.txt
│ │ │ │ ├── 016_CollectionMappingWithIrregularSingularLambdaParameterName.txt
│ │ │ │ ├── 016_CollectionMappingWithIrregularSingularLambdaParameterName_FIXED.txt
│ │ │ │ ├── 017_CollectionMappingWithIrregularCamelCaseSingularLambdaParameterName.txt
│ │ │ │ ├── 017_CollectionMappingWithIrregularCamelCaseSingularLambdaParameterName_FIXED.txt
│ │ │ │ ├── 018_CollectionMappingWithPostfixGenericNameInSingular.txt
│ │ │ │ ├── 018_CollectionMappingWithPostfixGenericNameInSingular_FIXED.txt
│ │ │ │ ├── 019_MappingPropertiesInheritedFromLibraryClass.txt
│ │ │ │ ├── 019_MappingPropertiesInheritedFromLibraryClass_FIXED.txt
│ │ │ │ ├── 020_MappingPropertiesInConstructorInheritedFromLibraryClass.txt
│ │ │ │ ├── 020_MappingPropertiesInConstructorInheritedFromLibraryClass_FIXED.txt
│ │ │ │ ├── 021_MultiParameterPureMappingMethod.txt
│ │ │ │ ├── 021_MultiParameterPureMappingMethod_FIxed.txt
│ │ │ │ ├── 022_CollectionMappingIListToList.txt
│ │ │ │ ├── 022_CollectionMappingIListToList_Fixed.txt
│ │ │ │ ├── 023_PureLambdaMappingMethod.txt
│ │ │ │ ├── 023_PureLambdaMappingMethod_FIXED.txt
│ │ │ │ ├── 024_InvalidSyntaxPureMappingMethod.txt
│ │ │ │ ├── 024_InvalidSyntaxPureMappingMethod_FIXED.txt
│ │ │ │ ├── 025_ThisObjectToOtherMapping.txt
│ │ │ │ ├── 025_ThisObjectToOtherMapping_FIXED.txt
│ │ │ │ ├── 026_UpdateThisObjectWithSingleParameterMethod.txt
│ │ │ │ ├── 026_UpdateThisObjectWithSingleParameterMethod_FIXED.txt
│ │ │ │ ├── 027_ConstructorWithSingleParameter.txt
│ │ │ │ ├── 027_ConstructorWithSingleParameter_FIXED.txt
│ │ │ │ ├── 028_PrivateUpdateFieldAccessibility.txt
│ │ │ │ ├── 028_PrivateUpdateFieldAccessibility_FIXEDy.txt
│ │ │ │ ├── 029_PureMappingMethodWithCustomConversions.txt
│ │ │ │ ├── 029_PureMappingMethodWithCustomConversions_FIXED.txt
│ │ │ │ ├── 030_ConstructorUpdateFieldAccessibility.txt
│ │ │ │ ├── 030_ConstructorUpdateFieldAccessibility_FIXED.txt
│ │ │ │ ├── 031_PureMappingMethodWithInheritedCustomConversions.txt
│ │ │ │ ├── 031_PureMappingMethodWithInheritedCustomConversions_FIXED.txt
│ │ │ │ ├── 032_PubliclyUpdateFieldAccessibility.txt
│ │ │ │ ├── 032_PubliclyUpdateFieldAccessibility_FIXED.txt
│ │ │ │ ├── 033_PureMappingMethodWithFields.txt
│ │ │ │ ├── 033_PureMappingMethodWithFields_FIXED.txt
│ │ │ │ ├── 034_PubliclyUpdateFieldAccessibilityForFields.txt
│ │ │ │ ├── 034_PubliclyUpdateFieldAccessibilityForFields_FIXED.txt
│ │ │ │ ├── 035_ConstructorInitializeFIelds.txt
│ │ │ │ ├── 035_ConstructorInitializeFIelds_FIXED.txt
│ │ │ │ ├── 036_PureMappingMethodWithNullable.txt
│ │ │ │ ├── 036_PureMappingMethodWithNullable_FIXED.txt
│ │ │ │ ├── 037_ConstructorWithNullable.txt
│ │ │ │ └── 037_ConstructorWithNullable_FIXED.txt
│ │ ├── MethodParameterSuggestion
│ │ │ ├── MethodParameterSuggestionTestCases.Designer.cs
│ │ │ ├── MethodParameterSuggestionTestCases.resx
│ │ │ ├── MethodParametersSuggestionProviderTest.cs
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_SuggestOuterMethodParameters.txt
│ │ │ │ ├── 002_SuggestOuterMethodParametersAndLocal.txt
│ │ │ │ ├── 003_SuggestOuterMethodParametersAndMembers.txt
│ │ │ │ ├── 004_FallbackByTypeIfSingleCandidate.txt
│ │ │ │ ├── 005_FallbackByTypeIfSingleCandidateInterface.txt
│ │ │ │ ├── 006_FallbackByTypeIfSingleCandidateBaseClass.txt
│ │ │ │ ├── 007_FallbackByTypeIfSingleCandidateInterfaceInheritance.txt
│ │ │ │ ├── 008_FallbackByTypeIfSingleCandidateBaseClassInheritance.txt
│ │ │ │ ├── 009_SuggestParamsForExtensionMethod.txt
│ │ │ │ ├── 010_SuggestParamsWithInterface.txt
│ │ │ │ └── 011_SuggestParamsForGenericMethod.txt
│ │ ├── OnBuildGenerator
│ │ │ ├── OnBuildGeneratorTest.cs
│ │ │ ├── OnBuildGeneratorTestCases.Designer.cs
│ │ │ ├── OnBuildGeneratorTestCases.resx
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_SimpleMappingInterface.txt
│ │ │ │ ├── 001_SimpleMappingInterface_TRANSFORMED.txt
│ │ │ │ ├── 003_ExternalTypeMappers.txt
│ │ │ │ └── 003_ExternalTypeMappers_TRANSFORMED.txt
│ │ ├── Splatting
│ │ │ ├── SplattingTestCases.Designer.cs
│ │ │ ├── SplattingTestCases.resx
│ │ │ ├── SplattingTests.cs
│ │ │ └── TestCaseData
│ │ │ │ ├── 001_SplattingInMethodInvocation.txt
│ │ │ │ ├── 001_SplattingInMethodInvocationWithNamedParameters_FIXED.txt
│ │ │ │ ├── 001_SplattingInMethodInvocation_FIXED.txt
│ │ │ │ ├── 002_SplattingInConstructorInvocation.txt
│ │ │ │ ├── 002_SplattingInConstructorInvocationWithNamedParameters_FIXED.txt
│ │ │ │ ├── 002_SplattingInConstructorInvocation_FIXED.txt
│ │ │ │ ├── 003_SplattingWithBestOverloadMatch.txt
│ │ │ │ └── 003_SplattingWithBestOverloadMatch_FIXED.txt
│ │ ├── UpdateLambdaParameter
│ │ │ ├── TestCaseData
│ │ │ │ ├── 001_SimpleLambda.txt
│ │ │ │ ├── 001_SimpleLambda_FIXED.txt
│ │ │ │ ├── 002_ParenthesisLambda.txt
│ │ │ │ ├── 002_ParenthesisLambda_FIXED.txt
│ │ │ │ ├── 003_GenericLambda.txt
│ │ │ │ └── 003_GenericLambda_FIXED.txt
│ │ │ ├── UpdateLambdaParameterRefactoringTestCases.Designer.cs
│ │ │ ├── UpdateLambdaParameterRefactoringTestCases.resx
│ │ │ └── UpdateLambdaParameterRefactoringTests.cs
│ │ └── UseLocalVariablesAsParameters
│ │ │ ├── TestCaseData
│ │ │ ├── 001_UserLocaVariablesToCompleteMethodInvocation.txt
│ │ │ ├── 001_UserLocaVariablesToCompleteMethodInvocationWithNamedParameters_Fixed.txt
│ │ │ ├── 001_UserLocaVariablesToCompleteMethodInvocation_Fixed.txt
│ │ │ ├── 002_UserLocaVariablesToCompleteConstructorInvocation.txt
│ │ │ ├── 002_UserLocaVariablesToCompleteConstructorInvocationWithNamedParameters_Fixed .txt
│ │ │ └── 002_UserLocaVariablesToCompleteConstructorInvocation_Fixed.txt
│ │ │ ├── UseLocalVariablesTestCases.Designer.cs
│ │ │ ├── UseLocalVariablesTestCases.resx
│ │ │ └── UserLocalVariablesAsParametersTests.cs
│ ├── MappingGenerator.Vsix
│ │ ├── MappingGenerator.Vsix.csproj
│ │ ├── icon.png
│ │ ├── overview.md
│ │ ├── packages.config
│ │ ├── preview.png
│ │ ├── publishManifest.json
│ │ └── source.extension.vsixmanifest
│ └── MappingGenerator
│ │ ├── Features
│ │ ├── CodeFixes
│ │ │ ├── ExplicitConversionCodeFixProvider.cs
│ │ │ ├── InvocationScaffoldingCodeFixProvider.cs
│ │ │ ├── SplattingCodeFixProvider.cs
│ │ │ └── UseLocalVariablesAsParameterCodeFixProvider.cs
│ │ ├── Refactorings
│ │ │ ├── EmptyInitializationBlockRefactoring.cs
│ │ │ ├── ImplementCloneMethodRefactoring.cs
│ │ │ ├── MappingGeneratorRefactoring.cs
│ │ │ └── UpdateLambdaParameterRefactoring.cs
│ │ └── Suggestions
│ │ │ └── MethodParametersSuggestionProvider.cs
│ │ ├── MappingGenerator.csproj
│ │ ├── Mappings
│ │ ├── AnnotatedType.cs
│ │ ├── CloneMappingEngine.cs
│ │ ├── CustomConversionHelper.cs
│ │ ├── MappingContext.cs
│ │ ├── MappingElement.cs
│ │ ├── MappingEngine.cs
│ │ ├── MappingHelper.cs
│ │ ├── MappingImplementorEngine.cs
│ │ ├── MappingImplementors
│ │ │ ├── FallbackMappingImplementor.cs
│ │ │ ├── IMappingMethodImplementor.cs
│ │ │ ├── IdentityMappingMethodImplementor.cs
│ │ │ ├── MultiParameterMappingConstructorImplementor.cs
│ │ │ ├── MultiParameterPureMappingMethodImplementor.cs
│ │ │ ├── SingleParameterMappingConstructorImplementor.cs
│ │ │ ├── SingleParameterPureMappingMethodImplementor.cs
│ │ │ ├── ThisObjectToOtherMappingMethodImplementor.cs
│ │ │ ├── UpdateSecondParameterMappingMethodImplementor.cs
│ │ │ ├── UpdateThisObjectMultiParameterMappingMethodImplementor.cs
│ │ │ └── UpdateThisObjectSingleParameterMappingMethodImplementor.cs
│ │ ├── MappingMatchers
│ │ │ ├── BestPossibleMatcher.cs
│ │ │ ├── IMappingMatcher.cs
│ │ │ ├── MappingMatch.cs
│ │ │ └── SingleSourceMatcher.cs
│ │ ├── MappingType.cs
│ │ ├── NameHelper.cs
│ │ ├── SourceFinders
│ │ │ ├── IgnorableMappingSourceFinder.cs
│ │ │ ├── LocalScopeMappingSourceFinder.cs
│ │ │ ├── NullableExtensions.cs
│ │ │ ├── ObjectMembersMappingSourceFinder.cs
│ │ │ ├── OrderedSourceFinder.cs
│ │ │ └── ScaffoldingSourceFinder.cs
│ │ └── WrapperInfo.cs
│ │ ├── MethodHelpers
│ │ ├── ConstructorInvocation.cs
│ │ ├── IInvocation.cs
│ │ ├── MatchedParameterList.cs
│ │ ├── MethodHelper.cs
│ │ ├── MethodInvocation.cs
│ │ └── SuggestionHelpers.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── RoslynHelpers
│ │ ├── AccessibilityHelper.cs
│ │ ├── MappingTargetHelper.cs
│ │ ├── ObjectField.cs
│ │ ├── ObjectFieldExtensions.cs
│ │ ├── ObjectHelper.cs
│ │ ├── ObjectProperty.cs
│ │ ├── SemanticModelExtensions.cs
│ │ ├── SymbolHelper.cs
│ │ ├── SyntaxGeneratorExtensions.cs
│ │ └── SyntaxHelper.cs
│ │ └── tools
│ │ ├── install.ps1
│ │ └── uninstall.ps1
└── OnBuildGenerator
│ ├── MappingGenerator.OnBuildGenerator.csproj
│ ├── MappingInterface.cs
│ └── OnBuildMappingGenerator.cs
├── README.md
├── appveyor.yml
├── doc
├── InitializeWithLocalVariables.gif
├── cs0029.jpg
├── cs0266.jpg
├── emptyInitialization.gif
├── localsforconstructor.gif
├── mapping_constructor.gif
├── mapping_lambda.gif
├── multi_parameter_constructor.gif
├── multiparameterconstructor.gif
├── multiparameterupdate.gif
├── object_scaffolding.gif
├── pure_mapping_method.gif
├── pure_mapping_method_newone.gif
├── resharper_settings.jpg
├── splatting.gif
├── support_anim.gif
├── update_member_method.gif
└── update_method.gif
└── docs
└── CONTRIBUTING.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.cs text eol=crlf
2 | *.txt text eol=crlf
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Bug report
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Mapping Generator Version**
11 | [Current]
12 |
13 | **Mapping Generator distribution**
14 | VSExtension/NugetPackage
15 |
16 | **IDE type and version**
17 | Example: Visual Studio 2019 16.8
18 |
19 | **Describe the incorrect behavior**
20 | A clear and concise description of what the bug is.
21 |
22 | **Describe the expected behavior**
23 | A clear and concise description of what are you expecting.
24 |
25 | **Screenshots**
26 | Screenshots presenting error message
27 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Feature description**
11 | A clear and concise description of what the problem is.
12 |
13 | **Reasoning behind**
14 | What are the benefits of the requested feature.
15 |
16 | **Real word example of the usage**
17 | Provide an example of feature usage. Example source and destination types, mapping method signature and the expected mapping code.
18 |
--------------------------------------------------------------------------------
/.github/workflows/pr-verification.yml:
--------------------------------------------------------------------------------
1 | name: pr-verification
2 | on:
3 | pull_request:
4 | types: [opened, synchronize, reopened]
5 | jobs:
6 | build-extension:
7 | runs-on: windows-latest
8 | env:
9 | DOTNET_NOLOGO: true
10 | DOTNET_CLI_TELEMETRY_OPTOUT: true
11 | RepositoryUrl: 'https://github.com/${{ github.repository }}'
12 | RepositoryBranch: '${{ github.ref }}'
13 | SourceRevisionId: '${{ github.sha }}'
14 | VersionSuffix: 'pr-${{github.event.number}}.${{ github.run_number }}'
15 | Configuration: Release
16 | SolutionPath: MappingGenerator\MappingGenerator.sln
17 | VsixManifestPath: MappingGenerator\MappingGenerator\MappingGenerator.Vsix\source.extension.vsixmanifest
18 | steps:
19 | - uses: actions/checkout@v2
20 | - name: Setup .NET Core
21 | uses: actions/setup-dotnet@v1
22 | with:
23 | dotnet-version: '3.1.x'
24 | - name: Setup MSBuild.exe
25 | uses: microsoft/setup-msbuild@v1.0.2
26 | with:
27 | vs-version: '[16.8,16.9)'
28 | - name: Restore NuGet Packages
29 | run: nuget restore $env:SolutionPath
30 | - name: Calculate next version
31 | uses: cezarypiatek/NextVersionGeneratorAction@0.4
32 | with:
33 | minor-pattern: '\bAdd\b'
34 | patch-pattern: '.*'
35 | output-to-env-variable: 'VersionPrefix'
36 | - name: Set version for Visual Studio Extension
37 | uses: cezarypiatek/VsixVersionAction@1.0
38 | with:
39 | version: '${{env.VersionPrefix}}+${{env.VersionSuffix}}'
40 | vsix-manifest-file: ${{ env.VsixManifestPath }}
41 | - name: Build extension
42 | run: msbuild $env:SolutionPath /t:Rebuild
43 | env:
44 | DeployExtension: False
45 | - name: Test extension
46 | run: dotnet test --no-build --verbosity normal $env:SolutionPath
47 | - name: Collect artifacts - VSIX
48 | uses: actions/upload-artifact@v2
49 | with:
50 | name: MappingGenerator-VSIX
51 | path: MappingGenerator\MappingGenerator\MappingGenerator.Vsix\bin\Release\MappingGenerator.vsix
52 | - name: Collect artifacts - nugets
53 | uses: actions/upload-artifact@v2
54 | with:
55 | name: MappingGenerator-Nugets
56 | path: '**/MappingGenerator*.nupkg'
57 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Cezary Piątek
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MappingGenerator/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 |
3 | # VSTHRD200: Use "Async" suffix for async methods
4 | dotnet_diagnostic.VSTHRD200.severity = none
5 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/001_CompleteInitializationBlockWithLocals.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.TestCases
6 | {
7 | public class UserDTO
8 | {
9 | public string FirstName { get; set; }
10 | public string LastName { get; set; }
11 | public int Age { get; set; }
12 | }
13 |
14 | class Class1
15 | {
16 | public void CreateUser(int age)
17 | {
18 | var firstName = "Cezary";
19 | var lastName = "Piatek";
20 |
21 | var x = new UserDTO
22 | [|{
23 |
24 | }|];
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/001_CompleteInitializationBlockWithLocals_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.TestCases
6 | {
7 | public class UserDTO
8 | {
9 | public string FirstName { get; set; }
10 | public string LastName { get; set; }
11 | public int Age { get; set; }
12 | }
13 |
14 | class Class1
15 | {
16 | public void CreateUser(int age)
17 | {
18 | var firstName = "Cezary";
19 | var lastName = "Piatek";
20 |
21 | var x = new UserDTO
22 | {
23 | FirstName = firstName,
24 | LastName = lastName,
25 | Age = age
26 | };
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/002_CompleteInitializationBlockWithLambdaParameter.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 |
4 | namespace MappingGenerator.Test.EmptyInitializationBlock.TestCasesData
5 | {
6 | public class UserDTO
7 | {
8 | public string FirstName { get; set; }
9 | public string LastName { get; set; }
10 | public int Age { get; set; }
11 | }
12 |
13 | public class UserEntity
14 | {
15 | public string FirstName { get; set; }
16 | public string LastName { get; set; }
17 | public int Age { get; set; }
18 | }
19 |
20 | public class Mapper
21 | {
22 | public Expression> Map = (UserEntity entity) => new UserDTO
23 | [|{
24 | }|];
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/002_CompleteInitializationBlockWithLambdaParameter_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 |
4 | namespace MappingGenerator.Test.EmptyInitializationBlock.TestCasesData
5 | {
6 | public class UserDTO
7 | {
8 | public string FirstName { get; set; }
9 | public string LastName { get; set; }
10 | public int Age { get; set; }
11 | }
12 |
13 | public class UserEntity
14 | {
15 | public string FirstName { get; set; }
16 | public string LastName { get; set; }
17 | public int Age { get; set; }
18 | }
19 |
20 | public class Mapper
21 | {
22 | public Expression> Map = (UserEntity entity) => new UserDTO
23 | {
24 | FirstName = entity.FirstName,
25 | LastName = entity.LastName,
26 | Age = entity.Age
27 | };
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/003_CompleteInitializationBlockWithSompleLambdaParameter.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MappingGenerator.Test.EmptyInitializationBlock.TestCasesData
7 | {
8 | public class Mapper
9 | {
10 | public IList Map(IList entities)
11 | {
12 | return entities.Select((UserEntity x) => new UserDTO [|{ }|]).ToList();
13 | }
14 | }
15 |
16 | public class UserDTO
17 | {
18 | public string FirstName { get; set; }
19 | public string LastName { get; set; }
20 | public int Age { get; set; }
21 | }
22 |
23 | public class UserEntity
24 | {
25 | public string FirstName { get; set; }
26 | public string LastName { get; set; }
27 | public int Age { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/003_CompleteInitializationBlockWithSompleLambdaParameter_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MappingGenerator.Test.EmptyInitializationBlock.TestCasesData
7 | {
8 | public class Mapper
9 | {
10 | public IList Map(IList entities)
11 | {
12 | return entities.Select((UserEntity x) => new UserDTO
13 | {
14 | FirstName = x.FirstName,
15 | LastName = x.LastName,
16 | Age = x.Age
17 | }).ToList();
18 | }
19 | }
20 |
21 | public class UserDTO
22 | {
23 | public string FirstName { get; set; }
24 | public string LastName { get; set; }
25 | public int Age { get; set; }
26 | }
27 |
28 | public class UserEntity
29 | {
30 | public string FirstName { get; set; }
31 | public string LastName { get; set; }
32 | public int Age { get; set; }
33 | }
34 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/004_CompleteInitializationBlockWithSampleDataRecursiveType.txt:
--------------------------------------------------------------------------------
1 | namespace TestAutoMapper
2 | {
3 | public class Tree
4 | {
5 | public string Name { get; set; }
6 | public Tree Left { get; set; }
7 | public Tree Right { get; set; }
8 | }
9 |
10 | public static class Factory
11 | {
12 | public static Tree New()
13 | {
14 | return new Tree
15 | [|{
16 | }|];
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/004_CompleteInitializationBlockWithSampleDataRecursiveType_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace TestAutoMapper
2 | {
3 | public class Tree
4 | {
5 | public string Name { get; set; }
6 | public Tree Left { get; set; }
7 | public Tree Right { get; set; }
8 | }
9 |
10 | public static class Factory
11 | {
12 | public static Tree New()
13 | {
14 | return new Tree
15 | {
16 | Name = "lorem ipsum",
17 | Left = new Tree
18 | {
19 | Name = "lorem ipsum",
20 | Left = null /* Stop recursive mapping */,
21 | Right = null /* Stop recursive mapping */
22 | },
23 | Right = new Tree
24 | {
25 | Name = "lorem ipsum",
26 | Left = null /* Stop recursive mapping */,
27 | Right = null /* Stop recursive mapping */
28 | }
29 | };
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/005_CompleteInitializationBlockWithSampleDatComplexType.txt:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Collections;
3 | using System.Collections.ObjectModel;
4 | using System;
5 |
6 | namespace TestAutoMapper
7 | {
8 | class DefaultObject
9 | {
10 | public string MyProperty { get; set; }
11 |
12 | public int MyProperty1 { get; set; }
13 |
14 | public float MyProperty2 { get; set; }
15 |
16 | public bool MyProperty3 { get; set; }
17 |
18 | public sbyte MyProperty4 { get; set; }
19 |
20 | public byte MyProperty5 { get; set; }
21 |
22 | public char MyProperty6 { get; set; }
23 |
24 | public CustomEnum MyProperty7 { get; set; }
25 |
26 | public decimal DecimalProperty { get; set; }
27 |
28 | public InnerDefaultObject Inner { get; set; }
29 |
30 | public IList GenericInners { get; set; }
31 |
32 | public ReadOnlyCollection InnersReadonly { get; set; }
33 |
34 | public IList NonGenericInners { get; set; }
35 |
36 | public DateTime OccuredOn { get; set; }
37 | }
38 |
39 | class InnerDefaultObject
40 | {
41 | public string MyProperty { get; set; }
42 |
43 | public int MyProperty1 { get; set; }
44 |
45 | public int[] Numbers { get; set; }
46 |
47 | public IOtherObject FieldWithInterface { get; set; }
48 |
49 | public YetAnotherObject PropertyWithConstructor { get; set; }
50 | }
51 |
52 | interface IOtherObject
53 | {
54 | string Field1 { get; set; }
55 | }
56 |
57 | class OtherObject : IOtherObject
58 | {
59 | public string Field1 { get; set; }
60 | public string Field2 { get; set; }
61 | }
62 |
63 | class YetAnotherObject
64 | {
65 | public YetAnotherObject(string name, OtherObject other)
66 | {
67 | this.Name = name;
68 | this.Other = other;
69 |
70 | }
71 |
72 | public string Name { get; }
73 | public OtherObject Other { get; }
74 | }
75 |
76 | public enum CustomEnum
77 | {
78 | Opt1=1,
79 | Opt2
80 | }
81 |
82 | static class Factory
83 | {
84 | public static DefaultObject New()
85 | {
86 | return new DefaultObject
87 | [|{
88 | }|];
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/006_SelectInSimpleLinq.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace ConsoleApp9
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | var users = new List();
12 | var query = from p in users
13 | where p.FirstName !=""
14 | select new UserDTO
15 | {
16 | [||]
17 | };
18 | }
19 | }
20 |
21 |
22 | class User
23 | {
24 | public string FirstName { get; set; }
25 | public string LastName { get; set; }
26 |
27 | }
28 | class UserDTO
29 | {
30 | public string FirstName { get; set; }
31 | public string LastName { get; set; }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/006_SelectInSimpleLinqFixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace ConsoleApp9
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | var users = new List();
12 | var query = from p in users
13 | where p.FirstName !=""
14 | select new UserDTO
15 | {
16 | FirstName = p.FirstName,
17 | LastName = p.LastName
18 | };
19 | }
20 | }
21 |
22 |
23 | class User
24 | {
25 | public string FirstName { get; set; }
26 | public string LastName { get; set; }
27 |
28 | }
29 | class UserDTO
30 | {
31 | public string FirstName { get; set; }
32 | public string LastName { get; set; }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/011_CompleteInitializationBlockWithLocals.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.TestCases
6 | {
7 | public class UserDTO
8 | {
9 | public string FirstName { get; set; }
10 | public string LastName { get; set; }
11 | public int Age { get; set; }
12 | }
13 |
14 | class Class1
15 | {
16 | public void CreateUser()
17 | {
18 | var firstName = "Cezary";
19 | var lastName = "Piatek";
20 |
21 | var user = new UserDTO
22 | [|{
23 |
24 | }|];
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/EmptyInitializationBlock/TestCasesData/011_CompleteInitializationBlockWithLocals_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.TestCases
6 | {
7 | public class UserDTO
8 | {
9 | public string FirstName { get; set; }
10 | public string LastName { get; set; }
11 | public int Age { get; set; }
12 | }
13 |
14 | class Class1
15 | {
16 | public void CreateUser()
17 | {
18 | var firstName = "Cezary";
19 | var lastName = "Piatek";
20 |
21 | var user = new UserDTO
22 | {
23 | FirstName = firstName,
24 | LastName = lastName
25 | };
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public void DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | this.Address = [|addressEntity|];
15 | }
16 | }
17 |
18 | public class AddressDTO
19 | {
20 | public string FlatNo { get; set; }
21 | public string BuildtingNo { get; set; }
22 | public string Street { get; set; }
23 | public string ZipCode { get; set; }
24 | public string City { get; set; }
25 | }
26 |
27 | public class AddressEntity
28 | {
29 | public string FlatNo { get; set; }
30 | public string BuildtingNo { get; set; }
31 | public string Street { get; set; }
32 | public string ZipCode { get; set; }
33 | public string City { get; set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public void DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | this.Address = new AddressDTO
15 | {
16 | FlatNo = addressEntity.FlatNo,
17 | BuildtingNo = addressEntity.BuildtingNo,
18 | Street = addressEntity.Street,
19 | ZipCode = addressEntity.ZipCode,
20 | City = addressEntity.City
21 | };
22 | }
23 | }
24 |
25 | public class AddressDTO
26 | {
27 | public string FlatNo { get; set; }
28 | public string BuildtingNo { get; set; }
29 | public string Street { get; set; }
30 | public string ZipCode { get; set; }
31 | public string City { get; set; }
32 | }
33 |
34 | public class AddressEntity
35 | {
36 | public string FlatNo { get; set; }
37 | public string BuildtingNo { get; set; }
38 | public string Street { get; set; }
39 | public string ZipCode { get; set; }
40 | public string City { get; set; }
41 | }
42 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | public AddressDTO Address { get; set; }
11 |
12 | public ReadOnlyCollection DoSomething(IList addresses)
13 | {
14 | return [|addresses|];
15 | }
16 | }
17 |
18 | public class AddressDTO
19 | {
20 | public string FlatNo { get; set; }
21 | public string BuildtingNo { get; set; }
22 | public string Street { get; set; }
23 | public string ZipCode { get; set; }
24 | public string City { get; set; }
25 | }
26 |
27 | public class AddressEntity
28 | {
29 | public string FlatNo { get; set; }
30 | public string BuildtingNo { get; set; }
31 | public string Street { get; set; }
32 | public string ZipCode { get; set; }
33 | public string City { get; set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | public AddressDTO Address { get; set; }
11 |
12 | public ReadOnlyCollection DoSomething(IList addresses)
13 | {
14 | return addresses.Select(address => new AddressDTO
15 | {
16 | FlatNo = address.FlatNo,
17 | BuildtingNo = address.BuildtingNo,
18 | Street = address.Street,
19 | ZipCode = address.ZipCode,
20 | City = address.City
21 | }).ToList().AsReadOnly();
22 | }
23 | }
24 |
25 | public class AddressDTO
26 | {
27 | public string FlatNo { get; set; }
28 | public string BuildtingNo { get; set; }
29 | public string Street { get; set; }
30 | public string ZipCode { get; set; }
31 | public string City { get; set; }
32 | }
33 |
34 | public class AddressEntity
35 | {
36 | public string FlatNo { get; set; }
37 | public string BuildtingNo { get; set; }
38 | public string Street { get; set; }
39 | public string ZipCode { get; set; }
40 | public string City { get; set; }
41 | }
42 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield.txt:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
4 | {
5 | public class TestMapper
6 | {
7 | public AddressDTO Address { get; set; }
8 |
9 | public IEnumerable DoSomething(AddressEntity address)
10 | {
11 | yield return [|address|];
12 | }
13 | }
14 |
15 | public class AddressDTO
16 | {
17 | public string FlatNo { get; set; }
18 | public string BuildtingNo { get; set; }
19 | public string Street { get; set; }
20 | public string ZipCode { get; set; }
21 | public string City { get; set; }
22 | }
23 |
24 | public class AddressEntity
25 | {
26 | public string FlatNo { get; set; }
27 | public string BuildtingNo { get; set; }
28 | public string Street { get; set; }
29 | public string ZipCode { get; set; }
30 | public string City { get; set; }
31 | }
32 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
4 | {
5 | public class TestMapper
6 | {
7 | public AddressDTO Address { get; set; }
8 |
9 | public IEnumerable DoSomething(AddressEntity address)
10 | {
11 | yield return new AddressDTO
12 | {
13 | FlatNo = address.FlatNo,
14 | BuildtingNo = address.BuildtingNo,
15 | Street = address.Street,
16 | ZipCode = address.ZipCode,
17 | City = address.City
18 | };
19 | }
20 | }
21 |
22 | public class AddressDTO
23 | {
24 | public string FlatNo { get; set; }
25 | public string BuildtingNo { get; set; }
26 | public string Street { get; set; }
27 | public string ZipCode { get; set; }
28 | public string City { get; set; }
29 | }
30 |
31 | public class AddressEntity
32 | {
33 | public string FlatNo { get; set; }
34 | public string BuildtingNo { get; set; }
35 | public string Street { get; set; }
36 | public string ZipCode { get; set; }
37 | public string City { get; set; }
38 | }
39 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public UserDTO DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | return new UserDTO{
15 | Address = [|addressEntity|]
16 | }
17 | }
18 | }
19 |
20 | public class UserDTO{
21 | public AddressDTO Address {get; set;}
22 | }
23 |
24 | public class AddressDTO
25 | {
26 | public string FlatNo { get; set; }
27 | public string BuildtingNo { get; set; }
28 | public string Street { get; set; }
29 | public string ZipCode { get; set; }
30 | public string City { get; set; }
31 | }
32 |
33 | public class AddressEntity
34 | {
35 | public string FlatNo { get; set; }
36 | public string BuildtingNo { get; set; }
37 | public string Street { get; set; }
38 | public string ZipCode { get; set; }
39 | public string City { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public UserDTO DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | return new UserDTO{
15 | Address = new AddressDTO
16 | {
17 | FlatNo = addressEntity.FlatNo,
18 | BuildtingNo = addressEntity.BuildtingNo,
19 | Street = addressEntity.Street,
20 | ZipCode = addressEntity.ZipCode,
21 | City = addressEntity.City
22 | }
23 | }
24 | }
25 | }
26 |
27 | public class UserDTO{
28 | public AddressDTO Address {get; set;}
29 | }
30 |
31 | public class AddressDTO
32 | {
33 | public string FlatNo { get; set; }
34 | public string BuildtingNo { get; set; }
35 | public string Street { get; set; }
36 | public string ZipCode { get; set; }
37 | public string City { get; set; }
38 | }
39 |
40 | public class AddressEntity
41 | {
42 | public string FlatNo { get; set; }
43 | public string BuildtingNo { get; set; }
44 | public string Street { get; set; }
45 | public string ZipCode { get; set; }
46 | public string City { get; set; }
47 | }
48 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/005_ExplicitConversionReUseInstance.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public void DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | this.Address = [|addressEntity|];
15 | }
16 | }
17 |
18 | public class AddressDTO
19 | {
20 | public string FlatNo { get; set; }
21 | public string BuildtingNo { get; set; }
22 | public string Street { get; set; }
23 | public string ZipCode { get; set; }
24 | public string City { get; set; }
25 | }
26 |
27 | public class AddressEntity
28 | {
29 | public string FlatNo { get; set; }
30 | public string BuildtingNo { get; set; }
31 | public string Street { get; set; }
32 | public string ZipCode { get; set; }
33 | public string City { get; set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/005_ExplicitConversionReUseInstance_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public void DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | this.Address.FlatNo = addressEntity.FlatNo;
15 | this.Address.BuildtingNo = addressEntity.BuildtingNo;
16 | this.Address.Street = addressEntity.Street;
17 | this.Address.ZipCode = addressEntity.ZipCode;
18 | this.Address.City = addressEntity.City;
19 | }
20 | }
21 |
22 | public class AddressDTO
23 | {
24 | public string FlatNo { get; set; }
25 | public string BuildtingNo { get; set; }
26 | public string Street { get; set; }
27 | public string ZipCode { get; set; }
28 | public string City { get; set; }
29 | }
30 |
31 | public class AddressEntity
32 | {
33 | public string FlatNo { get; set; }
34 | public string BuildtingNo { get; set; }
35 | public string Street { get; set; }
36 | public string ZipCode { get; set; }
37 | public string City { get; set; }
38 | }
39 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/006_ExplicitConversionForInvalidAssigmentInInitBlockReuseInstance.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public UserDTO DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | return new UserDTO{
15 | Address = [|addressEntity|]
16 | }
17 | }
18 | }
19 |
20 | public class UserDTO{
21 | public AddressDTO Address {get; set;}
22 | }
23 |
24 | public class AddressDTO
25 | {
26 | public string FlatNo { get; set; }
27 | public string BuildtingNo { get; set; }
28 | public string Street { get; set; }
29 | public string ZipCode { get; set; }
30 | public string City { get; set; }
31 | }
32 |
33 | public class AddressEntity
34 | {
35 | public string FlatNo { get; set; }
36 | public string BuildtingNo { get; set; }
37 | public string Street { get; set; }
38 | public string ZipCode { get; set; }
39 | public string City { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/006_ExplicitConversionForInvalidAssigmentInInitBlockReuseInstance_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class TestMapper
8 | {
9 | public AddressDTO Address { get; set; }
10 |
11 | public UserDTO DoSomething()
12 | {
13 | var addressEntity = new AddressEntity();
14 | return new UserDTO{
15 | Address =
16 | {
17 | FlatNo = addressEntity.FlatNo,
18 | BuildtingNo = addressEntity.BuildtingNo,
19 | Street = addressEntity.Street,
20 | ZipCode = addressEntity.ZipCode,
21 | City = addressEntity.City
22 | }
23 | }
24 | }
25 | }
26 |
27 | public class UserDTO{
28 | public AddressDTO Address {get; set;}
29 | }
30 |
31 | public class AddressDTO
32 | {
33 | public string FlatNo { get; set; }
34 | public string BuildtingNo { get; set; }
35 | public string Street { get; set; }
36 | public string ZipCode { get; set; }
37 | public string City { get; set; }
38 | }
39 |
40 | public class AddressEntity
41 | {
42 | public string FlatNo { get; set; }
43 | public string BuildtingNo { get; set; }
44 | public string Street { get; set; }
45 | public string ZipCode { get; set; }
46 | public string City { get; set; }
47 | }
48 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/007_ExplicitConversionForValueCollection.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class Source
8 | {
9 | public string A { get; set; }
10 | }
11 |
12 | public class Destination
13 | {
14 | public string A { get; set; }
15 | }
16 |
17 | public class SampleMapper
18 | {
19 | public IEnumerable Example(Dictionary source)
20 | {
21 | return [|source.Values|];
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/007_ExplicitConversionForValueCollection_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
6 | {
7 | public class Source
8 | {
9 | public string A { get; set; }
10 | }
11 |
12 | public class Destination
13 | {
14 | public string A { get; set; }
15 | }
16 |
17 | public class SampleMapper
18 | {
19 | public IEnumerable Example(Dictionary source)
20 | {
21 | return source.Values.Select(sourceValue => new Destination
22 | {
23 | A = sourceValue.A
24 | });
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/ImplementCloneMethodTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using MappingGenerator.Features.Refactorings;
5 | using Microsoft.CodeAnalysis;
6 | using Microsoft.CodeAnalysis.CodeRefactorings;
7 | using NUnit.Framework;
8 | using RoslynTestKit;
9 |
10 | namespace MappingGenerator.Test.ImplementCloneMethod
11 | {
12 | public class ImplementCloneMethodTests : CodeRefactoringTestFixture
13 | {
14 | [Test]
15 | public void should_be_able_to_generate_deep_clone_method()
16 | {
17 | var test = ImplementCloneMethodTestCases._001_DeepClone;
18 | var fixedCode = ImplementCloneMethodTestCases._001_DeepClone_FIXED;
19 | TestCodeRefactoring(test, fixedCode);
20 | }
21 |
22 | [Test]
23 | public void should_be_able_to_generate_clone_with_using_clone_from_members()
24 | {
25 | var test = ImplementCloneMethodTestCases._002_DetecCloneOnMembers;
26 | var fixedCode = ImplementCloneMethodTestCases._002_DetecCloneOnMembers_FIXED;
27 | TestCodeRefactoring(test, fixedCode);
28 | }
29 |
30 | [Test]
31 | public void should_be_able_to_implement_clone_method_body()
32 | {
33 | var test = ImplementCloneMethodTestCases._003_ImplementCloneMethodBody;
34 | var fixedCode = ImplementCloneMethodTestCases._003_ImplementCloneMethodBody_FIXED;
35 | TestCodeRefactoring(test, fixedCode);
36 | }
37 |
38 | protected override string LanguageName => LanguageNames.CSharp;
39 | protected override CodeRefactoringProvider CreateProvider()
40 | {
41 | return new ImplementCloneMethodRefactoring();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class BaseDTO
9 | {
10 | public long Id { get; set;}
11 | }
12 |
13 | public class [|UserDTO|] : BaseDTO
14 | {
15 | public string FirstName { get; }
16 | public string LastName { get; private set; }
17 | public int Age { get; set; }
18 | public int Cash { get;}
19 | public AccountDTO Account { get; private set; }
20 | public List Debs { get; set; }
21 | public UserSourceDTO Source { get; set; }
22 | public string Login { get; set; }
23 | public byte[] ImageData { get; set; }
24 | public List LuckyNumbers { get; set; }
25 | public int Total { get; set; }
26 | public AddressDTO MainAddress { get; set; }
27 | public ReadOnlyCollection Addresses { get; set; }
28 | public int UnitId { get; set; }
29 | public int? Rate { get; set; }
30 | }
31 |
32 | public class UserSourceDTO
33 | {
34 | public string ProviderName { get; set; }
35 | public string ProviderAddress { get; set; }
36 |
37 | public UserSourceDTO(string providerName, string providerAddress)
38 | {
39 | ProviderName = providerName;
40 | ProviderAddress = providerAddress;
41 | }
42 | }
43 |
44 | public class AccountDTO
45 | {
46 | public string BankName { get; set; }
47 | public string Number { get; set; }
48 | }
49 |
50 | public class AddressDTO
51 | {
52 | public string City { get; set; }
53 | public string ZipCode { get; set; }
54 | public string Street { get; set; }
55 | public string FlatNo { get; set; }
56 | public string BuildingNo { get; set; }
57 | }
58 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/002_DetecCloneOnMembers.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class Classx : ICloneable
9 | {
10 | public string A { get; set; }
11 | public string B { get; set; }
12 |
13 | public Classx Clone()
14 | {
15 | return new Classx()
16 | {
17 | A = A,
18 | B = B
19 | };
20 | }
21 |
22 | object ICloneable.Clone()
23 | {
24 | return Clone();
25 | }
26 | }
27 |
28 |
29 | public class Classy : ICloneable
30 | {
31 | public string A { get; set; }
32 | public string B { get; set; }
33 |
34 |
35 | object ICloneable.Clone()
36 | {
37 | throw new NotImplementedException();
38 | }
39 | }
40 |
41 | public class Classz : ICloneable
42 | {
43 | public string A { get; set; }
44 | public string B { get; set; }
45 |
46 |
47 | public object Clone()
48 | {
49 | throw new NotImplementedException();
50 | }
51 | }
52 |
53 | public class [|User|]
54 | {
55 | public string FirstName { get; set; }
56 | public string LastName { get; set; }
57 | public int Age { get; set; }
58 | public Classx MyProperty1 { get; set; }
59 | public Classy MyProperty2 { get; set; }
60 | public Classz MyProperty3 { get; set; }
61 | }
62 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/002_DetecCloneOnMembers_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class Classx : ICloneable
9 | {
10 | public string A { get; set; }
11 | public string B { get; set; }
12 |
13 | public Classx Clone()
14 | {
15 | return new Classx()
16 | {
17 | A = A,
18 | B = B
19 | };
20 | }
21 |
22 | object ICloneable.Clone()
23 | {
24 | return Clone();
25 | }
26 | }
27 |
28 |
29 | public class Classy : ICloneable
30 | {
31 | public string A { get; set; }
32 | public string B { get; set; }
33 |
34 |
35 | object ICloneable.Clone()
36 | {
37 | throw new NotImplementedException();
38 | }
39 | }
40 |
41 | public class Classz : ICloneable
42 | {
43 | public string A { get; set; }
44 | public string B { get; set; }
45 |
46 |
47 | public object Clone()
48 | {
49 | throw new NotImplementedException();
50 | }
51 | }
52 |
53 | public class User : System.ICloneable
54 | {
55 | public string FirstName { get; set; }
56 | public string LastName { get; set; }
57 | public int Age { get; set; }
58 | public Classx MyProperty1 { get; set; }
59 | public Classy MyProperty2 { get; set; }
60 | public Classz MyProperty3 { get; set; }
61 |
62 | public User Clone()
63 | {
64 | return new User
65 | {
66 | FirstName = FirstName,
67 | LastName = LastName,
68 | Age = Age,
69 | MyProperty1 = MyProperty1.Clone(),
70 | MyProperty2 = ((ICloneable)MyProperty2).Clone() as Classy,
71 | MyProperty3 = MyProperty3.Clone() as Classz
72 | };
73 | }
74 |
75 | object ICloneable.Clone()
76 | {
77 | return Clone();
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/003_ImplementCloneMethodBody.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class ClassX
6 | {
7 | public string A { get; set; }
8 | public string B { get; set; }
9 |
10 | public ClassX [|Clone|]()
11 | {
12 | throw new NotImplementedException();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/003_ImplementCloneMethodBody_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class ClassX
6 | {
7 | public string A { get; set; }
8 | public string B { get; set; }
9 |
10 | public ClassX Clone()
11 | {
12 | return new ClassX
13 | {
14 | A = A,
15 | B = B
16 | };
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/InvocationScaffoldingTests.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Features.CodeFixes;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CodeFixes;
4 | using NUnit.Framework;
5 | using RoslynTestKit;
6 | using static MappingGenerator.Test.InvocationScaffolding.InvocationScaffoldingTestCases;
7 |
8 | namespace MappingGenerator.Test.InvocationScaffolding
9 | {
10 | public class InvocationScaffoldingTests: CodeFixTestFixture
11 | {
12 | [Test]
13 | public void should_be_able_to_scaffold_method_invocation_using_regular_arguments()
14 | {
15 | TestCodeFix(_001_MethodInvocationScaffolding_With_RegularArguments, _001_MethodInvocationScaffolding_With_RegularArguments_FIXED, InvocationScaffoldingCodeFixProvider.CS7036);
16 | }
17 |
18 | [Test]
19 | public void should_be_able_to_scaffold_method_invocation_using_named_arguments()
20 | {
21 | TestCodeFix(_002_MethodInvocationScaffolding_With_NamedArguments, _002_MethodInvocationScaffolding_With_NamedArguments_FIXED, InvocationScaffoldingCodeFixProvider.CS7036, 1);
22 | }
23 |
24 | [Test]
25 | public void should_be_able_to_scaffold_constructor_invocation_using_regular_arguments()
26 | {
27 | TestCodeFix(_003_ConstructorInvocationScaffolding_With_RegularArguments, _003_ConstructorInvocationScaffolding_With_RegularArguments_FIXED, InvocationScaffoldingCodeFixProvider.CS7036);
28 |
29 | }
30 |
31 | [Test]
32 | public void should_be_able_to_scaffold_constructor_invocation_using_named_arguments()
33 | {
34 | TestCodeFix(_004_ConstructorInvocationScaffolding_With_NamedArguments, _004_ConstructorInvocationScaffolding_With_NamedArguments_FIXED, InvocationScaffoldingCodeFixProvider.CS7036, 1);
35 | }
36 |
37 | protected override string LanguageName => LanguageNames.CSharp;
38 |
39 | protected override CodeFixProvider CreateProvider()
40 | {
41 | return new InvocationScaffoldingCodeFixProvider();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/001_MethodInvocationScaffolding_With_RegularArguments.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static void DoSth()
6 | {
7 | [|DoSthElse()|];
8 | }
9 |
10 |
11 | public static void DoSthElse(string parameter1, int parameter2)
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/001_MethodInvocationScaffolding_With_RegularArguments_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static void DoSth()
6 | {
7 | DoSthElse("lorem ipsum", 32);
8 | }
9 |
10 |
11 | public static void DoSthElse(string parameter1, int parameter2)
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/002_MethodInvocationScaffolding_With_NamedArguments.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static void DoSth()
6 | {
7 | [|DoSthElse()|];
8 | }
9 |
10 |
11 | public static void DoSthElse(string parameter1, int parameter2)
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/002_MethodInvocationScaffolding_With_NamedArguments_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static void DoSth()
6 | {
7 | DoSthElse(parameter1: "lorem ipsum", parameter2: 32);
8 | }
9 |
10 |
11 | public static void DoSthElse(string parameter1, int parameter2)
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/003_ConstructorInvocationScaffolding_With_RegularArguments.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static AnotherClass DoSth()
6 | {
7 | return new [|AnotherClass()|];
8 | }
9 |
10 |
11 | public class AnotherClass
12 | {
13 | public AnotherClass(string parameter1, int parameter2)
14 | {
15 | }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/003_ConstructorInvocationScaffolding_With_RegularArguments_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static AnotherClass DoSth()
6 | {
7 | return new AnotherClass("lorem ipsum", 32);
8 | }
9 |
10 |
11 | public class AnotherClass
12 | {
13 | public AnotherClass(string parameter1, int parameter2)
14 | {
15 | }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/004_ConstructorInvocationScaffolding_With_NamedArguments.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static AnotherClass DoSth()
6 | {
7 | return new [|AnotherClass()|];
8 | }
9 |
10 |
11 | public class AnotherClass
12 | {
13 | public AnotherClass(string parameter1, int parameter2)
14 | {
15 | }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/InvocationScaffolding/TestData/004_ConstructorInvocationScaffolding_With_NamedArguments_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace Scaffolding
2 | {
3 | public static class SampleClass
4 | {
5 | public static AnotherClass DoSth()
6 | {
7 | return new AnotherClass(parameter1: "lorem ipsum", parameter2: 32);
8 | }
9 |
10 |
11 | public class AnotherClass
12 | {
13 | public AnotherClass(string parameter1, int parameter2)
14 | {
15 | }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/MappingGeneratorForBrokenCodeTests.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Features.Refactorings;
2 | using MappingGenerator.Test.MappingGenerator;
3 | using Microsoft.CodeAnalysis;
4 | using Microsoft.CodeAnalysis.CodeRefactorings;
5 | using NUnit.Framework;
6 | using RoslynTestKit;
7 |
8 | namespace MappingGenerator.Test.Mapping
9 | {
10 | public class MappingGeneratorForBrokenCodeTests : CodeRefactoringTestFixture
11 | {
12 | protected override string LanguageName => LanguageNames.CSharp;
13 | protected override CodeRefactoringProvider CreateProvider() => new MappingGeneratorRefactoring();
14 | protected override bool FailWhenInputContainsErrors => false;
15 |
16 | [Test]
17 | public void should_be_able_to_replace_invalid_body_with_mapping_body()
18 | {
19 | TestCodeRefactoring(MappingGeneratorTestCases._024_InvalidSyntaxPureMappingMethod, MappingGeneratorTestCases._024_InvalidSyntaxPureMappingMethod_FIXED);
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/005_UpdateThisObjectWithMultipleParameters.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | public class Person
4 | {
5 | public int Age { get; set; }
6 | public string FirstName { get; set; }
7 | public string LastName { get; set; }
8 |
9 | public void [|Update|](int age, string firstName, string lastName)
10 | {
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/005_UpdateThisObjectWithMultipleParameters_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | public class Person
4 | {
5 | public int Age { get; set; }
6 | public string FirstName { get; set; }
7 | public string LastName { get; set; }
8 |
9 | public void Update(int age, string firstName, string lastName)
10 | {
11 | Age = age;
12 | FirstName = firstName;
13 | LastName = lastName;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/005_UpdateThisObjectWithTwoParameters.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | public class Person
4 | {
5 | public int Age { get; set; }
6 | public string Name { get; set; }
7 |
8 | public void [|Update|](int age, string name)
9 | {
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/005_UpdateThisObjectWithTwoParameters_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | public class Person
4 | {
5 | public int Age { get; set; }
6 | public string Name { get; set; }
7 |
8 | public void Update(int age, string name)
9 | {
10 | Age = age;
11 | Name = name;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/008_StopRecursingMapping.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
5 | {
6 | public class Model1Vm
7 | {
8 | public int Id { get; set; }
9 | public List Model2s { get; set; }
10 |
11 | public Model1Vm [|Map|](Model1 src)
12 | {
13 | throw new NotImplementedException();
14 | }
15 | }
16 |
17 | public class Model2Vm
18 | {
19 | public int Id { get; set; }
20 | public Model1Vm Model1 { get; set; }
21 |
22 | public string Label { get; set; }
23 | }
24 |
25 | public class Model1
26 | {
27 | public int Id { get; set; }
28 | public List Model2s { get; set; }
29 | }
30 |
31 | public class Model2
32 | {
33 | public int Id { get; set; }
34 | public Model1 Model1 { get; set; }
35 |
36 | public string Label { get; set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/008_StopRecursingMapping_Fixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
5 | {
6 | public class Model1Vm
7 | {
8 | public int Id { get; set; }
9 | public List Model2s { get; set; }
10 |
11 | public Model1Vm Map(Model1 src)
12 | {
13 | return new Model1Vm
14 | {
15 | Id = src.Id,
16 | Model2s = src.Model2s.ConvertAll(srcModel2 => new Model2Vm
17 | {
18 | Id = srcModel2.Id,
19 | Model1 = srcModel2.Model1 /* Stop recursive mapping */,
20 | Label = srcModel2.Label
21 | })
22 | };
23 | }
24 | }
25 |
26 | public class Model2Vm
27 | {
28 | public int Id { get; set; }
29 | public Model1Vm Model1 { get; set; }
30 |
31 | public string Label { get; set; }
32 | }
33 |
34 | public class Model1
35 | {
36 | public int Id { get; set; }
37 | public List Model2s { get; set; }
38 | }
39 |
40 | public class Model2
41 | {
42 | public int Id { get; set; }
43 | public Model1 Model1 { get; set; }
44 |
45 | public string Label { get; set; }
46 | }
47 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/009_IdentityFunctionMapping.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity
7 | {
8 | public class TestMapper
9 | {
10 | public static UserDTO [|Map|](UserDTO old)
11 | {
12 | throw new NotImplementedException();
13 | }
14 | }
15 |
16 | public class UserDTO
17 | {
18 | public string FirstName { get; }
19 | public string LastName { get; private set; }
20 | public int Age { get; set; }
21 | public int Cash { get; }
22 | public AccountDTO Account { get; private set; }
23 | public List Debs { get; set; }
24 | public UserSourceDTO Source { get; set; }
25 | public string Login { get; set; }
26 | public byte[] ImageData { get; set; }
27 | public List LuckyNumbers { get; set; }
28 | public int Total { get; set; }
29 | public AddressDTO MainAddress { get; set; }
30 | public ReadOnlyCollection Addresses { get; set; }
31 | public int UnitId { get; set; }
32 | public Guid UniqueKey { get; set;}
33 | }
34 |
35 | public class UserSourceDTO
36 | {
37 | public string ProviderName { get; set; }
38 | public string ProviderAddress { get; set; }
39 |
40 | public UserSourceDTO(string providerName, string providerAddress)
41 | {
42 | ProviderName = providerName;
43 | ProviderAddress = providerAddress;
44 | }
45 | }
46 |
47 | public class AccountDTO:ICloneable
48 | {
49 | public string BankName { get; set; }
50 | public string Number { get; set; }
51 |
52 | public object Clone()
53 | {
54 | throw new NotImplementedException();
55 | }
56 | }
57 |
58 | public class AddressDTO
59 | {
60 | public string City { get; set; }
61 | public string ZipCode { get; set; }
62 | public string Street { get; set; }
63 | public string FlatNo { get; set; }
64 | public string BuildingNo { get; set; }
65 | }
66 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/010_IdentityFunctionMappingForSimpleType.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity
7 | {
8 | public class TestMapper
9 | {
10 | public static long [|Map|](long old)
11 | {
12 | throw new NotImplementedException();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/010_IdentityFunctionMappingForSimpleType_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity
7 | {
8 | public class TestMapper
9 | {
10 | public static long Map(long old)
11 | {
12 | return old;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/011_IdentityFunctionMappingForCollection.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity
7 | {
8 | public class TestMapper
9 | {
10 | public static List [|Map|](List old)
11 | {
12 | throw new NotImplementedException();
13 | }
14 | }
15 |
16 | public class UserDTO
17 | {
18 | public string FirstName { get; }
19 | public string LastName { get; private set; }
20 | public int Age { get; set; }
21 | public int Cash { get; }
22 | public AccountDTO Account { get; private set; }
23 | public List Debs { get; set; }
24 | public UserSourceDTO Source { get; set; }
25 | public string Login { get; set; }
26 | public byte[] ImageData { get; set; }
27 | public List LuckyNumbers { get; set; }
28 | public int Total { get; set; }
29 | public AddressDTO MainAddress { get; set; }
30 | public ReadOnlyCollection Addresses { get; set; }
31 | public int UnitId { get; set; }
32 | }
33 |
34 | public class UserSourceDTO
35 | {
36 | public string ProviderName { get; set; }
37 | public string ProviderAddress { get; set; }
38 |
39 | public UserSourceDTO(string providerName, string providerAddress)
40 | {
41 | ProviderName = providerName;
42 | ProviderAddress = providerAddress;
43 | }
44 | }
45 |
46 | public class AccountDTO:ICloneable
47 | {
48 | public string BankName { get; set; }
49 | public string Number { get; set; }
50 |
51 | public object Clone()
52 | {
53 | throw new NotImplementedException();
54 | }
55 | }
56 |
57 | public class AddressDTO
58 | {
59 | public string City { get; set; }
60 | public string ZipCode { get; set; }
61 | public string Street { get; set; }
62 | public string FlatNo { get; set; }
63 | public string BuildingNo { get; set; }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/012_CollectionMappingWithSingularLambdaParameterName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List [|Map|](List categories)
22 | {
23 | throw new NotImplementedException();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/012_CollectionMappingWithSingularLambdaParameterName_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List Map(List categories)
22 | {
23 | return categories.ConvertAll(category => new YY
24 | {
25 | Id = category.Id,
26 | Name = category.Name
27 | });
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/013_CollectionMappingWithPrefixedLambdaParameterName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int CategoryId { get; set; }
17 | public string CategoryName { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List [|MapNew|](List categories)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/013_CollectionMappingWithPrefixedLambdaParameterName_FIXED..txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int CategoryId { get; set; }
17 | public string CategoryName { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List MapNew(List categories)
23 | {
24 | return categories.ConvertAll(category => new ZZ
25 | {
26 | CategoryId = category.Id,
27 | CategoryName = category.Name
28 | });
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/014_CollectionMappingWithGenericName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List [|MapNew|](List dictionary)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/014_CollectionMappingWithGenericName_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List MapNew(List dictionary)
23 | {
24 | return dictionary.ConvertAll(item => new ZZ
25 | {
26 | Id = item.Id,
27 | Name = item.Name
28 | });
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/015_CollectionMappingWithPostfixGenericName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List [|MapNew|](List usersList)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/015_CollectionMappingWithPostfixGenericName_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List MapNew(List usersList)
23 | {
24 | return usersList.ConvertAll(user => new ZZ
25 | {
26 | Id = user.Id,
27 | Name = user.Name
28 | });
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/016_CollectionMappingWithIrregularSingularLambdaParameterName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List [|Map|](List people)
22 | {
23 | throw new NotImplementedException();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/016_CollectionMappingWithIrregularSingularLambdaParameterName_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List Map(List people)
22 | {
23 | return people.ConvertAll(person => new YY
24 | {
25 | Id = person.Id,
26 | Name = person.Name
27 | });
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/017_CollectionMappingWithIrregularCamelCaseSingularLambdaParameterName.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List [|Map|](List relatedPeople)
22 | {
23 | throw new NotImplementedException();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/017_CollectionMappingWithIrregularCamelCaseSingularLambdaParameterName_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List Map(List relatedPeople)
22 | {
23 | return relatedPeople.ConvertAll(relatedPerson => new YY
24 | {
25 | Id = relatedPerson.Id,
26 | Name = relatedPerson.Name
27 | });
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/018_CollectionMappingWithPostfixGenericNameInSingular.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List [|MapNew|](List userList)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/018_CollectionMappingWithPostfixGenericNameInSingular_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 |
6 | namespace TestAutoMapper.Identity.X
7 | {
8 | public class XX
9 | {
10 | public int Id { get; set; }
11 | public string Name { get; set; }
12 | }
13 |
14 | public class ZZ
15 | {
16 | public int Id { get; set; }
17 | public string Name { get; set; }
18 | }
19 |
20 | public static class Mapper{
21 |
22 | public static List MapNew(List userList)
23 | {
24 | return userList.ConvertAll(user => new ZZ
25 | {
26 | Id = user.Id,
27 | Name = user.Name
28 | });
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/019_MappingPropertiesInheritedFromLibraryClass.txt:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNet.Identity.EntityFramework;
2 | using System;
3 |
4 | namespace TestAutoMapper
5 | {
6 | public static class ExternalUserTest
7 | {
8 | public static ApplicationUserEntity [|ToEntity|](this UserModel model)
9 | {
10 | throw new NotImplementedException();
11 | }
12 | }
13 |
14 | public class UserModel
15 | {
16 | public string NewProperty1 { get; set; }
17 | public string NewProperty2 { get; set; }
18 |
19 | public virtual string Email { get; set; }
20 |
21 | public virtual bool EmailConfirmed { get; set; }
22 |
23 | public virtual string PasswordHash { get; set; }
24 |
25 | public virtual string SecurityStamp { get; set; }
26 |
27 | public virtual string PhoneNumber { get; set; }
28 | public virtual bool PhoneNumberConfirmed { get; set; }
29 |
30 | }
31 |
32 | public class ApplicationUserEntity: IdentityUser
33 | {
34 | public string NewProperty1 { get; set; }
35 | public string NewProperty2 { get; set; }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/019_MappingPropertiesInheritedFromLibraryClass_FIXED.txt:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNet.Identity.EntityFramework;
2 | using System;
3 |
4 | namespace TestAutoMapper
5 | {
6 | public static class ExternalUserTest
7 | {
8 | public static ApplicationUserEntity ToEntity(this UserModel model)
9 | {
10 | return new ApplicationUserEntity
11 | {
12 | NewProperty1 = model.NewProperty1,
13 | NewProperty2 = model.NewProperty2,
14 | Email = model.Email,
15 | EmailConfirmed = model.EmailConfirmed,
16 | PasswordHash = model.PasswordHash,
17 | SecurityStamp = model.SecurityStamp,
18 | PhoneNumber = model.PhoneNumber,
19 | PhoneNumberConfirmed = model.PhoneNumberConfirmed
20 | };
21 | }
22 | }
23 |
24 | public class UserModel
25 | {
26 | public string NewProperty1 { get; set; }
27 | public string NewProperty2 { get; set; }
28 |
29 | public virtual string Email { get; set; }
30 |
31 | public virtual bool EmailConfirmed { get; set; }
32 |
33 | public virtual string PasswordHash { get; set; }
34 |
35 | public virtual string SecurityStamp { get; set; }
36 |
37 | public virtual string PhoneNumber { get; set; }
38 | public virtual bool PhoneNumberConfirmed { get; set; }
39 |
40 | }
41 |
42 | public class ApplicationUserEntity: IdentityUser
43 | {
44 | public string NewProperty1 { get; set; }
45 | public string NewProperty2 { get; set; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/020_MappingPropertiesInConstructorInheritedFromLibraryClass.txt:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNet.Identity.EntityFramework;
2 | using System;
3 |
4 | namespace TestAutoMapper
5 | {
6 | public class UserModel
7 | {
8 | public string NewProperty1 { get; set; }
9 | public string NewProperty2 { get; set; }
10 |
11 | public virtual string Email { get; set; }
12 |
13 | public virtual bool EmailConfirmed { get; set; }
14 |
15 | public virtual string PasswordHash { get; set; }
16 |
17 | public virtual string SecurityStamp { get; set; }
18 |
19 | public virtual string PhoneNumber { get; set; }
20 | public virtual bool PhoneNumberConfirmed { get; set; }
21 |
22 | }
23 |
24 | public class ApplicationUserEntity: IdentityUser
25 | {
26 | public string NewProperty1 { get; set; }
27 | public string NewProperty2 { get; set; }
28 |
29 | public [|ApplicationUserEntity|](UserModel model)
30 | {
31 | throw new NotImplementedException();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/020_MappingPropertiesInConstructorInheritedFromLibraryClass_FIXED.txt:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNet.Identity.EntityFramework;
2 | using System;
3 |
4 | namespace TestAutoMapper
5 | {
6 | public class UserModel
7 | {
8 | public string NewProperty1 { get; set; }
9 | public string NewProperty2 { get; set; }
10 |
11 | public virtual string Email { get; set; }
12 |
13 | public virtual bool EmailConfirmed { get; set; }
14 |
15 | public virtual string PasswordHash { get; set; }
16 |
17 | public virtual string SecurityStamp { get; set; }
18 |
19 | public virtual string PhoneNumber { get; set; }
20 | public virtual bool PhoneNumberConfirmed { get; set; }
21 |
22 | }
23 |
24 | public class ApplicationUserEntity: IdentityUser
25 | {
26 | public string NewProperty1 { get; set; }
27 | public string NewProperty2 { get; set; }
28 |
29 | public ApplicationUserEntity(UserModel model)
30 | {
31 | NewProperty1 = model.NewProperty1;
32 | NewProperty2 = model.NewProperty2;
33 | Email = model.Email;
34 | EmailConfirmed = model.EmailConfirmed;
35 | PasswordHash = model.PasswordHash;
36 | SecurityStamp = model.SecurityStamp;
37 | PhoneNumber = model.PhoneNumber;
38 | PhoneNumberConfirmed = model.PhoneNumberConfirmed;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/022_CollectionMappingIListToList.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List [|Map|](IList categories)
22 | {
23 | throw new NotImplementedException();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/022_CollectionMappingIListToList_Fixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace TestAutoMapper.Identity.X
6 | {
7 | public class XX
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 | }
12 |
13 | public class YY
14 | {
15 | public int Id { get; set; }
16 | public string Name { get; set; }
17 | }
18 |
19 | public static class Mapper{
20 |
21 | public static List Map(IList categories)
22 | {
23 | return categories.Select(category => new YY
24 | {
25 | Id = category.Id,
26 | Name = category.Name
27 | }).ToList();
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/025_ThisObjectToOtherMapping.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public struct Category { }
6 | public struct Tag { }
7 | public class CreateProductCommand
8 | {
9 | public string Name { get; set; }
10 |
11 | public decimal Price { get; set; }
12 |
13 | public Category Category { get; set; }
14 |
15 | public Tag[] Tags { get; set; }
16 |
17 | public Product [|ToProduct()|]
18 | {
19 | throw new NotImplementedException();
20 | }
21 | }
22 |
23 | public class Product
24 | {
25 | public Product(string name, decimal price, Category category, Tag[] tags)
26 | {
27 | Id = new Guid();
28 | Name = name;
29 | Price = price;
30 | Category = category;
31 | Tags = tags;
32 | }
33 |
34 | public Guid Id { get; private set; }
35 |
36 | public string Name { get; private set; }
37 |
38 | public decimal Price { get; private set; }
39 |
40 | public Category Category { get; private set; }
41 |
42 | public Tag[] Tags { get; private set; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/025_ThisObjectToOtherMapping_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public struct Category { }
6 | public struct Tag { }
7 | public class CreateProductCommand
8 | {
9 | public string Name { get; set; }
10 |
11 | public decimal Price { get; set; }
12 |
13 | public Category Category { get; set; }
14 |
15 | public Tag[] Tags { get; set; }
16 |
17 | public Product ToProduct()
18 | {
19 | return new Product(name: this.Name, price: this.Price, category: this.Category, tags: this.Tags);
20 | }
21 | }
22 |
23 | public class Product
24 | {
25 | public Product(string name, decimal price, Category category, Tag[] tags)
26 | {
27 | Id = new Guid();
28 | Name = name;
29 | Price = price;
30 | Category = category;
31 | Tags = tags;
32 | }
33 |
34 | public Guid Id { get; private set; }
35 |
36 | public string Name { get; private set; }
37 |
38 | public decimal Price { get; private set; }
39 |
40 | public Category Category { get; private set; }
41 |
42 | public Tag[] Tags { get; private set; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/026_UpdateThisObjectWithSingleParameterMethod.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class Person
6 | {
7 | public int Age { get; set; }
8 | public string Name { get; set; }
9 |
10 | public void [|Update|](int age)
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/026_UpdateThisObjectWithSingleParameterMethod_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class Person
6 | {
7 | public int Age { get; set; }
8 | public string Name { get; set; }
9 |
10 | public void Update(int age)
11 | {
12 | Age = age;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/027_ConstructorWithSingleParameter.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class Person
6 | {
7 | public int Age { get; set; }
8 | public string Name { get; set; }
9 |
10 | public [|Person|](int age)
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/027_ConstructorWithSingleParameter_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
4 | {
5 | public class Person
6 | {
7 | public int Age { get; set; }
8 | public string Name { get; set; }
9 |
10 | public Person(int age)
11 | {
12 | Age = age;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/028_PrivateUpdateFieldAccessibility.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA
4 | {
5 | public string Property1 { get; set; }
6 | public string Property2 { get; set; }
7 | public string Property3 { get; set; }
8 | public string Property4 { get; set; }
9 | public string Property5 { get; set; }
10 | public string Property6 { get; set; }
11 | public string Property7 { get; set; }
12 | public string Property8 { get; set; }
13 | public string Property9 { get; set; }
14 | public string Property10 { get; set; }
15 | public string BaseProperty1 { get; set; }
16 | public string BaseProperty2 { get; set; }
17 | public string BaseProperty3 { get; set; }
18 | public string BaseProperty4 { get; set; }
19 | public string BaseProperty5 { get; set; }
20 | public string BaseProperty6 { get; set; }
21 | public string BaseProperty7 { get; set; }
22 | public string BaseProperty8 { get; set; }
23 | public string BaseProperty9 { get; set; }
24 | public string BaseProperty10 { get; set; }
25 | public string BaseProperty11 { get; set; }
26 | }
27 |
28 | class BaseClassB
29 | {
30 | public string BaseProperty1 { get; set; }
31 | internal string BaseProperty2 { get; set; }
32 | public string BaseProperty3 { get; private set; }
33 | internal string BaseProperty4 { get; private set; }
34 | public string BaseProperty5 { get; }
35 | public string BaseProperty6 => string.Empty;
36 | string BaseProperty7 { get; set; }
37 | private string BaseProperty8 { get; set; }
38 | protected string BaseProperty9 { get; set; }
39 | protected string BaseProperty10 { get; private set; }
40 | public string BaseProperty11 { get; protected set; }
41 | }
42 |
43 | class ClassB: BaseClassB
44 | {
45 | public string Property1 { get; set; }
46 | internal string Property2 { get; set; }
47 | public string Property3 { get; private set; }
48 | internal string Property4 { get; private set; }
49 | public string Property5 { get; }
50 | public string Property6 => string.Empty;
51 | string Property7 { get; set; }
52 | private string Property8 { get; set; }
53 | protected string Property9 { get; set; }
54 | protected string Property10 { get; private set; }
55 |
56 | private void [|Update|](ClassA from)
57 | {
58 |
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/030_ConstructorUpdateFieldAccessibility.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA
4 | {
5 | public string Property1 { get; set; }
6 | public string Property2 { get; set; }
7 | public string Property3 { get; set; }
8 | public string Property4 { get; set; }
9 | public string Property5 { get; set; }
10 | public string Property6 { get; set; }
11 | public string Property7 { get; set; }
12 | public string Property8 { get; set; }
13 | public string Property9 { get; set; }
14 | public string Property10 { get; set; }
15 | public string BaseProperty1 { get; set; }
16 | public string BaseProperty2 { get; set; }
17 | public string BaseProperty3 { get; set; }
18 | public string BaseProperty4 { get; set; }
19 | public string BaseProperty5 { get; set; }
20 | public string BaseProperty6 { get; set; }
21 | public string BaseProperty7 { get; set; }
22 | public string BaseProperty8 { get; set; }
23 | public string BaseProperty9 { get; set; }
24 | public string BaseProperty10 { get; set; }
25 | public string BaseProperty11 { get; set; }
26 | }
27 |
28 | class BaseClassB
29 | {
30 | public string BaseProperty1 { get; set; }
31 | internal string BaseProperty2 { get; set; }
32 | public string BaseProperty3 { get; private set; }
33 | internal string BaseProperty4 { get; private set; }
34 | public string BaseProperty5 { get; }
35 | public string BaseProperty6 => string.Empty;
36 | string BaseProperty7 { get; set; }
37 | private string BaseProperty8 { get; set; }
38 | protected string BaseProperty9 { get; set; }
39 | protected string BaseProperty10 { get; private set; }
40 | public string BaseProperty11 { get; protected set; }
41 | }
42 |
43 | class ClassB: BaseClassB
44 | {
45 | public string Property1 { get; set; }
46 | internal string Property2 { get; set; }
47 | public string Property3 { get; private set; }
48 | internal string Property4 { get; private set; }
49 | public string Property5 { get; }
50 | public string Property6 => string.Empty;
51 | string Property7 { get; set; }
52 | private string Property8 { get; set; }
53 | protected string Property9 { get; set; }
54 | protected string Property10 { get; private set; }
55 |
56 | public [|ClassB|](ClassA from)
57 | {
58 |
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/032_PubliclyUpdateFieldAccessibility.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA
4 | {
5 | public string Property1 { get; set; }
6 | public string Property2 { get; set; }
7 | public string Property3 { get; set; }
8 | public string Property4 { get; set; }
9 | public string Property5 { get; set; }
10 | public string Property6 { get; set; }
11 | public string Property7 { get; set; }
12 | public string Property8 { get; set; }
13 | public string Property9 { get; set; }
14 | public string Property10 { get; set; }
15 | public string BaseProperty1 { get; set; }
16 | public string BaseProperty2 { get; set; }
17 | public string BaseProperty3 { get; set; }
18 | public string BaseProperty4 { get; set; }
19 | public string BaseProperty5 { get; set; }
20 | public string BaseProperty6 { get; set; }
21 | public string BaseProperty7 { get; set; }
22 | public string BaseProperty8 { get; set; }
23 | public string BaseProperty9 { get; set; }
24 | public string BaseProperty10 { get; set; }
25 | public string BaseProperty11 { get; set; }
26 | }
27 |
28 | class BaseClassB
29 | {
30 | public string BaseProperty1 { get; set; }
31 | internal string BaseProperty2 { get; set; }
32 | public string BaseProperty3 { get; private set; }
33 | internal string BaseProperty4 { get; private set; }
34 | public string BaseProperty5 { get; }
35 | public string BaseProperty6 => string.Empty;
36 | string BaseProperty7 { get; set; }
37 | private string BaseProperty8 { get; set; }
38 | protected string BaseProperty9 { get; set; }
39 | protected string BaseProperty10 { get; private set; }
40 | public string BaseProperty11 { get; protected set; }
41 | }
42 |
43 | class ClassB: BaseClassB
44 | {
45 | public string Property1 { get; set; }
46 | internal string Property2 { get; set; }
47 | public string Property3 { get; private set; }
48 | internal string Property4 { get; private set; }
49 | public string Property5 { get; }
50 | public string Property6 => string.Empty;
51 | string Property7 { get; set; }
52 | private string Property8 { get; set; }
53 | protected string Property9 { get; set; }
54 | protected string Property10 { get; private set; }
55 | }
56 |
57 | class Mapper
58 | {
59 | public ClassB [|Map|](ClassA from)
60 | {
61 | throw new System.NotImplementedException();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/034_PubliclyUpdateFieldAccessibilityForFields.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA: BaseClassA
4 | {
5 | public string Field1;
6 | public string Field2;
7 | public string Field3;
8 | public string Field4;
9 | public string BaseField1;
10 | public string BaseField2;
11 | public string BaseField3;
12 | public string BaseField4;
13 | public string ExtraField1;
14 | protected string ExtraField2;
15 | private string ExtraField3;
16 | internal string ExtraField4;
17 | }
18 |
19 | class BaseClassA
20 | {
21 | public string BaseExtraField1;
22 | protected string BaseExtraField2;
23 | private string BaseExtraField3;
24 | internal string BaseExtraField4;
25 | }
26 |
27 |
28 | class ClassB: BaseClassB
29 | {
30 | public string Field1;
31 | private string Field2;
32 | protected string Field3;
33 | internal string Field4;
34 | public string ExtraField1;
35 | public string ExtraField2;
36 | public string ExtraField3;
37 | public string ExtraField4;
38 | public string BaseExtraField1;
39 | public string BaseExtraField2;
40 | public string BaseExtraField3;
41 | public string BaseExtraField4;
42 | }
43 |
44 | class BaseClassB
45 | {
46 | public string BaseField1;
47 | private string BaseField2;
48 | protected string BaseField3;
49 | internal string BaseField4;
50 | }
51 |
52 | class Mapper
53 | {
54 | public ClassB [|Map|](ClassA from)
55 | {
56 | throw new System.NotImplementedException();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/034_PubliclyUpdateFieldAccessibilityForFields_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA: BaseClassA
4 | {
5 | public string Field1;
6 | public string Field2;
7 | public string Field3;
8 | public string Field4;
9 | public string BaseField1;
10 | public string BaseField2;
11 | public string BaseField3;
12 | public string BaseField4;
13 | public string ExtraField1;
14 | protected string ExtraField2;
15 | private string ExtraField3;
16 | internal string ExtraField4;
17 | }
18 |
19 | class BaseClassA
20 | {
21 | public string BaseExtraField1;
22 | protected string BaseExtraField2;
23 | private string BaseExtraField3;
24 | internal string BaseExtraField4;
25 | }
26 |
27 |
28 | class ClassB: BaseClassB
29 | {
30 | public string Field1;
31 | private string Field2;
32 | protected string Field3;
33 | internal string Field4;
34 | public string ExtraField1;
35 | public string ExtraField2;
36 | public string ExtraField3;
37 | public string ExtraField4;
38 | public string BaseExtraField1;
39 | public string BaseExtraField2;
40 | public string BaseExtraField3;
41 | public string BaseExtraField4;
42 | }
43 |
44 | class BaseClassB
45 | {
46 | public string BaseField1;
47 | private string BaseField2;
48 | protected string BaseField3;
49 | internal string BaseField4;
50 | }
51 |
52 | class Mapper
53 | {
54 | public ClassB Map(ClassA from)
55 | {
56 | return new ClassB
57 | {
58 | Field1 = from.Field1,
59 | Field4 = from.Field4,
60 | ExtraField1 = from.ExtraField1,
61 | ExtraField4 = from.ExtraField4,
62 | BaseExtraField1 = from.BaseExtraField1,
63 | BaseExtraField4 = from.BaseExtraField4,
64 | BaseField1 = from.BaseField1,
65 | BaseField4 = from.BaseField4
66 | };
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/035_ConstructorInitializeFIelds.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA: BaseClassA
4 | {
5 | public string Field1;
6 | public string Field2;
7 | public string Field3;
8 | public string Field4;
9 | public string BaseField1;
10 | public string BaseField2;
11 | public string BaseField3;
12 | public string BaseField4;
13 | public string ExtraField1;
14 | protected string ExtraField2;
15 | private string ExtraField3;
16 | internal string ExtraField4;
17 |
18 | public [|ClassA|](ClassB input)
19 | {
20 | }
21 | }
22 |
23 | class BaseClassA
24 | {
25 | public string BaseExtraField1;
26 | protected string BaseExtraField2;
27 | private string BaseExtraField3;
28 | internal string BaseExtraField4;
29 | }
30 |
31 |
32 | class ClassB: BaseClassB
33 | {
34 | public string Field1;
35 | private string Field2;
36 | protected string Field3;
37 | internal string Field4;
38 | public string ExtraField1;
39 | public string ExtraField2;
40 | public string ExtraField3;
41 | public string ExtraField4;
42 | public string BaseExtraField1;
43 | public string BaseExtraField2;
44 | public string BaseExtraField3;
45 | public string BaseExtraField4;
46 | }
47 |
48 | class BaseClassB
49 | {
50 | public string BaseField1;
51 | private string BaseField2;
52 | protected string BaseField3;
53 | internal string BaseField4;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator/TestCaseData/035_ConstructorInitializeFIelds_FIXED.txt:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
2 | {
3 | class ClassA: BaseClassA
4 | {
5 | public string Field1;
6 | public string Field2;
7 | public string Field3;
8 | public string Field4;
9 | public string BaseField1;
10 | public string BaseField2;
11 | public string BaseField3;
12 | public string BaseField4;
13 | public string ExtraField1;
14 | protected string ExtraField2;
15 | private string ExtraField3;
16 | internal string ExtraField4;
17 |
18 | public ClassA(ClassB input)
19 | {
20 | Field1 = input.Field1;
21 | Field4 = input.Field4;
22 | BaseField1 = input.BaseField1;
23 | BaseField4 = input.BaseField4;
24 | ExtraField1 = input.ExtraField1;
25 | ExtraField2 = input.ExtraField2;
26 | ExtraField3 = input.ExtraField3;
27 | ExtraField4 = input.ExtraField4;
28 | BaseExtraField1 = input.BaseExtraField1;
29 | BaseExtraField2 = input.BaseExtraField2;
30 | BaseExtraField4 = input.BaseExtraField4;
31 | }
32 | }
33 |
34 | class BaseClassA
35 | {
36 | public string BaseExtraField1;
37 | protected string BaseExtraField2;
38 | private string BaseExtraField3;
39 | internal string BaseExtraField4;
40 | }
41 |
42 |
43 | class ClassB: BaseClassB
44 | {
45 | public string Field1;
46 | private string Field2;
47 | protected string Field3;
48 | internal string Field4;
49 | public string ExtraField1;
50 | public string ExtraField2;
51 | public string ExtraField3;
52 | public string ExtraField4;
53 | public string BaseExtraField1;
54 | public string BaseExtraField2;
55 | public string BaseExtraField3;
56 | public string BaseExtraField4;
57 | }
58 |
59 | class BaseClassB
60 | {
61 | public string BaseField1;
62 | private string BaseField2;
63 | protected string BaseField3;
64 | internal string BaseField4;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/001_SuggestOuterMethodParameters.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | public static UserDTO Map(string firstName, string lastName, int age)
11 | {
12 | Map2([||]);
13 | }
14 |
15 | public static UserDTO Map2(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/002_SuggestOuterMethodParametersAndLocal.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | public static UserDTO Map(string firstName, string lastName, int age)
11 | {
12 | var parent = new UserDTO;
13 | Map2([||]);
14 | }
15 |
16 | public static UserDTO Map2(string firstName, string lastName, int age, UserDTO parent)
17 | {
18 |
19 | }
20 | }
21 |
22 | public class UserDTO
23 | {
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/003_SuggestOuterMethodParametersAndMembers.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | private readonly UserDTO parent = new UserDTO;
11 |
12 | public static UserDTO Map(string firstName, string lastName, int age)
13 | {
14 | Map2([||]);
15 | }
16 |
17 | public static UserDTO Map2(string firstName, string lastName, int age, UserDTO parent)
18 | {
19 |
20 | }
21 | }
22 |
23 | public class UserDTO
24 | {
25 |
26 | }
27 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/004_FallbackByTypeIfSingleCandidate.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | public static UserDTO Map(string firstName, string lastName, int age)
11 | {
12 | var firstParent = new UserDTO;
13 | Map2([||]);
14 | }
15 |
16 | public static UserDTO Map2(string firstName, string lastName, int age, UserDTO parent)
17 | {
18 |
19 | }
20 | }
21 |
22 | public class UserDTO
23 | {
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/005_FallbackByTypeIfSingleCandidateInterface.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | IUserDTO firstParent = new UserDTO;
11 |
12 | public static UserDTO Map(string firstName, string lastName, int age)
13 | {
14 | Map2([||]);
15 | }
16 |
17 | public static UserDTO Map2(string firstName, string lastName, int age, IUserDTO parent)
18 | {
19 |
20 | }
21 | }
22 |
23 | public interface IUserDTO {}
24 |
25 | public class UserDTO:IUserDTO
26 | {
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/006_FallbackByTypeIfSingleCandidateBaseClass.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | EntityDTO firstParent = new UserDTO;
11 |
12 | public static UserDTO Map(string firstName, string lastName, int age)
13 | {
14 | Map2([||]);
15 | }
16 |
17 | public static UserDTO Map2(string firstName, string lastName, int age, EntityDTO parent)
18 | {
19 |
20 | }
21 | }
22 |
23 | public class EntityDTO {}
24 |
25 | public class UserDTO:EntityDTO
26 | {
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/007_FallbackByTypeIfSingleCandidateInterfaceInheritance.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | UserDTO firstParent = new UserDTO;
11 |
12 | public static UserDTO Map(string firstName, string lastName, int age)
13 | {
14 | Map2([||]);
15 | }
16 |
17 | public static UserDTO Map2(string firstName, string lastName, int age, IUserDTO parent)
18 | {
19 |
20 | }
21 | }
22 |
23 | public interface IUserDTO {}
24 |
25 | public class UserDTO:IUserDTO
26 | {
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/008_FallbackByTypeIfSingleCandidateBaseClassInheritance.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 | UserDTO firstParent = new UserDTO;
11 |
12 | public static UserDTO Map(string firstName, string lastName, int age)
13 | {
14 | Map2([||]);
15 | }
16 |
17 | public static UserDTO Map2(string firstName, string lastName, int age, EntityDTO parent)
18 | {
19 |
20 | }
21 | }
22 |
23 | public class EntityDTO {}
24 |
25 | public class UserDTO:EntityDTO
26 | {
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/009_SuggestParamsForExtensionMethod.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 |
11 | public static UserDTO Map(string firstName, string lastName, int age)
12 | {
13 | var user = new UserDTO;
14 | user.Update([||]);
15 | return user;
16 | }
17 | }
18 |
19 | public class UserDTO
20 | {
21 |
22 | }
23 |
24 | public static class UserDTOExtensions
25 | {
26 | public static void Update(this UserDTO user, string firstName, string lastName, int age)
27 | {
28 |
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/010_SuggestParamsWithInterface.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Collections.ObjectModel;
5 |
6 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
7 | {
8 | public class TestMapper
9 | {
10 |
11 | public static UserDTO Map(string firstName, string lastName, IdentityProvider provider)
12 | {
13 | var user = new UserDTO;
14 | user.Update([||]);
15 | return user;
16 | }
17 | }
18 |
19 | public class UserDTO
20 | {
21 |
22 | }
23 |
24 | public abstract class AbstractIdentityProvider
25 | {
26 | void DoSomething()
27 | {
28 | }
29 | }
30 |
31 | public class IdentityProvider: AbstractIdentityProvider
32 | {
33 |
34 | }
35 |
36 | public static class UserDTOExtensions
37 | {
38 | public static void Update(this UserDTO user, string firstName, string lastName, AbstractIdentityProvider other)
39 | {
40 |
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/MethodParameterSuggestion/TestCaseData/011_SuggestParamsForGenericMethod.txt:
--------------------------------------------------------------------------------
1 |
2 | namespace MappingGenerator.Test.MappingGenerator.TestCaseData
3 | {
4 | public class TestMapper
5 | {
6 | public static void DoSomething()
7 | {
8 | UserEntity entity = new UserEntity();
9 | UserDTO dto = new UserDTO();
10 | UpdateUser([||]);
11 | }
12 |
13 | private static void UpdateUser(T1 entity, T2 dto)
14 | where T1 : UserEntity
15 | where T2 : class, IUserDTO
16 | {
17 |
18 | }
19 | }
20 |
21 | public interface IUserDTO { }
22 |
23 | public class UserDTO: IUserDTO
24 | {
25 |
26 | }
27 |
28 | public class UserEntity
29 | {
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/OnBuildGenerator/OnBuildGeneratorTest.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Immutable;
2 | using MappingGenerator.OnBuildGenerator;
3 | using NUnit.Framework;
4 | using SmartCodeGenerator.TestKit;
5 | using static MappingGenerator.Test.OnBuildGenerator.OnBuildGeneratorTestCases;
6 |
7 | namespace MappingGenerator.Test.OnBuildGenerator
8 | {
9 | public class OnBuildGeneratorTest
10 | {
11 | private const string IgnoreGeneratorVersionPattern = /*lang=regex*/ @"\d+\.\d+\.\d+\.\d+";
12 |
13 | [Test]
14 | public void should_be_able_to_generate_mapping_interface_implementation()
15 | {
16 | var generatorFixture = new SmartCodeGeneratorFixture(typeof(OnBuildMappingGenerator), new[]
17 | {
18 | ReferenceSource.FromType(),
19 | ReferenceSource.FromType(typeof(ImmutableArray<>)),
20 | });
21 |
22 |
23 | generatorFixture.AssertGeneratedCode(_001_SimpleMappingInterface, _001_SimpleMappingInterface_TRANSFORMED, IgnoreGeneratorVersionPattern);
24 | }
25 |
26 |
27 | [Test]
28 | public void should_be_able_to_generate_mapping_interface_implementation_using_custom_mappers()
29 | {
30 | var generatorFixture = new SmartCodeGeneratorFixture(typeof(OnBuildMappingGenerator), new[]
31 | {
32 | ReferenceSource.FromType()
33 | });
34 |
35 |
36 | generatorFixture.AssertGeneratedCode(_003_ExternalTypeMappers, _003_ExternalTypeMappers_TRANSFORMED, IgnoreGeneratorVersionPattern);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/SplattingTests.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Features.CodeFixes;
2 | using Microsoft.CodeAnalysis.CodeFixes;
3 | using MappingGenerator.Test.Splatting;
4 | using Microsoft.CodeAnalysis;
5 | using NUnit.Framework;
6 | using RoslynTestKit;
7 |
8 | namespace MappingGenerator.Test
9 | {
10 | public class SplattingTests : CodeFixTestFixture
11 | {
12 | [Test]
13 | public void should_be_able_to_generate_splatting_for_method_invocation_with_regular_parameters()
14 | {
15 | TestCodeFix(SplattingTestCases._001_SplattingInMethodInvocation, SplattingTestCases._001_SplattingInMethodInvocation_FIXED, SplattingCodeFixProvider.CS7036, 0);
16 | }
17 |
18 | [Test]
19 | public void should_be_able_to_generate_splatting_for_method_invocation_with_named_parameters()
20 | {
21 | TestCodeFix(SplattingTestCases._001_SplattingInMethodInvocation, SplattingTestCases._001_SplattingInMethodInvocationWithNamedParameters_FIXED, SplattingCodeFixProvider.CS7036, 1);
22 | }
23 |
24 | [Test]
25 | public void should_be_able_to_generate_splatting_for_constructor_invocation_with_regular_parameters()
26 | {
27 | TestCodeFix(SplattingTestCases._002_SplattingInConstructorInvocation, SplattingTestCases._002_SplattingInConstructorInvocation_FIXED, SplattingCodeFixProvider.CS7036, 0);
28 | }
29 |
30 | [Test]
31 | public void should_be_able_to_generate_splatting_for_constructor_invocation_with_named_parameters()
32 | {
33 | TestCodeFix(SplattingTestCases._002_SplattingInConstructorInvocation, SplattingTestCases._002_SplattingInConstructorInvocationWithNamedParameters_FIXED, SplattingCodeFixProvider.CS7036, 1);
34 | }
35 |
36 | [Test]
37 | public void should_be_able_to_generate_splatting_for_best_method_overload()
38 | {
39 | TestCodeFix(SplattingTestCases._003_SplattingWithBestOverloadMatch, SplattingTestCases._003_SplattingWithBestOverloadMatch_FIXED, SplattingCodeFixProvider.CS1501, 1);
40 | }
41 |
42 | protected override string LanguageName => LanguageNames.CSharp;
43 | protected override CodeFixProvider CreateProvider()
44 | {
45 | return new SplattingCodeFixProvider();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/001_SplattingInMethodInvocation.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | [|ProceessUser(user)|];
13 | }
14 |
15 | public void ProceessUser(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 |
22 | public class UserDTO
23 | {
24 | public string FirstName { get; set; }
25 | public string LastName { get; set; }
26 | public int Age { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/001_SplattingInMethodInvocationWithNamedParameters_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | ProceessUser(firstName: user.FirstName, lastName: user.LastName, age: user.Age);
13 | }
14 |
15 | public void ProceessUser(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 |
22 | public class UserDTO
23 | {
24 | public string FirstName { get; set; }
25 | public string LastName { get; set; }
26 | public int Age { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/001_SplattingInMethodInvocation_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | ProceessUser(user.FirstName, user.LastName, user.Age);
13 | }
14 |
15 | public void ProceessUser(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 |
22 | public class UserDTO
23 | {
24 | public string FirstName { get; set; }
25 | public string LastName { get; set; }
26 | public int Age { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/002_SplattingInConstructorInvocation.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | new [|SampleClass(user)|];
13 | }
14 | }
15 |
16 | public class SampleClass
17 | {
18 | public SampleClass(string firstName, string lastName, int age)
19 | {
20 |
21 | }
22 | }
23 |
24 |
25 | public class UserDTO
26 | {
27 | public string FirstName { get; set; }
28 | public string LastName { get; set; }
29 | public int Age { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/002_SplattingInConstructorInvocationWithNamedParameters_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | new SampleClass(firstName: user.FirstName, lastName: user.LastName, age: user.Age);
13 | }
14 | }
15 |
16 | public class SampleClass
17 | {
18 | public SampleClass(string firstName, string lastName, int age)
19 | {
20 |
21 | }
22 | }
23 |
24 |
25 | public class UserDTO
26 | {
27 | public string FirstName { get; set; }
28 | public string LastName { get; set; }
29 | public int Age { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/002_SplattingInConstructorInvocation_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | new SampleClass(user.FirstName, user.LastName, user.Age);
13 | }
14 | }
15 |
16 | public class SampleClass
17 | {
18 | public SampleClass(string firstName, string lastName, int age)
19 | {
20 |
21 | }
22 | }
23 |
24 |
25 | public class UserDTO
26 | {
27 | public string FirstName { get; set; }
28 | public string LastName { get; set; }
29 | public int Age { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/003_SplattingWithBestOverloadMatch.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | UserProcessor.[|ProceessUser(user)|];
13 | }
14 |
15 | public void ProceessUser(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 | public class UserProcessor
22 | {
23 | public void ProceessUser(string firstName, string lastName)
24 | {
25 |
26 | }
27 |
28 | public void ProceessUser(string firstName, string lastName, int age)
29 | {
30 |
31 | }
32 | }
33 |
34 |
35 | public class UserDTO
36 | {
37 | public string FirstName { get; set; }
38 | public string LastName { get; set; }
39 | public int Age { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/Splatting/TestCaseData/003_SplattingWithBestOverloadMatch_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.Splatting.TestCaseData
6 | {
7 | class TestMapper
8 | {
9 | public void DoSomething()
10 | {
11 | var user = new UserDTO;
12 | UserProcessor.ProceessUser(firstName: user.FirstName, lastName: user.LastName, age: user.Age);
13 | }
14 |
15 | public void ProceessUser(string firstName, string lastName, int age)
16 | {
17 |
18 | }
19 | }
20 |
21 | public class UserProcessor
22 | {
23 | public void ProceessUser(string firstName, string lastName)
24 | {
25 |
26 | }
27 |
28 | public void ProceessUser(string firstName, string lastName, int age)
29 | {
30 |
31 | }
32 | }
33 |
34 |
35 | public class UserDTO
36 | {
37 | public string FirstName { get; set; }
38 | public string LastName { get; set; }
39 | public int Age { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/001_SimpleLambda.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ConsoleApp9
4 | {
5 | public class User
6 | {
7 | public int Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Tenant { get; set; }
12 | }
13 |
14 | public class UserView
15 | {
16 | public int Id { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public string Tenant { get; set; }
21 | }
22 |
23 | public static class Examples
24 | {
25 | public static void Process(User user)
26 | {
27 | Update(userView => {[||]});
28 | }
29 |
30 | private static void Update(Action updateAction)
31 | {
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/001_SimpleLambda_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ConsoleApp9
4 | {
5 | public class User
6 | {
7 | public int Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Tenant { get; set; }
12 | }
13 |
14 | public class UserView
15 | {
16 | public int Id { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public string Tenant { get; set; }
21 | }
22 |
23 | public static class Examples
24 | {
25 | public static void Process(User user)
26 | {
27 | Update(userView =>
28 | {
29 | userView.Id = user.Id;
30 | userView.Name = user.Name;
31 | userView.Tenant = user.Tenant;
32 | });
33 | }
34 |
35 | private static void Update(Action updateAction)
36 | {
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/002_ParenthesisLambda.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ConsoleApp9
4 | {
5 | public class User
6 | {
7 | public int Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Tenant { get; set; }
12 | }
13 |
14 | public class UserView
15 | {
16 | public int Id { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public string Tenant { get; set; }
21 | }
22 |
23 | public static class Examples
24 | {
25 | public static void Process(User user)
26 | {
27 | Update((userView) => {[||]});
28 | }
29 |
30 | private static void Update(Action updateAction)
31 | {
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/002_ParenthesisLambda_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ConsoleApp9
4 | {
5 | public class User
6 | {
7 | public int Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Tenant { get; set; }
12 | }
13 |
14 | public class UserView
15 | {
16 | public int Id { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public string Tenant { get; set; }
21 | }
22 |
23 | public static class Examples
24 | {
25 | public static void Process(User user)
26 | {
27 | Update((userView) =>
28 | {
29 | userView.Id = user.Id;
30 | userView.Name = user.Name;
31 | userView.Tenant = user.Tenant;
32 | });
33 | }
34 |
35 | private static void Update(Action updateAction)
36 | {
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/003_GenericLambda.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ConsoleApp9
5 | {
6 | public class User
7 | {
8 | public int Id { get; set; }
9 |
10 | public string Name { get; set; }
11 |
12 | public string Tenant { get; set; }
13 | }
14 |
15 | public class UserView
16 | {
17 | public int Id { get; set; }
18 |
19 | public string Name { get; set; }
20 |
21 | public string Tenant { get; set; }
22 | }
23 |
24 | public static class Examples
25 | {
26 | public static void Process(User user)
27 | {
28 | var views = new List();
29 | Update(views, userView => {[||]});
30 | }
31 |
32 | private static void Update(List list, Action updateAction)
33 | {
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/TestCaseData/003_GenericLambda_FIXED.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ConsoleApp9
5 | {
6 | public class User
7 | {
8 | public int Id { get; set; }
9 |
10 | public string Name { get; set; }
11 |
12 | public string Tenant { get; set; }
13 | }
14 |
15 | public class UserView
16 | {
17 | public int Id { get; set; }
18 |
19 | public string Name { get; set; }
20 |
21 | public string Tenant { get; set; }
22 | }
23 |
24 | public static class Examples
25 | {
26 | public static void Process(User user)
27 | {
28 | var views = new List();
29 | Update(views, userView =>
30 | {
31 | userView.Id = user.Id;
32 | userView.Name = user.Name;
33 | userView.Tenant = user.Tenant;
34 | });
35 | }
36 |
37 | private static void Update(List list, Action updateAction)
38 | {
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UpdateLambdaParameter/UpdateLambdaParameterRefactoringTests.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Features.Refactorings;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CodeRefactorings;
4 | using NUnit.Framework;
5 | using RoslynTestKit;
6 | using static MappingGenerator.Test.UpdateLambdaParameter.UpdateLambdaParameterRefactoringTestCases;
7 |
8 | namespace MappingGenerator.Test.UpdateLambdaParameter
9 | {
10 | public class UpdateLambdaParameterRefactoringTests: CodeRefactoringTestFixture
11 | {
12 | protected override string LanguageName => LanguageNames.CSharp;
13 | protected override CodeRefactoringProvider CreateProvider() => new UpdateLambdaParameterRefactoring();
14 |
15 | [Test]
16 | public void should_be_able_to_update_simple_lambda_parameter()
17 | {
18 | TestCodeRefactoring(_001_SimpleLambda, _001_SimpleLambda_FIXED);
19 | }
20 |
21 | [Test]
22 | public void should_be_able_to_update_lambda_parameter_when_wrapped_in_parenthesis()
23 | {
24 | TestCodeRefactoring(_002_ParenthesisLambda, _002_ParenthesisLambda_FIXED);
25 | }
26 |
27 | [Test]
28 | public void should_be_able_to_update_generic_lambda_parameter()
29 | {
30 | TestCodeRefactoring(_003_GenericLambda, _003_GenericLambda_FIXED);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/001_UserLocaVariablesToCompleteMethodInvocation.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | [|DoSomethingElse()|];
14 | }
15 |
16 | public void DoSomethingElse(string firstName, string lastName, int age, decimal weight)
17 | {
18 |
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/001_UserLocaVariablesToCompleteMethodInvocationWithNamedParameters_Fixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | DoSomethingElse(firstName: firstName, lastName: lastName, age: age, weight: weight);
14 | }
15 |
16 | public void DoSomethingElse(string firstName, string lastName, int age, decimal weight)
17 | {
18 |
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/001_UserLocaVariablesToCompleteMethodInvocation_Fixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | DoSomethingElse(firstName, lastName, age, weight);
14 | }
15 |
16 | public void DoSomethingElse(string firstName, string lastName, int age, decimal weight)
17 | {
18 |
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/002_UserLocaVariablesToCompleteConstructorInvocation.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | new [|SampleClass()|];
14 | }
15 | }
16 |
17 | public class SampleClass
18 | {
19 | public SampleClass(string firstName, string lastName, int age, decimal weight)
20 | {
21 |
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/002_UserLocaVariablesToCompleteConstructorInvocationWithNamedParameters_Fixed .txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | new SampleClass(firstName: firstName, lastName: lastName, age: age, weight: weight);
14 | }
15 | }
16 |
17 | public class SampleClass
18 | {
19 | public SampleClass(string firstName, string lastName, int age, decimal weight)
20 | {
21 |
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/TestCaseData/002_UserLocaVariablesToCompleteConstructorInvocation_Fixed.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MappingGenerator.Test.UseLocalVariablesAsParameters.TestCaseData
6 | {
7 | public class SampleClass
8 | {
9 | public void DoSomething(string firstName, string lastName)
10 | {
11 | var age = 33;
12 | var weight = 80m;
13 | new SampleClass(firstName, lastName, age, weight);
14 | }
15 | }
16 |
17 | public class SampleClass
18 | {
19 | public SampleClass(string firstName, string lastName, int age, decimal weight)
20 | {
21 |
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Test/UseLocalVariablesAsParameters/UserLocalVariablesAsParametersTests.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Features.CodeFixes;
2 | using Microsoft.CodeAnalysis.CodeFixes;
3 | using MappingGenerator.Test.UseLocalVariablesAsParameters;
4 | using Microsoft.CodeAnalysis;
5 | using NUnit.Framework;
6 | using RoslynTestKit;
7 |
8 | namespace MappingGenerator.Test
9 | {
10 |
11 | public class UseLocalVariablesAsParameter : CodeFixTestFixture
12 | {
13 | [Test]
14 | public void should_be_able_to_complete_method_invocation_with_local_variables_as_regular_parameters()
15 | {
16 | TestCodeFix(UseLocalVariablesTestCases._001_UserLocaVariablesToCompleteMethodInvocation, UseLocalVariablesTestCases._001_UserLocaVariablesToCompleteMethodInvocation_Fixed, UseLocalVariablesAsParameterCodeFixProvider.CS7036, 0);
17 | }
18 |
19 | [Test]
20 | public void should_be_able_to_complete_method_invocation_with_local_variables_as_named_parameters()
21 | {
22 | TestCodeFix(UseLocalVariablesTestCases._001_UserLocaVariablesToCompleteMethodInvocation, UseLocalVariablesTestCases._001_UserLocaVariablesToCompleteMethodInvocationWithNamedParameters_Fixed, UseLocalVariablesAsParameterCodeFixProvider.CS7036, 1);
23 | }
24 |
25 | [Test]
26 | public void should_be_able_to_complete_constructor_invocation_with_local_variables_as_regular_parameters()
27 | {
28 | TestCodeFix(UseLocalVariablesTestCases._002_UserLocaVariablesToCompleteConstructorInvocation, UseLocalVariablesTestCases._002_UserLocaVariablesToCompleteConstructorInvocation_Fixed, SplattingCodeFixProvider.CS7036, 0);
29 | }
30 |
31 | [Test]
32 | public void should_be_able_to_complete_constructor_invocation_with_local_variables_as_named_parameters()
33 | {
34 | TestCodeFix(UseLocalVariablesTestCases._002_UserLocaVariablesToCompleteConstructorInvocation, UseLocalVariablesTestCases._002_UserLocaVariablesToCompleteConstructorInvocationWithNamedParameters_Fixed, SplattingCodeFixProvider.CS7036, 1);
35 | }
36 |
37 | protected override string LanguageName => LanguageNames.CSharp;
38 |
39 | protected override CodeFixProvider CreateProvider()
40 | {
41 | return new UseLocalVariablesAsParameterCodeFixProvider();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/icon.png
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/overview.md:
--------------------------------------------------------------------------------
1 | ## Description
2 | Extension that allows you to easily generate an implementation for mapping methods. This generator mimics well known AutoMapper. No more dull code typing. [Check the full list of features](https://github.com/cezarypiatek/MappingGenerator).
3 |
4 | ## Further Development
5 | If you find this extension useful (you feel it helps you on the daily basis) you can support further development by buying me a coffee (it's simple, just click the button below and follow further instructions). Sometimes it's hard to stay awake till midnight implementing new features, coffee helps me with that. I really appreciate your support in any form.
6 |
7 | [](https://www.buymeacoffee.com/tmAJLYvWy)
8 |
9 | 
10 |
11 |
12 | Release notes: [MappingGenerator releases](https://github.com/cezarypiatek/MappingGenerator/releases)
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/preview.png
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/publishManifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/vsix-publish",
3 | "categories": [
4 | "coding",
5 | "scaffolding"
6 | ],
7 | "identity": {
8 | "internalName": "mappinggenerator"
9 | },
10 | "overview": "overview.md",
11 | "priceCategory": "free",
12 | "publisher": "54748ff9-45fc-43c2-8ec5-cf7912bc3b84",
13 | "private": false,
14 | "qna": true,
15 | "repo": "https://github.com/cezarypiatek/MappingGenerator"
16 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MappingGenerator
6 | Roslyn based code fix provider that allows to generate mapping code in design time.
7 | preview.png
8 | preview.png
9 | automapper, code-generator, mapper, roslyn
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/MappingGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard1.3
5 | false
6 | True
7 | true
8 |
9 |
10 |
11 | MappingGenerator
12 | Cezary Piątek
13 | https://github.com/cezarypiatek/MappingGenerator/blob/master/LICENSE
14 | https://github.com/cezarypiatek/MappingGenerator
15 | https://github.com/cezarypiatek/MappingGenerator/raw/master/MappingGenerator/MappingGenerator/MappingGenerator.Vsix/icon.png
16 | https://github.com/cezarypiatek/MappingGenerator
17 | false
18 | "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
19 |
20 | Copyright
21 | MappingGenerator, analyzers
22 | true
23 | 8.0
24 |
25 |
26 |
27 |
28 |
29 | all
30 | runtime; build; native; contentfiles; analyzers; buildtransitive
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/AnnotatedType.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.Mappings.SourceFinders;
2 | using Microsoft.CodeAnalysis;
3 |
4 | namespace MappingGenerator.Mappings
5 | {
6 | public class AnnotatedType
7 | {
8 | public ITypeSymbol Type { get; }
9 | public bool CanBeNull { get; }
10 |
11 | public AnnotatedType(ITypeSymbol type)
12 | {
13 | Type = type;
14 | CanBeNull = type.CanBeNull();
15 | }
16 |
17 | public AnnotatedType(ITypeSymbol type, bool canBeNull)
18 | {
19 | Type = type;
20 | CanBeNull = canBeNull;
21 | }
22 |
23 | public AnnotatedType AsNotNull()
24 | {
25 | return new AnnotatedType(Type, false);
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/CustomConversionHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using MappingGenerator.RoslynHelpers;
4 | using Microsoft.CodeAnalysis;
5 |
6 | namespace MappingGenerator.Mappings
7 | {
8 | public static class CustomConversionHelper
9 | {
10 | public static IEnumerable FindCustomConversionMethods(IMethodSymbol methodSymbol)
11 | {
12 | var containingType = methodSymbol.ContainingType;
13 | return FindCustomConversionMethods(containingType);
14 | }
15 |
16 | public static IEnumerable FindCustomConversionMethods(INamedTypeSymbol containingType)
17 | {
18 | var userDefinedConversions = containingType.GetBaseTypesAndThis()
19 | .SelectMany(t => t.GetMembers().OfType().Where(IsConversionMethod));
20 | return userDefinedConversions;
21 | }
22 |
23 | private static bool IsConversionMethod(IMethodSymbol methodSymbol)
24 | {
25 | return methodSymbol.ReturnsVoid == false &&
26 | methodSymbol.Parameters.Length == 1 &&
27 | methodSymbol.Parameters[0] is {} parameter &&
28 | parameter.IsOptional == false &&
29 | parameter.RefKind == RefKind.None ;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingElement.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 |
4 | namespace MappingGenerator.Mappings
5 | {
6 | public class MappingElement
7 | {
8 | public ExpressionSyntax Expression { get; set; }
9 | public AnnotatedType ExpressionType { get; set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/FallbackMappingImplementor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.CodeAnalysis;
6 | using Microsoft.CodeAnalysis.Editing;
7 |
8 | namespace MappingGenerator.Mappings.MappingImplementors
9 | {
10 | class FallbackMappingImplementor : IMappingMethodImplementor
11 | {
12 | private readonly IMappingMethodImplementor[] implementors;
13 |
14 | public FallbackMappingImplementor(params IMappingMethodImplementor[] implementors)
15 | {
16 | this.implementors = implementors;
17 | }
18 |
19 | public bool CanImplement(IMethodSymbol methodSymbol)
20 | {
21 | return implementors.Any(x => x.CanImplement(methodSymbol));
22 | }
23 |
24 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
25 | SemanticModel semanticModel, MappingContext mappingContext)
26 | {
27 | foreach (var implementor in implementors)
28 | {
29 | var result = await implementor.GenerateImplementation(methodSymbol, generator, semanticModel, mappingContext).ConfigureAwait(false);
30 | if (result.Count > 0)
31 | {
32 | return result;
33 | }
34 | }
35 |
36 | return Array.Empty();
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/IMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using Microsoft.CodeAnalysis;
4 | using Microsoft.CodeAnalysis.Editing;
5 |
6 | namespace MappingGenerator.Mappings.MappingImplementors
7 | {
8 | public interface IMappingMethodImplementor
9 | {
10 | bool CanImplement(IMethodSymbol methodSymbol);
11 |
12 | Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel, MappingContext mappingContext);
13 | }
14 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/IdentityMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.SourceFinders;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.CSharp.Syntax;
6 | using Microsoft.CodeAnalysis.Editing;
7 | using Microsoft.CodeAnalysis.Formatting;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | internal class IdentityMappingMethodImplementor: IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | return methodSymbol.Parameters.Length == 1 && methodSymbol.ReturnType.Equals(methodSymbol.Parameters[0].Type);
16 | }
17 |
18 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel, MappingContext mappingContext)
19 | {
20 | var cloneMappingEngine = new CloneMappingEngine(semanticModel, generator);
21 | var sourceParameter = methodSymbol.Parameters[0];
22 | var sourceType = new AnnotatedType(sourceParameter.Type);
23 | var targetType = new AnnotatedType(methodSymbol.ReturnType);
24 | var newExpression = await cloneMappingEngine.MapExpression((ExpressionSyntax)generator.IdentifierName(sourceParameter.Name), sourceType, targetType, mappingContext).ConfigureAwait(false);
25 | return new[] { generator.ReturnStatement(newExpression).WithAdditionalAnnotations(Formatter.Annotation) };
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/MultiParameterMappingConstructorImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.Editing;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | class MultiParameterMappingConstructorImplementor:IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | return methodSymbol.Parameters.Length > 1 && SymbolHelper.IsConstructor(methodSymbol);
16 | }
17 |
18 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
19 | SemanticModel semanticModel, MappingContext mappingContext)
20 | {
21 | var mappingEngine = new MappingEngine(semanticModel, generator);
22 | var sourceFinder = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol.Parameters);
23 | var mappingTargetHelper = new MappingTargetHelper();
24 | var targets = mappingTargetHelper.GetFieldsThaCanBeSetFromConstructor(methodSymbol.ContainingType, mappingContext);
25 | return await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext).ConfigureAwait(false);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/MultiParameterPureMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using Microsoft.CodeAnalysis;
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 | using Microsoft.CodeAnalysis.Editing;
8 | using Microsoft.CodeAnalysis.Formatting;
9 |
10 | namespace MappingGenerator.Mappings.MappingImplementors
11 | {
12 | class MultiParameterPureMappingMethodImplementor: IMappingMethodImplementor
13 | {
14 | public bool CanImplement(IMethodSymbol methodSymbol)
15 | {
16 | return methodSymbol.Parameters.Length > 1 && methodSymbol.ReturnsVoid == false;
17 | }
18 |
19 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
20 | SemanticModel semanticModel, MappingContext mappingContext)
21 | {
22 | var mappingEngine = new MappingEngine(semanticModel, generator);
23 | var targetType = methodSymbol.ReturnType;
24 | var sourceFinder = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol);
25 | var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)generator.ObjectCreationExpression(targetType.StripNullability());
26 | var newExpression = await mappingEngine.AddInitializerWithMappingAsync(objectCreationExpressionSyntax, new SingleSourceMatcher(sourceFinder), targetType, mappingContext).ConfigureAwait(false);
27 | return new[] { generator.ReturnStatement(newExpression).WithAdditionalAnnotations(Formatter.Annotation) };
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/SingleParameterMappingConstructorImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.Editing;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | class SingleParameterMappingConstructorImplementor:IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | return methodSymbol.Parameters.Length == 1 && SymbolHelper.IsConstructor(methodSymbol);
16 | }
17 |
18 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
19 | SemanticModel semanticModel, MappingContext mappingContext)
20 | {
21 | var mappingEngine = new MappingEngine(semanticModel, generator);
22 | var sourceParameter = methodSymbol.Parameters[0];
23 | var sourceFinder = new ObjectMembersMappingSourceFinder(new AnnotatedType(sourceParameter.Type), generator.IdentifierName(sourceParameter.Name));
24 | var mappingTargetHelper = new MappingTargetHelper();
25 | var targets = mappingTargetHelper.GetFieldsThaCanBeSetFromConstructor(methodSymbol.ContainingType, mappingContext);
26 | return await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext).ConfigureAwait(false);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/SingleParameterPureMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.SourceFinders;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.CSharp.Syntax;
6 | using Microsoft.CodeAnalysis.Editing;
7 | using Microsoft.CodeAnalysis.Formatting;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | internal class SingleParameterPureMappingMethodImplementor: IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | return methodSymbol.Parameters.Length == 1 && methodSymbol.ReturnsVoid == false;
16 | }
17 |
18 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
19 | SemanticModel semanticModel, MappingContext mappingContext)
20 | {
21 | var mappingEngine = new MappingEngine(semanticModel, generator);
22 | var source = methodSymbol.Parameters[0];
23 | var sourceType = new AnnotatedType(source.Type);
24 | var targetType = new AnnotatedType(methodSymbol.ReturnType);
25 | var newExpression = await mappingEngine.MapExpression((ExpressionSyntax)generator.IdentifierName(source.Name), sourceType, targetType, mappingContext).ConfigureAwait(false);
26 | return new[] { generator.ReturnStatement(newExpression).WithAdditionalAnnotations(Formatter.Annotation) };
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/ThisObjectToOtherMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.SourceFinders;
4 | using MappingGenerator.RoslynHelpers;
5 | using Microsoft.CodeAnalysis;
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 | using Microsoft.CodeAnalysis.Editing;
8 | using Microsoft.CodeAnalysis.Formatting;
9 |
10 | namespace MappingGenerator.Mappings.MappingImplementors
11 | {
12 | class ThisObjectToOtherMappingMethodImplementor:IMappingMethodImplementor
13 | {
14 | public bool CanImplement(IMethodSymbol methodSymbol)
15 | {
16 | return methodSymbol.IsStatic == false &&
17 | methodSymbol.Parameters.Length == 0 &&
18 | methodSymbol.ReturnsVoid == false &&
19 | ObjectHelper.IsSimpleType(methodSymbol.ReturnType) == false;
20 | }
21 |
22 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
23 | SemanticModel semanticModel, MappingContext mappingContext)
24 | {
25 | var mappingEngine = new MappingEngine(semanticModel, generator);
26 | var destinationType = new AnnotatedType(methodSymbol.ReturnType);
27 | var sourceType = new AnnotatedType(methodSymbol.ContainingType);
28 | var newExpression = await mappingEngine.MapExpression((ExpressionSyntax)generator.ThisExpression(), sourceType, destinationType, mappingContext).ConfigureAwait(false);
29 | return new[] { generator.ReturnStatement(newExpression).WithAdditionalAnnotations(Formatter.Annotation) };
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/UpdateSecondParameterMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.Editing;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | class UpdateSecondParameterMappingMethodImplementor:IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | if (SymbolHelper.IsConstructor(methodSymbol))
16 | {
17 | return false;
18 | }
19 | return methodSymbol.Parameters.Length == 2 && methodSymbol.ReturnsVoid;
20 | }
21 |
22 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
23 | SemanticModel semanticModel, MappingContext mappingContext)
24 | {
25 | var mappingEngine = new MappingEngine(semanticModel, generator);
26 | var source = methodSymbol.Parameters[0];
27 | var target = methodSymbol.Parameters[1];
28 | var mappingTargetHelper = new MappingTargetHelper();
29 | var targets = mappingTargetHelper.GetFieldsThaCanBeSetPublicly(target.Type, mappingContext);
30 | var sourceFinder = new ObjectMembersMappingSourceFinder(new AnnotatedType(source.Type), generator.IdentifierName(source.Name));
31 | return await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext, globalTargetAccessor: generator.IdentifierName(target.Name)).ConfigureAwait(false);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/UpdateThisObjectMultiParameterMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.Editing;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | class UpdateThisObjectMultiParameterMappingMethodImplementor:IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | if (SymbolHelper.IsConstructor(methodSymbol))
16 | {
17 | return false;
18 | }
19 | return methodSymbol.Parameters.Length > 1 && methodSymbol.ReturnsVoid;
20 | }
21 |
22 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
23 | SemanticModel semanticModel, MappingContext mappingContext)
24 | {
25 | var mappingEngine = new MappingEngine(semanticModel, generator);
26 | var sourceFinder = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol.Parameters);
27 | var mappingTargetHelper = new MappingTargetHelper();
28 | var targets = mappingTargetHelper.GetFieldsThaCanBeSetPrivately(methodSymbol.ContainingType, mappingContext);
29 | return await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext).ConfigureAwait(false);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingImplementors/UpdateThisObjectSingleParameterMappingMethodImplementor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.Mappings.MappingMatchers;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.Editing;
8 |
9 | namespace MappingGenerator.Mappings.MappingImplementors
10 | {
11 | class UpdateThisObjectSingleParameterMappingMethodImplementor:IMappingMethodImplementor
12 | {
13 | public bool CanImplement(IMethodSymbol methodSymbol)
14 | {
15 | if (SymbolHelper.IsConstructor(methodSymbol))
16 | {
17 | return false;
18 | }
19 | return methodSymbol.Parameters.Length == 1 && methodSymbol.ReturnsVoid;
20 | }
21 |
22 | public async Task> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
23 | SemanticModel semanticModel, MappingContext mappingContext)
24 | {
25 | var mappingEngine = new MappingEngine(semanticModel, generator);
26 | var source = methodSymbol.Parameters[0];
27 | var sourceFinder = new ObjectMembersMappingSourceFinder(new AnnotatedType(source.Type), generator.IdentifierName(source.Name));
28 | var mappingTargetHelper = new MappingTargetHelper();
29 | var targets = mappingTargetHelper.GetFieldsThaCanBeSetPrivately(methodSymbol.ContainingType, mappingContext);
30 | return await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext).ConfigureAwait(false);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingMatchers/BestPossibleMatcher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using MappingGenerator.Mappings.SourceFinders;
6 | using MappingGenerator.RoslynHelpers;
7 | using Microsoft.CodeAnalysis;
8 | using Microsoft.CodeAnalysis.Editing;
9 |
10 | namespace MappingGenerator.Mappings.MappingMatchers
11 | {
12 | class BestPossibleMatcher : IMappingMatcher
13 | {
14 | private readonly IReadOnlyList matchers;
15 |
16 | public BestPossibleMatcher(IReadOnlyList sourceFinders)
17 | {
18 | matchers = sourceFinders.Select(x => new SingleSourceMatcher(x)).ToList();
19 | }
20 |
21 | public async Task> MatchAll(IReadOnlyCollection targets,
22 | SyntaxGenerator syntaxGenerator, MappingContext mappingContext, SyntaxNode globalTargetAccessor = null)
23 | {
24 | var matchedSets = await GetMatchedSets(targets, syntaxGenerator, mappingContext, globalTargetAccessor).ConfigureAwait(false);
25 | return matchedSets.OrderByDescending(x => x.Count).FirstOrDefault() ?? Array.Empty();
26 | }
27 |
28 | private async Task>> GetMatchedSets(IReadOnlyCollection targets, SyntaxGenerator syntaxGenerator, MappingContext mappingContext, SyntaxNode globalTargetAccessor)
29 | {
30 | var results = new List>();
31 | foreach (var x in matchers)
32 | {
33 | var matches = await x.MatchAll(targets, syntaxGenerator, mappingContext, globalTargetAccessor).ConfigureAwait(false);
34 | results.Add(matches);
35 | if (matches.Count == targets.Count)
36 | {
37 | break;
38 | }
39 | }
40 |
41 | return results;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingMatchers/IMappingMatcher.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using MappingGenerator.RoslynHelpers;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.Editing;
6 |
7 | namespace MappingGenerator.Mappings.MappingMatchers
8 | {
9 | public interface IMappingMatcher
10 | {
11 | Task> MatchAll(IReadOnlyCollection targets, SyntaxGenerator syntaxGenerator,
12 | MappingContext mappingContext, SyntaxNode globalTargetAccessor = null);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingMatchers/MappingMatch.cs:
--------------------------------------------------------------------------------
1 | namespace MappingGenerator.Mappings.MappingMatchers
2 | {
3 | public class MappingMatch
4 | {
5 | public MappingElement Source { get; set; }
6 | public MappingElement Target { get; set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingMatchers/SingleSourceMatcher.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Threading.Tasks;
4 | using MappingGenerator.Mappings.SourceFinders;
5 | using MappingGenerator.RoslynHelpers;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.CSharp;
8 | using Microsoft.CodeAnalysis.CSharp.Syntax;
9 | using Microsoft.CodeAnalysis.Editing;
10 |
11 | namespace MappingGenerator.Mappings.MappingMatchers
12 | {
13 | class SingleSourceMatcher : IMappingMatcher
14 | {
15 | private readonly IMappingSourceFinder sourceFinder;
16 |
17 | public SingleSourceMatcher(IMappingSourceFinder sourceFinder)
18 | {
19 | this.sourceFinder = sourceFinder;
20 | }
21 |
22 | public async Task> MatchAll(IReadOnlyCollection targets, SyntaxGenerator syntaxGenerator, MappingContext mappingContext, SyntaxNode globalTargetAccessor = null)
23 | {
24 |
25 | var results = new List(targets.Count);
26 | foreach (var target in targets)
27 | {
28 | results.Add(new MappingMatch
29 | {
30 | Source = await sourceFinder.FindMappingSource(target.Name, target.Type, mappingContext).ConfigureAwait(false),
31 | Target = CreateTargetElement(globalTargetAccessor, target, syntaxGenerator)
32 | });
33 | }
34 |
35 | return results.Where(x => x.Source != null).ToList();
36 | }
37 |
38 | private MappingElement CreateTargetElement(SyntaxNode globalTargetAccessor, IObjectField target, SyntaxGenerator syntaxGenerator)
39 | {
40 | return new MappingElement
41 | {
42 | Expression = (ExpressionSyntax)CreateAccessPropertyExpression(globalTargetAccessor, target, syntaxGenerator),
43 | ExpressionType = target.Type
44 | };
45 | }
46 |
47 | private static SyntaxNode CreateAccessPropertyExpression(SyntaxNode globalTargetAccessor, IObjectField property, SyntaxGenerator generator)
48 | {
49 | if (globalTargetAccessor == null)
50 | {
51 | return SyntaxFactory.IdentifierName(property.Name);
52 | }
53 | return generator.MemberAccessExpression(globalTargetAccessor, property.Name);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/MappingType.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.CodeAnalysis;
3 |
4 | namespace MappingGenerator.Mappings
5 | {
6 | public class MappingType
7 | {
8 | public ITypeSymbol FromType { get; set; }
9 | public ITypeSymbol ToType { get; set; }
10 |
11 | public override bool Equals(object obj)
12 | {
13 | return obj is MappingType type &&
14 | EqualityComparer.Default.Equals(FromType, type.FromType) &&
15 | EqualityComparer.Default.Equals(ToType, type.ToType);
16 | }
17 |
18 | public override int GetHashCode()
19 | {
20 | int hashCode = 1267219665;
21 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(FromType);
22 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ToType);
23 | return hashCode;
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/NameHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Microsoft.CodeAnalysis;
4 | using Pluralize.NET;
5 |
6 | namespace MappingGenerator.Mappings
7 | {
8 | public static class NameHelper
9 | {
10 | private static readonly char[] ForbiddenSigns = new[] {'.', '[', ']', '(', ')','?','!'};
11 | private static readonly Pluralizer Pluralizer = new Pluralizer();
12 |
13 | public static string CreateLambdaParameterName(SyntaxNode sourceList)
14 | {
15 | var originalName = sourceList.ToFullString();
16 | var localVariableName = ToLocalVariableName(originalName);
17 | var finalName = ToSingularLocalVariableName(localVariableName);
18 | if (originalName == finalName)
19 | {
20 | return $"{finalName}Element";
21 | }
22 | return finalName;
23 | }
24 |
25 | public static string ToLocalVariableName(string proposalLocalName)
26 | {
27 | var nameParts = proposalLocalName.Replace("@","").Trim().Split(ForbiddenSigns).Where(x=> string.IsNullOrWhiteSpace(x) == false).Select(x=>
28 | {
29 | var cleanElement = x.Trim();
30 | return $"{cleanElement.Substring(0, 1).ToUpper()}{cleanElement.Substring(1)}";
31 | });
32 | var withoutForbiddenSigns = string.Join("",nameParts);
33 | return $"{withoutForbiddenSigns.Substring(0, 1).ToLower()}{withoutForbiddenSigns.Substring(1)}";
34 | }
35 |
36 | private static readonly string[] CollectionSynonyms = new[] {"List", "Collection", "Set", "Queue", "Dictionary", "Stack", "Array"};
37 |
38 | private static string ToSingularLocalVariableName(string proposalLocalName)
39 | {
40 | if (CollectionSynonyms.Any(x=> x.Equals(proposalLocalName, StringComparison.OrdinalIgnoreCase)))
41 | {
42 | return "item";
43 | }
44 |
45 | foreach (var collectionName in CollectionSynonyms)
46 | {
47 | if (proposalLocalName.EndsWith(collectionName, StringComparison.OrdinalIgnoreCase))
48 | {
49 | proposalLocalName = proposalLocalName.Substring(0, proposalLocalName.Length - collectionName.Length);
50 | break;
51 | }
52 | }
53 |
54 | if (IsPluralForm(proposalLocalName))
55 | {
56 | return Pluralizer.Singularize(proposalLocalName);
57 | }
58 |
59 | return proposalLocalName;
60 | }
61 |
62 | private static bool IsPluralForm(string proposalLocalName)
63 | {
64 | return string.Equals(Pluralizer.Pluralize(proposalLocalName), proposalLocalName, StringComparison.OrdinalIgnoreCase);
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/SourceFinders/IgnorableMappingSourceFinder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.CodeAnalysis;
4 |
5 | namespace MappingGenerator.Mappings.SourceFinders
6 | {
7 | public class IgnorableMappingSourceFinder:IMappingSourceFinder
8 | {
9 | private readonly IMappingSourceFinder wrappedFinder;
10 | private readonly Func ignore;
11 |
12 | public IgnorableMappingSourceFinder(IMappingSourceFinder wrappedFinder, Func ignore)
13 | {
14 | this.wrappedFinder = wrappedFinder;
15 | this.ignore = ignore;
16 | }
17 |
18 | public async Task FindMappingSource(string targetName, AnnotatedType targetType, MappingContext mappingContext)
19 | {
20 | var mapping = await wrappedFinder.FindMappingSource(targetName, targetType, mappingContext).ConfigureAwait(false);
21 | return mapping == null || ignore(mapping) ? null : mapping;
22 | }
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/SourceFinders/OrderedSourceFinder.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace MappingGenerator.Mappings.SourceFinders
5 | {
6 | class OrderedSourceFinder : IMappingSourceFinder
7 | {
8 | private readonly IReadOnlyList sourceFinders;
9 |
10 | public OrderedSourceFinder(IReadOnlyList sourceFinders)
11 | {
12 | this.sourceFinders = sourceFinders;
13 | }
14 |
15 | public async Task FindMappingSource(string targetName, AnnotatedType targetType, MappingContext mappingContext)
16 | {
17 | foreach (var sourceFinder in sourceFinders)
18 | {
19 | var mappingElement = await sourceFinder.FindMappingSource(targetName, targetType, mappingContext).ConfigureAwait(false);
20 | if (mappingElement != null)
21 | {
22 | return mappingElement;
23 | }
24 | }
25 |
26 | return null;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/Mappings/WrapperInfo.cs:
--------------------------------------------------------------------------------
1 | using MappingGenerator.RoslynHelpers;
2 | using Microsoft.CodeAnalysis;
3 |
4 | namespace MappingGenerator.Mappings
5 | {
6 | class WrapperInfo
7 | {
8 | public WrapperInfoType Type { get;}
9 | public IObjectField UnwrappingObjectField { get; }
10 | public IMethodSymbol UnwrappingMethod { get; }
11 |
12 | public WrapperInfo()
13 | {
14 | Type = WrapperInfoType.No;
15 | }
16 |
17 | public WrapperInfo(IObjectField unwrappingObjectField)
18 | {
19 | UnwrappingObjectField = unwrappingObjectField;
20 | Type = WrapperInfoType.ObjectField;
21 | }
22 |
23 | public WrapperInfo(IMethodSymbol unwrappingMethod)
24 | {
25 | UnwrappingMethod = unwrappingMethod;
26 | Type = WrapperInfoType.Method;
27 | }
28 | }
29 |
30 | enum WrapperInfoType
31 | {
32 | No,
33 | ObjectField,
34 | Method
35 | }
36 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/MethodHelpers/ConstructorInvocation.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Collections.Immutable;
3 | using System.Linq;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.CSharp.Syntax;
6 |
7 | namespace MappingGenerator.MethodHelpers
8 | {
9 | public class ConstructorInvocation:IInvocation
10 | {
11 | private readonly ObjectCreationExpressionSyntax creationExpression;
12 |
13 | public ConstructorInvocation(ObjectCreationExpressionSyntax creationExpression)
14 | {
15 | this.creationExpression = creationExpression;
16 | }
17 |
18 | public IEnumerable> GetOverloadParameterSets(SemanticModel semanticModel)
19 | {
20 | var symbolInfo = semanticModel.GetSymbolInfo(creationExpression.Type);
21 | if (symbolInfo.Symbol is INamedTypeSymbol instantiatedType)
22 | {
23 | return instantiatedType.Constructors.Select(x => x.Parameters);
24 | }
25 | return null;
26 | }
27 |
28 | public SyntaxNode WithArgumentList(ArgumentListSyntax argumentListSyntax)
29 | {
30 | return creationExpression.WithArgumentList(argumentListSyntax);
31 | }
32 |
33 | public SyntaxNode SourceNode => creationExpression;
34 | public ArgumentListSyntax Arguments => creationExpression.ArgumentList;
35 | }
36 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/MethodHelpers/IInvocation.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Collections.Immutable;
3 | using Microsoft.CodeAnalysis;
4 | using Microsoft.CodeAnalysis.CSharp.Syntax;
5 |
6 | namespace MappingGenerator.MethodHelpers
7 | {
8 | public interface IInvocation
9 | {
10 | IEnumerable> GetOverloadParameterSets(SemanticModel semanticModel);
11 | SyntaxNode WithArgumentList(ArgumentListSyntax argumentListSyntax);
12 | SyntaxNode SourceNode { get; }
13 | ArgumentListSyntax Arguments { get; }
14 | }
15 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/MethodHelpers/MethodInvocation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.Immutable;
4 | using System.Linq;
5 | using System.Text;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.CSharp.Syntax;
8 |
9 | namespace MappingGenerator.MethodHelpers
10 | {
11 | public class MethodInvocation:IInvocation
12 | {
13 | private readonly InvocationExpressionSyntax invocationExpression;
14 |
15 | public MethodInvocation(InvocationExpressionSyntax invocationExpression)
16 | {
17 | this.invocationExpression = invocationExpression;
18 | }
19 |
20 | public IEnumerable> GetOverloadParameterSets(SemanticModel semanticModel)
21 | {
22 | var methodSymbol = GetMethodOverloads(semanticModel, out var methodOverloads);
23 | if (methodOverloads == null)
24 | {
25 | return null;
26 | }
27 |
28 |
29 | if (methodSymbol.IsExtensionMethod && invocationExpression.Expression is MemberAccessExpressionSyntax)
30 | {
31 | return methodOverloads.Where( x=> x.IsExtensionMethod).Select(x => x.Parameters.Skip(1).ToImmutableArray()).ToList();
32 | }
33 |
34 | return methodOverloads.Select(x => x.Parameters).ToList();
35 | }
36 |
37 | private IMethodSymbol GetMethodOverloads(SemanticModel semanticModel, out IEnumerable methodOverloads)
38 | {
39 | var methodSymbol = semanticModel.GetSymbolInfo(invocationExpression).CandidateSymbols.OfType()
40 | .FirstOrDefault();
41 | methodOverloads = methodSymbol?.ContainingType.GetMembers(methodSymbol.Name).OfType();
42 | return methodSymbol;
43 | }
44 |
45 | public SyntaxNode WithArgumentList(ArgumentListSyntax argumentListSyntax)
46 | {
47 | return invocationExpression.WithArgumentList(argumentListSyntax);
48 | }
49 |
50 | public SyntaxNode SourceNode => invocationExpression;
51 | public ArgumentListSyntax Arguments => invocationExpression.ArgumentList;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/MethodHelpers/SuggestionHelpers.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CSharp;
4 | using Microsoft.CodeAnalysis.CSharp.Syntax;
5 |
6 | namespace MappingGenerator.MethodHelpers
7 | {
8 | internal class SuggestionHelpers
9 | {
10 |
11 | internal static SyntaxToken GetCurrentArgumentListSyntaxToken(SyntaxNode node, int currentPosition)
12 | {
13 | var allArgumentLists = node.DescendantNodes(n => n.FullSpan.Contains(currentPosition - 1)).OfType().OrderBy(n => n.FullSpan.Length);
14 | return allArgumentLists.SelectMany(n => n.ChildTokens()
15 | .Where(t => t.IsKind(SyntaxKind.OpenParenToken) || t.IsKind(SyntaxKind.CommaToken))
16 | .Where(t => t.FullSpan.Contains(currentPosition - 1))).FirstOrDefault();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/MappingTargetHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using MappingGenerator.Mappings;
4 | using Microsoft.CodeAnalysis;
5 |
6 | namespace MappingGenerator.RoslynHelpers
7 | {
8 | public class MappingTargetHelper
9 | {
10 | private static readonly NameEqualityComparer nameEqualityComparer = new NameEqualityComparer();
11 | public IReadOnlyCollection GetFieldsThaCanBeSetFromConstructor(ITypeSymbol type, MappingContext mappingContext)
12 | {
13 | return GetObjectFields(type).Where(x=>x.CanBeSetInConstructor(type, mappingContext)).Distinct(nameEqualityComparer).ToList();
14 | }
15 |
16 | public IReadOnlyCollection GetFieldsThaCanBeSetPublicly(ITypeSymbol type,
17 | MappingContext mappingContext)
18 | {
19 | return GetObjectFields(type).Where(x => x.CanBeSet(type, mappingContext)).Distinct(nameEqualityComparer).ToList();
20 | }
21 |
22 | public IReadOnlyCollection GetFieldsThaCanBeSetPrivately(ITypeSymbol type, MappingContext mappingContext)
23 | {
24 | return GetObjectFields(type).Where(x => x.CanBeSet(type, mappingContext)).Distinct(nameEqualityComparer).ToList();
25 | }
26 |
27 | private readonly Dictionary> fieldsCache = new Dictionary>();
28 | private IReadOnlyList GetObjectFields(ITypeSymbol type)
29 | {
30 | if (fieldsCache.TryGetValue(type, out var fields))
31 | {
32 | return fields;
33 | }
34 |
35 | var freshFields = type.GetObjectFields().ToList();
36 | fieldsCache[type] = freshFields;
37 | return freshFields;
38 | }
39 |
40 |
41 | class NameEqualityComparer : IEqualityComparer
42 | {
43 | public bool Equals(IObjectField x, IObjectField y) => x?.Name == y?.Name;
44 |
45 | public int GetHashCode(IObjectField obj) => obj.Name.GetHashCode();
46 | }
47 |
48 | }
49 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/ObjectField.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using MappingGenerator.Mappings;
3 | using MappingGenerator.Mappings.SourceFinders;
4 | using Microsoft.CodeAnalysis;
5 |
6 | namespace MappingGenerator.RoslynHelpers
7 | {
8 | public class ObjectField : IObjectField
9 | {
10 | private readonly IFieldSymbol fieldSymbol;
11 |
12 | public ObjectField(IFieldSymbol fieldSymbol)
13 | {
14 | this.fieldSymbol = fieldSymbol;
15 | this.Type = new AnnotatedType(fieldSymbol.Type);
16 | }
17 |
18 | public string Name => fieldSymbol.Name;
19 |
20 | public AnnotatedType Type { get; }
21 |
22 | public bool CanBeSet(ITypeSymbol via, MappingContext mappingContext)
23 | {
24 | if (fieldSymbol.IsReadOnly)
25 | {
26 | return false;
27 | }
28 |
29 | return mappingContext.AccessibilityHelper.IsSymbolAccessible(fieldSymbol, via);
30 |
31 | }
32 |
33 | public bool CanBeSetInConstructor(ITypeSymbol via, MappingContext mappingContext)
34 | {
35 | return mappingContext.AccessibilityHelper.IsSymbolAccessible(fieldSymbol, via);
36 | }
37 |
38 | public bool CanBeGet(ITypeSymbol via, MappingContext mappingContext)
39 | {
40 | return mappingContext.AccessibilityHelper.IsSymbolAccessible(fieldSymbol, via);
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/ObjectFieldExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Microsoft.CodeAnalysis;
4 |
5 | namespace MappingGenerator.RoslynHelpers
6 | {
7 | public static class ObjectFieldExtensions
8 | {
9 | public static IEnumerable GetObjectFields(this ITypeSymbol type)
10 | {
11 | var allMembers = type.GetAllMembers();
12 | foreach (var objectField in GetObjectFields(allMembers))
13 | yield return objectField;
14 | }
15 |
16 | public static IEnumerable GetObjectFields(IEnumerable allMembers)
17 | {
18 | foreach (var symbol in allMembers)
19 | {
20 | if (symbol.IsStatic)
21 | {
22 | continue;
23 | }
24 |
25 | if (symbol is IPropertySymbol property)
26 | {
27 | if (property.IsIndexer == false)
28 | {
29 | yield return new ObjectProperty(property);
30 | }
31 |
32 | continue;
33 | }
34 |
35 | if (symbol is IFieldSymbol fieldSymbol)
36 | {
37 | if (fieldSymbol.IsImplicitlyDeclared == false)
38 | {
39 | yield return new ObjectField(fieldSymbol);
40 | }
41 | }
42 | }
43 | }
44 |
45 |
46 | }
47 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/SymbolHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.CSharp;
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace MappingGenerator.RoslynHelpers
9 | {
10 | internal static class SymbolHelper
11 | {
12 | public static bool IsConstructor(IMethodSymbol methodSymbol)
13 | {
14 | return methodSymbol.MethodKind == MethodKind.Constructor;
15 | }
16 |
17 | public static IEnumerable UnwrapGeneric(this ITypeSymbol typeSymbol)
18 | {
19 | if (typeSymbol.TypeKind == TypeKind.TypeParameter && typeSymbol is ITypeParameterSymbol namedType && namedType.Kind != SymbolKind.ErrorType)
20 | {
21 | return namedType.ConstraintTypes;
22 | }
23 | return new []{typeSymbol};
24 | }
25 |
26 | public static bool IsDeclaredOutsideTheSourcecode(IPropertySymbol property)
27 | {
28 | return property.DeclaringSyntaxReferences.Length == 0;
29 | }
30 |
31 | public static bool IsNullable(ITypeSymbol type, out ITypeSymbol underlyingType)
32 | {
33 | if (type.TypeKind == TypeKind.Struct && type.Name == "Nullable")
34 | {
35 | underlyingType = GetUnderlyingNullableType(type);
36 | return true;
37 | }
38 |
39 | underlyingType = null;
40 | return false;
41 | }
42 |
43 | public static ITypeSymbol GetUnderlyingNullableType(ITypeSymbol type)
44 | {
45 | return ((INamedTypeSymbol) type).TypeArguments.First();
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/SyntaxGeneratorExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using Microsoft.CodeAnalysis;
4 | using Microsoft.CodeAnalysis.CSharp;
5 | using Microsoft.CodeAnalysis.CSharp.Syntax;
6 | using Microsoft.CodeAnalysis.Editing;
7 |
8 | namespace MappingGenerator.RoslynHelpers
9 | {
10 | public static class SyntaxGeneratorExtensions
11 | {
12 | public static SyntaxNode CompleteAssignmentStatement(this SyntaxGenerator generator, SyntaxNode left, SyntaxNode right)
13 | {
14 | var assignmentExpression = generator.AssignmentStatement(left, right);
15 | return generator.ExpressionStatement(assignmentExpression);
16 | }
17 |
18 | public static SyntaxNode ContextualReturnStatement(this SyntaxGenerator generator, SyntaxNode nodeToReturn, bool generatorContext)
19 | {
20 | if (generatorContext)
21 | {
22 | return SyntaxFactory.YieldStatement(SyntaxKind.YieldReturnStatement, nodeToReturn as ExpressionSyntax);
23 | }
24 | return generator.ReturnStatement(nodeToReturn);
25 | }
26 |
27 | public static async Task ReplaceNodes(this Document document, SyntaxNode oldNode, SyntaxNode newNode, CancellationToken cancellationToken)
28 | {
29 | var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
30 | var newRoot = root!.ReplaceNode(oldNode, newNode);
31 | return document.WithSyntaxRoot(newRoot);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/RoslynHelpers/SyntaxHelper.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 |
5 | namespace MappingGenerator.RoslynHelpers
6 | {
7 | static class SyntaxHelper
8 | {
9 | public static T FindContainer(this SyntaxNode tokenParent) where T:SyntaxNode
10 | {
11 | if (tokenParent is T invocation)
12 | {
13 | return invocation;
14 | }
15 |
16 | return tokenParent.Parent == null ? null : FindContainer(tokenParent.Parent);
17 | }
18 |
19 | public static SyntaxNode FindNearestContainer(this SyntaxNode tokenParent) where T1:SyntaxNode where T2:SyntaxNode
20 | {
21 | if (tokenParent is T1 t1)
22 | {
23 | return t1;
24 | }
25 |
26 | if (tokenParent is T2 t2)
27 | {
28 | return t2;
29 | }
30 |
31 |
32 | return tokenParent.Parent == null ? null : FindNearestContainer(tokenParent.Parent);
33 | }
34 |
35 | public static StatementSyntax AsStatement(this SyntaxNode node)
36 | {
37 | if (node is ExpressionSyntax expression)
38 | return SyntaxFactory.ExpressionStatement(expression);
39 | return (StatementSyntax)node;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/tools/install.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 |
3 | if($project.Object.SupportsPackageDependencyResolution)
4 | {
5 | if($project.Object.SupportsPackageDependencyResolution())
6 | {
7 | # Do not install analyzers via install.ps1, instead let the project system handle it.
8 | return
9 | }
10 | }
11 |
12 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers") * -Resolve
13 |
14 | foreach($analyzersPath in $analyzersPaths)
15 | {
16 | if (Test-Path $analyzersPath)
17 | {
18 | # Install the language agnostic analyzers.
19 | foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll)
20 | {
21 | if($project.Object.AnalyzerReferences)
22 | {
23 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
24 | }
25 | }
26 | }
27 | }
28 |
29 | # $project.Type gives the language name like (C# or VB.NET)
30 | $languageFolder = ""
31 | if($project.Type -eq "C#")
32 | {
33 | $languageFolder = "cs"
34 | }
35 | if($project.Type -eq "VB.NET")
36 | {
37 | $languageFolder = "vb"
38 | }
39 | if($languageFolder -eq "")
40 | {
41 | return
42 | }
43 |
44 | foreach($analyzersPath in $analyzersPaths)
45 | {
46 | # Install language specific analyzers.
47 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder
48 | if (Test-Path $languageAnalyzersPath)
49 | {
50 | foreach ($analyzerFilePath in Get-ChildItem -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll)
51 | {
52 | if($project.Object.AnalyzerReferences)
53 | {
54 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
55 | }
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/MappingGenerator/MappingGenerator/MappingGenerator/tools/uninstall.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 |
3 | if($project.Object.SupportsPackageDependencyResolution)
4 | {
5 | if($project.Object.SupportsPackageDependencyResolution())
6 | {
7 | # Do not uninstall analyzers via uninstall.ps1, instead let the project system handle it.
8 | return
9 | }
10 | }
11 |
12 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers") * -Resolve
13 |
14 | foreach($analyzersPath in $analyzersPaths)
15 | {
16 | # Uninstall the language agnostic analyzers.
17 | if (Test-Path $analyzersPath)
18 | {
19 | foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll)
20 | {
21 | if($project.Object.AnalyzerReferences)
22 | {
23 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
24 | }
25 | }
26 | }
27 | }
28 |
29 | # $project.Type gives the language name like (C# or VB.NET)
30 | $languageFolder = ""
31 | if($project.Type -eq "C#")
32 | {
33 | $languageFolder = "cs"
34 | }
35 | if($project.Type -eq "VB.NET")
36 | {
37 | $languageFolder = "vb"
38 | }
39 | if($languageFolder -eq "")
40 | {
41 | return
42 | }
43 |
44 | foreach($analyzersPath in $analyzersPaths)
45 | {
46 | # Uninstall language specific analyzers.
47 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder
48 | if (Test-Path $languageAnalyzersPath)
49 | {
50 | foreach ($analyzerFilePath in Get-ChildItem -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll)
51 | {
52 | if($project.Object.AnalyzerReferences)
53 | {
54 | try
55 | {
56 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
57 | }
58 | catch
59 | {
60 |
61 | }
62 | }
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/MappingGenerator/OnBuildGenerator/MappingGenerator.OnBuildGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 | true
6 | true
7 | MappingGenerator.OnBuildGenerator
8 | Cezary Piątek
9 | MappingGenerator.OnBuildGenerator
10 | true
11 |
12 |
13 |
14 |
15 | all
16 | True
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/MappingGenerator/OnBuildGenerator/MappingInterface.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace MappingGenerator.OnBuildGenerator
5 | {
6 | [AttributeUsage(AttributeTargets.Interface)]
7 | [Conditional("CodeGeneration")]
8 | public class MappingInterface:Attribute
9 | {
10 | public System.Type[] CustomStaticMappers { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.20.{build}
2 | image: Visual Studio 2019
3 | configuration: Release
4 | assembly_info:
5 | patch: true
6 | file: '**\AssemblyInfo.*'
7 | assembly_version: '{version}'
8 | assembly_file_version: '{version}'
9 | assembly_informational_version: '{version}'
10 | dotnet_csproj:
11 | patch: true
12 | file: '**\*.csproj'
13 | version: '{version}'
14 | package_version: '{version}'
15 | assembly_version: '{version}'
16 | file_version: '{version}'
17 | informational_version: '{version}'
18 | before_build:
19 | - ps: >-
20 | function Set-VsixVersion {
21 | param(
22 | [Parameter(Mandatory=$true)]
23 | [string]$manifestPath,
24 | [Parameter(Mandatory=$true)]
25 | [string]$Version
26 | )
27 | $manifestXml = [xml](Get-Content $manifestPath -Raw)
28 | $manifestXml.PackageManifest.Metadata.Identity.Version = $Version
29 | $manifestXml.save($manifestPath)
30 | }
31 |
32 | git submodule update --init --recursive
33 |
34 | Set-VsixVersion -Version "$($env:APPVEYOR_BUILD_VERSION)" -manifestPath C:\projects\mappinggenerator\MappingGenerator\MappingGenerator\MappingGenerator.Vsix\source.extension.vsixmanifest
35 |
36 | nuget restore MappingGenerator
37 |
38 | dotnet restore MappingGenerator
39 | build:
40 | project: MappingGenerator\MappingGenerator.sln
41 | verbosity: minimal
42 | after_build:
43 | - ps: Get-ChildItem MappingGenerator\MappingGenerator\MappingGenerator.Vsix\ -Recurse
44 | artifacts:
45 | - path: MappingGenerator\MappingGenerator\MappingGenerator.Vsix\bin\Release\MappingGenerator.vsix
46 | name: MappingGenerator.vsix
47 | - path: MappingGenerator\MappingGenerator\MappingGenerator\bin\Release\MappingGenerator.*.nupkg
48 | name: MappingGenerator.nupkg
49 | - path: MappingGenerator\OnBuildGenerator\bin\Release\MappingGenerator.OnBuildGenerator.*.nupkg
50 | name: MappingGenerator.OnBuildGenerator.nupkg
--------------------------------------------------------------------------------
/doc/InitializeWithLocalVariables.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/InitializeWithLocalVariables.gif
--------------------------------------------------------------------------------
/doc/cs0029.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/cs0029.jpg
--------------------------------------------------------------------------------
/doc/cs0266.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/cs0266.jpg
--------------------------------------------------------------------------------
/doc/emptyInitialization.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/emptyInitialization.gif
--------------------------------------------------------------------------------
/doc/localsforconstructor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/localsforconstructor.gif
--------------------------------------------------------------------------------
/doc/mapping_constructor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/mapping_constructor.gif
--------------------------------------------------------------------------------
/doc/mapping_lambda.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/mapping_lambda.gif
--------------------------------------------------------------------------------
/doc/multi_parameter_constructor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/multi_parameter_constructor.gif
--------------------------------------------------------------------------------
/doc/multiparameterconstructor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/multiparameterconstructor.gif
--------------------------------------------------------------------------------
/doc/multiparameterupdate.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/multiparameterupdate.gif
--------------------------------------------------------------------------------
/doc/object_scaffolding.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/object_scaffolding.gif
--------------------------------------------------------------------------------
/doc/pure_mapping_method.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/pure_mapping_method.gif
--------------------------------------------------------------------------------
/doc/pure_mapping_method_newone.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/pure_mapping_method_newone.gif
--------------------------------------------------------------------------------
/doc/resharper_settings.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/resharper_settings.jpg
--------------------------------------------------------------------------------
/doc/splatting.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/splatting.gif
--------------------------------------------------------------------------------
/doc/support_anim.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/support_anim.gif
--------------------------------------------------------------------------------
/doc/update_member_method.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/update_member_method.gif
--------------------------------------------------------------------------------
/doc/update_method.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cezarypiatek/MappingGenerator/4d5a97c42e0c1ec743268af5a32483a9d0239f25/doc/update_method.gif
--------------------------------------------------------------------------------
/docs/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | 1. Create an issue to describe and discuss the bug or enhancement.
2 | 2. When the issue is aprroved you can fork from the [develop](https://github.com/cezarypiatek/MappingGenerator/tree/develop) branch and prepare the bug fix or new feature
3 | 3. In order to compile the project you need VS2017 and .NET Compiler Platform SDK (You can install it through Visual Studio Installer)
4 | 3. If there is no objection to the code quality, no discrepancy between implementation and arrangement from the issue description and the appveyor build is passing the PR should be accepted
5 |
--------------------------------------------------------------------------------