Skip to content

Commit 75aad5c

Browse files
Merge pull request #43 from vivopensource/dev
Merges Dev to Main
2 parents a1446c9 + 725bf4f commit 75aad5c

File tree

20 files changed

+257
-29
lines changed

20 files changed

+257
-29
lines changed

Core/Console/ConsoleLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ConsoleLogger(ILogger logger)
1313

1414
public virtual void Log(string info)
1515
{
16-
BaseLogger.LogInformation("Message: {Info}", info);
16+
BaseLogger.LogInformation("{Info}", info);
1717
}
1818

1919
public bool LogAndReturnTrue(string info)

Core/Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageReference Include="Microsoft.Extensions.Logging"/>
1212
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions"/>
1313
<PackageReference Include="Microsoft.Extensions.Logging.Console"/>
14+
<PackageReference Include="YamlDotNet" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
/*
1+
using YamlDotNet.Serialization;
2+
using YamlDotNet.Serialization.NamingConventions;
3+
4+
namespace Core.Extensions;
5+
26
internal static class ObjectExtensions
37
{
4-
public static bool IsEqualTo(this object obj1, object? obj2, string propName)
8+
public static string ToYamlString(this object obj)
59
{
6-
if (obj2 is null || obj1.GetType() != obj2.GetType())
7-
return false;
8-
9-
var prop1 = obj1.GetType().GetProperties().First(x => x.Name.Equals(propName));
10-
var prop2 = obj2.GetType().GetProperties().First(x => x.Name.Equals(propName));
11-
12-
var val1 = prop1.GetValue(obj1);
13-
var val2 = prop2.GetValue(obj2);
14-
15-
return val1!.Equals(val2);
10+
return new SerializerBuilder().WithNamingConvention(PascalCaseNamingConvention.Instance).Build().Serialize(obj);
1611
}
17-
}
18-
*/
12+
}

GofConsoleApp/Examples/ExecutionHelpers/PatternOptions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using GofConsoleApp.Examples.Behavioral.CorPattern;
33
using GofConsoleApp.Examples.Behavioral.StatePattern;
44
using GofConsoleApp.Examples.Behavioral.StrategyPattern;
5+
using GofConsoleApp.Examples.Structural.AdapterPattern;
56
using GofConsoleApp.Examples.Structural.DecoratorPattern;
67
using GofConsoleApp.Examples.Structural.ProxyPattern;
78

@@ -15,6 +16,7 @@ internal static class PatternOptions
1516
internal const string ProxyPatternOption = "12";
1617
internal const string ProxyPatternOptionBoundedInput = "12.2";
1718
internal const string ProxyPatternOptionBoundedInputOutput = "12.3";
19+
internal const string AdapterPatternOption = "13";
1820
internal const string ChainOfResponsibilityPatternOption = "21";
1921
internal const string ChainOfResponsibilityPatternOption2 = "21.2";
2022
internal const string ChainOfResponsibilityPatternOption3 = "21.3";
@@ -47,8 +49,11 @@ internal static class PatternOptions
4749
},
4850
{
4951
ProxyPatternOptionBoundedInputOutput,
50-
new PatternExampleMap("Proxy Pattern >> Bounded Input with Output",
51-
new UserInterfaceExampleBoundedAccess())
52+
new PatternExampleMap("Proxy Pattern >> Bounded Input with Output", new UserInterfaceExampleBoundedAccess())
53+
},
54+
{
55+
AdapterPatternOption,
56+
new PatternExampleMap("Adapter Pattern >> Adaptee:Employee , Target:Traveller", new AdapterPatternExample())
5257
},
5358

5459
// Behavioral Patterns
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace GofConsoleApp.Examples.Structural.AdapterPattern.Adaptee;
2+
3+
internal class Employee : IEmployee
4+
{
5+
public Employee(string id, string firstName, string lastName, string address)
6+
{
7+
Id = id;
8+
FirstName = firstName;
9+
LastName = lastName;
10+
Address = address;
11+
}
12+
13+
public string Id { get; }
14+
public string FirstName { get; }
15+
public string LastName { get; }
16+
public string Address { get; }
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace GofConsoleApp.Examples.Structural.AdapterPattern.Adaptee;
2+
3+
/// <summary>
4+
/// Adaptee: Defines an existing interface that needs adapting.
5+
/// </summary>
6+
internal interface IEmployee
7+
{
8+
string Id { get; }
9+
string FirstName { get; }
10+
string LastName { get; }
11+
string Address { get; }
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Core.Extensions;
2+
using GofConsoleApp.Examples.Structural.AdapterPattern.Adaptee;
3+
using GofConsoleApp.Examples.Structural.AdapterPattern.Target;
4+
5+
namespace GofConsoleApp.Examples.Structural.AdapterPattern;
6+
7+
internal class AdapterPatternExample : AbstractExample
8+
{
9+
protected override bool Execute()
10+
{
11+
IEmployee employee = new Employee("1", "John", "Doe", "Success Lane 1");
12+
Logger.Log($"Employee ({employee.Id}):");
13+
Logger.Log(employee.ToYamlString());
14+
15+
ITraveller sutAdapter = new EmployeeTravellerAdapter(employee);
16+
Logger.Log("Traveller information:");
17+
Logger.Log(sutAdapter.ToYamlString());
18+
19+
return true;
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using GofConsoleApp.Examples.Structural.AdapterPattern.Adaptee;
2+
using GofConsoleApp.Examples.Structural.AdapterPattern.Target;
3+
using GofPatterns.Structural.AdapterPattern;
4+
5+
namespace GofConsoleApp.Examples.Structural.AdapterPattern;
6+
7+
internal class EmployeeTravellerAdapter : IAdapter<IEmployee, ITraveller>, ITraveller
8+
{
9+
public EmployeeTravellerAdapter(IEmployee adaptee)
10+
{
11+
FullName = $"{adaptee.FirstName} {adaptee.LastName}";
12+
Address = adaptee.Address;
13+
}
14+
15+
public string FullName { get; }
16+
public string Address { get; }
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace GofConsoleApp.Examples.Structural.AdapterPattern.Target;
2+
3+
/// <summary>
4+
/// Target: Defines the domain-specific interface that Client uses.
5+
/// </summary>
6+
internal interface ITraveller
7+
{
8+
string FullName { get; }
9+
string Address { get; }
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace GofPatterns.Structural.AdapterPattern;
2+
3+
public interface IAdapter<out TOutput>
4+
{
5+
TOutput Request<TInput>(TInput input);
6+
}
7+
8+
public interface IAdapter<TAdaptee, TTarget> { }

0 commit comments

Comments
 (0)