Skip to content

Commit

Permalink
Release/2.0.1 (#94)
Browse files Browse the repository at this point in the history
* 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
4 people authored Oct 1, 2021
1 parent fb1dc25 commit 0ebeeef
Show file tree
Hide file tree
Showing 78 changed files with 1,592 additions and 288 deletions.
1 change: 1 addition & 0 deletions src/BBT.StructureTools.Extensions/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: System.CLSCompliant(true)]
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>
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;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
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
{
}
}
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
{
}
}
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);
}
}
Loading

0 comments on commit 0ebeeef

Please sign in to comment.