-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge tag '1.0.3' into develop * Convert registration methods simplified and additional convert helper implementations added. (#92) * Convert registration methods simplified. Generic parameter TConcreteTarget removed. ConvertHelperFactory and CreateConverHelper implementations moved to BBT.StructureTools.Extensions. * CreateTargetImplConvertTargetImpl implementations and tests added. * CreateConvertFromStrategy implementations and tests added. * Documentation improved. Co-authored-by: Stefan Lindegger <lis@bbtsoftware.ch> * Update link to release Co-authored-by: Christian Bumann <bch@bbtsoftware.ch> Co-authored-by: stefan-lindegger <49828420+stefan-lindegger@users.noreply.github.com> Co-authored-by: Stefan Lindegger <lis@bbtsoftware.ch>
- Loading branch information
1 parent
fb1dc25
commit 0ebeeef
Showing
78 changed files
with
1,592 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[assembly: System.CLSCompliant(true)] |
47 changes: 47 additions & 0 deletions
47
src/BBT.StructureTools.Extensions/BBT.StructureTools.Extensions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AssemblyTitle>BBT.StructureTools.Extensions</AssemblyTitle> | ||
<CodeAnalysisRuleSet>..\BBT.StructureTools.ruleset</CodeAnalysisRuleSet> | ||
<DocumentationFile>bin\$(Configuration)\BBT.StructureTools.XML</DocumentationFile> | ||
<OutputPath>bin\$(Configuration)\</OutputPath> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Title>BBT.StructureTools.Extensions</Title> | ||
<Description>Extensions to BBT.StructureTools (e.g. implementations of ICreateConvertHelper and IConvertHelperFactory interfaces).</Description> | ||
<Product>BBT.StructureTools</Product> | ||
<Company>BBT Software AG</Company> | ||
<Authors>BBT Software AG</Authors> | ||
<Copyright>Copyright © BBT Software AG</Copyright> | ||
<PackageTags>copy compare convert</PackageTags> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageProjectUrl>http://bbtsoftware.github.io/BBT.StructureTools/</PackageProjectUrl> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/bbtsoftware/BBT.StructureTools.git</RepositoryUrl> | ||
<PackageReleaseNotes>https://github.com/bbtsoftware/BBT.StructureTools/releases/tag/2.0.1</PackageReleaseNotes> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BBT.StructureTools\BBT.StructureTools.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="icon.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
42 changes: 42 additions & 0 deletions
42
...tureTools.Extensions/Convert/CreateConvertFromStrategy/CreateConvertFromStrategyHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using System.Collections.Generic; | ||
using BBT.StrategyPattern; | ||
using BBT.StructureTools; | ||
using BBT.StructureTools.Convert; | ||
using BBT.StructureTools.Extension; | ||
|
||
/// <inheritdoc/> | ||
public class CreateConvertFromStrategyHelper<TSource, TTarget, TIntention> | ||
: ICreateConvertFromStrategyHelper<TSource, TTarget, TIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TIntention : IBaseConvertIntention | ||
{ | ||
private readonly IGenericStrategyProvider<ICreateConvertStrategy<TSource, TTarget, TIntention>, TSource> strategyProvider; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CreateConvertFromStrategyHelper{TSource, TTarget, TIntention}" /> class. | ||
/// </summary> | ||
public CreateConvertFromStrategyHelper(IGenericStrategyProvider<ICreateConvertStrategy<TSource, TTarget, TIntention>, TSource> strategyProvider) | ||
{ | ||
strategyProvider.NotNull(nameof(strategyProvider)); | ||
|
||
this.strategyProvider = strategyProvider; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public TTarget CreateTarget(TSource source, ICollection<IBaseAdditionalProcessing> additionalProcessings) | ||
{ | ||
source.NotNull(nameof(source)); | ||
additionalProcessings.NotNull(nameof(additionalProcessings)); | ||
|
||
var strategy = this.strategyProvider.GetStrategy(source); | ||
|
||
var concreteTarget = strategy.CreateTarget(source); | ||
strategy.Convert(source, concreteTarget, additionalProcessings); | ||
|
||
return concreteTarget; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ls.Extensions/Convert/CreateConvertFromStrategy/CreateConvertFromStrategyHelperFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using System; | ||
using System.Linq.Expressions; | ||
using BBT.StructureTools.Convert; | ||
using BBT.StructureTools.Extension; | ||
using BBT.StructureTools.Initialization; | ||
|
||
/// <inheritdoc/> | ||
public class CreateConvertFromStrategyHelperFactory<TSource, TTarget, TConvertIntention> | ||
: ICreateConvertFromStrategyHelperFactory<TSource, TTarget, TConvertIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TConvertIntention : IBaseConvertIntention | ||
{ | ||
/// <inheritdoc/> | ||
public ICreateConvertHelper<TSource, TTarget, TConvertIntention> GetConvertHelper() | ||
{ | ||
var convertHelper = IocHandler.Instance.IocResolver | ||
.GetInstance<ICreateConvertFromStrategyHelper<TSource, TTarget, TConvertIntention>>(); | ||
return convertHelper; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ICreateConvertHelper<TSource, TTarget, TReverseRelation, TConvertIntention> GetConvertHelper<TReverseRelation>( | ||
Expression<Func<TTarget, TReverseRelation>> reverseRelationExpr) | ||
where TReverseRelation : class | ||
{ | ||
reverseRelationExpr.NotNull(nameof(reverseRelationExpr)); | ||
|
||
var convertHelper = IocHandler.Instance.IocResolver | ||
.GetInstance<ICreateConvertFromStrategyHelper<TSource, TTarget, TReverseRelation, TConvertIntention>>(); | ||
convertHelper.SetupReverseRelation(reverseRelationExpr); | ||
return convertHelper; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ls.Extensions/Convert/CreateConvertFromStrategy/CreateConvertFromStrategyHelperReverse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using BBT.StrategyPattern; | ||
using BBT.StructureTools; | ||
using BBT.StructureTools.Convert; | ||
using BBT.StructureTools.Extension; | ||
|
||
/// <inheritdoc/> | ||
public class CreateConvertFromStrategyHelperReverse<TSource, TTarget, TReverseRelation, TIntention> | ||
: ICreateConvertFromStrategyHelper<TSource, TTarget, TReverseRelation, TIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TReverseRelation : class | ||
where TIntention : IBaseConvertIntention | ||
{ | ||
private readonly IGenericStrategyProvider<ICreateConvertStrategy<TSource, TTarget, TIntention>, TSource> strategyProvider; | ||
private Expression<Func<TTarget, TReverseRelation>> reverseRelationExpr; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CreateConvertFromStrategyHelperReverse{TSource, TTarget, TReverseRelation, TIntention}" /> class. | ||
/// </summary> | ||
public CreateConvertFromStrategyHelperReverse(IGenericStrategyProvider<ICreateConvertStrategy<TSource, TTarget, TIntention>, TSource> strategyProvider) | ||
{ | ||
strategyProvider.NotNull(nameof(strategyProvider)); | ||
|
||
this.strategyProvider = strategyProvider; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public TTarget CreateTarget( | ||
TSource source, | ||
TReverseRelation reverseRelation, | ||
ICollection<IBaseAdditionalProcessing> additionalProcessings) | ||
{ | ||
source.NotNull(nameof(source)); | ||
reverseRelation.NotNull(nameof(reverseRelation)); | ||
|
||
var strategy = this.strategyProvider.GetStrategy(source); | ||
var concreteTarget = strategy.CreateTarget(source); | ||
concreteTarget.SetPropertyValue(this.reverseRelationExpr, reverseRelation); | ||
strategy.Convert(source, concreteTarget, additionalProcessings); | ||
return concreteTarget; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void SetupReverseRelation( | ||
Expression<Func<TTarget, TReverseRelation>> reverseRelationExpr) | ||
{ | ||
reverseRelationExpr.NotNull(nameof(reverseRelationExpr)); | ||
|
||
this.reverseRelationExpr = reverseRelationExpr; | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/BBT.StructureTools.Extensions/Convert/CreateConvertFromStrategy/CreateConvertStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using System.Collections.Generic; | ||
using BBT.StrategyPattern; | ||
using BBT.StructureTools; | ||
using BBT.StructureTools.Convert; | ||
using BBT.StructureTools.Extension; | ||
|
||
/// <inheritdoc/> | ||
public class CreateConvertStrategy<TSource, TConcreteSource, TTarget, TConcreteTarget, TConcreteTargetImpl, TIntention> | ||
: ICreateConvertStrategy<TSource, TTarget, TIntention> | ||
where TSource : class | ||
where TConcreteSource : class, TSource | ||
where TTarget : class | ||
where TConcreteTarget : class, TTarget | ||
where TConcreteTargetImpl : class, TConcreteTarget, new() | ||
where TIntention : IBaseConvertIntention | ||
{ | ||
private readonly IInstanceCreator<TConcreteTarget, TConcreteTargetImpl> creator; | ||
private readonly IConvert<TConcreteSource, TConcreteTarget, TIntention> converter; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CreateConvertStrategy{TSource, TConcreteSource, TTarget, TConcreteTarget, TConcreteTargetImpl, TIntention}"/> class. | ||
/// </summary> | ||
public CreateConvertStrategy( | ||
IInstanceCreator<TConcreteTarget, TConcreteTargetImpl> creator, | ||
IConvert<TConcreteSource, TConcreteTarget, TIntention> converter) | ||
{ | ||
creator.NotNull(nameof(creator)); | ||
converter.NotNull(nameof(converter)); | ||
|
||
this.creator = creator; | ||
this.converter = converter; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public TTarget CreateTarget(TSource source) | ||
{ | ||
source.NotNull(nameof(source)); | ||
|
||
var target = this.creator.Create(); | ||
return target; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Convert(TSource source, TTarget target, ICollection<IBaseAdditionalProcessing> additionalProcessings) | ||
{ | ||
source.NotNull(nameof(source)); | ||
target.NotNull(nameof(target)); | ||
additionalProcessings.NotNull(nameof(additionalProcessings)); | ||
|
||
this.converter.Convert((TConcreteSource)source, (TConcreteTarget)target, additionalProcessings); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsResponsible(TSource criterion) | ||
{ | ||
criterion.NotNull(nameof(criterion)); | ||
return criterion is TConcreteSource; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ureTools.Extensions/Convert/CreateConvertFromStrategy/ICreateConvertFromStrategyHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using BBT.StructureTools.Convert; | ||
|
||
/// <summary> | ||
/// Provides methods to support conversions where target objects are created. | ||
/// Use this helper implementation if the target object (i.e. <typeparamref name="TTarget"/>) | ||
/// is created as well as converted using a <see cref="ICreateConvertStrategy{TSource, TTarget, TIntention}"/>. | ||
/// A generic strategy implementation is provided, | ||
/// <see cref="CreateConvertStrategy{TSource, TConcreteSource, TTarget, TConcreteTarget, TConcreteTargetImpl, TIntention}"/>. | ||
/// Register strategies for all concerned derived types in your IoC container in use. | ||
/// </summary> | ||
/// <typeparam name="TSource">The source to convert from.</typeparam> | ||
/// <typeparam name="TTarget">The target to convert to.</typeparam> | ||
/// <typeparam name="TReverseRelation">The reverse relation property of <typeparamref name="TTarget"/>.</typeparam> | ||
/// <typeparam name="TConvertIntention">The intention of the conversion.</typeparam> | ||
public interface ICreateConvertFromStrategyHelper<in TSource, TTarget, TReverseRelation, TConvertIntention> | ||
: ICreateConvertHelper<TSource, TTarget, TReverseRelation, TConvertIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TReverseRelation : class | ||
where TConvertIntention : IBaseConvertIntention | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Provides methods to support conversions where target objects are created. | ||
/// Use this helper implementation if the target object (i.e. <typeparamref name="TTarget"/>) | ||
/// is created as well as converted using a <see cref="ICreateConvertStrategy{TSource, TTarget, TIntention}"/>. | ||
/// A generic strategy implementation is provided, | ||
/// <see cref="CreateConvertStrategy{TSource, TConcreteSource, TTarget, TConcreteTarget, TConcreteTargetImpl, TIntention}"/>. | ||
/// Register strategies for all concerned derived types in your IoC container in use. | ||
/// </summary> | ||
/// <typeparam name="TSource">The source to convert from.</typeparam> | ||
/// <typeparam name="TTarget">The target to convert to.</typeparam> | ||
/// <typeparam name="TConvertIntention">The intention of the conversion.</typeparam> | ||
public interface ICreateConvertFromStrategyHelper<in TSource, TTarget, TConvertIntention> | ||
: ICreateConvertHelper<TSource, TTarget, TConvertIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TConvertIntention : IBaseConvertIntention | ||
{ | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...s.Extensions/Convert/CreateConvertFromStrategy/ICreateConvertFromStrategyHelperFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using BBT.StructureTools.Convert; | ||
|
||
/// <summary> | ||
/// Provides methods to create <see cref="ICreateConvertFromStrategyHelper{TSource,TTarget,TConvertIntention}"/>. | ||
/// </summary> | ||
/// <typeparam name="TSource">The source to convert from.</typeparam> | ||
/// <typeparam name="TTarget">The target to convert to.</typeparam> | ||
/// <typeparam name="TConvertIntention">The intention of the conversion.</typeparam> | ||
public interface ICreateConvertFromStrategyHelperFactory<in TSource, TTarget, TConvertIntention> | ||
: IConvertHelperFactory<TSource, TTarget, TConvertIntention> | ||
where TSource : class | ||
where TTarget : class | ||
where TConvertIntention : IBaseConvertIntention | ||
{ | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...BBT.StructureTools.Extensions/Convert/CreateConvertFromStrategy/ICreateConvertStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace BBT.StructureTools.Extensions.Convert | ||
{ | ||
using System.Collections.Generic; | ||
using BBT.StrategyPattern; | ||
using BBT.StructureTools; | ||
using BBT.StructureTools.Convert; | ||
|
||
/// <summary> | ||
/// Strategy to provide methods for creation of a concrete <typeparamref name="TTarget"/> | ||
/// and conversion of a concrete <typeparamref name="TSource"/> into a concrete <typeparamref name="TTarget"/>. | ||
/// A generic strategy implementation is provided, | ||
/// <see cref="CreateConvertStrategy{TSource, TConcreteSource, TTarget, TConcreteTarget, TConcreateTargetImpl, TIntention}"/>. | ||
/// </summary> | ||
/// <typeparam name="TSource">The type of source.</typeparam> | ||
/// <typeparam name="TTarget">The type of target.</typeparam> | ||
/// <typeparam name="TIntention">The convert intention.</typeparam> | ||
public interface ICreateConvertStrategy<TSource, TTarget, TIntention> | ||
: IGenericStrategy<TSource> | ||
where TSource : class | ||
where TTarget : class | ||
where TIntention : IBaseConvertIntention | ||
{ | ||
/// <summary> | ||
/// Creates a concrete <typeparamref name="TTarget"/>. | ||
/// </summary> | ||
TTarget CreateTarget(TSource aSource); | ||
|
||
/// <summary> | ||
/// Converts a concrete <typeparamref name="TSource"/> into a concrete <typeparamref name="TTarget"/>. | ||
/// </summary> | ||
void Convert(TSource aSource, TTarget aTraget, ICollection<IBaseAdditionalProcessing> aAdditionalProcessings); | ||
} | ||
} |
Oops, something went wrong.