-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize repo with working class hierarchy
- Loading branch information
Showing
8 changed files
with
215 additions
and
0 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,10 @@ | ||
################################################################################ | ||
# This .gitignore file was automatically created by Microsoft(R) Visual Studio. | ||
################################################################################ | ||
|
||
/.vs | ||
/Archigen/.vs/Archigen/v16 | ||
/Archigen/Archigen/bin | ||
/Archigen/Archigen/obj | ||
/Archigen/Archigen.Example/bin | ||
/Archigen/Archigen.Example/obj |
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Archigen\Archigen.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,61 @@ | ||
using System; | ||
|
||
namespace Archigen.Example | ||
{ | ||
|
||
public class StringGenerator : IGenerator<string> | ||
{ | ||
public string Next() | ||
{ | ||
return "This is a string"; | ||
} | ||
} | ||
|
||
public class NumberGenerator : IGenerator<int> | ||
{ | ||
public int Next() | ||
{ | ||
return 42; | ||
} | ||
} | ||
|
||
public class UserGenerator : IGenerator<User> | ||
{ | ||
public User Next() | ||
{ | ||
return new User() { FirstName = "John", LastName = "Smith", Age = 9001 }; | ||
} | ||
} | ||
|
||
public class User | ||
{ | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public int Age { get; set; } | ||
public User Partner { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return FirstName + " " + LastName + " " + Age + " " + Partner?.ToString(); | ||
} | ||
|
||
} | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var g = new Generator<User>() | ||
.ForProperty<string>(x => x.FirstName, new StringGenerator()) | ||
.ForProperty<string>(x => x.LastName, new StringGenerator()) | ||
.ForProperty<int>(x => x.Age, new NumberGenerator()) | ||
.ForProperty<User>(x => x.Partner, new UserGenerator()); | ||
|
||
for(int i = 0; i < 10; i++) | ||
{ | ||
Console.WriteLine(g.Next()); | ||
} | ||
|
||
} | ||
} | ||
} |
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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31229.75 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archigen", "Archigen\Archigen.csproj", "{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archigen.Example", "Archigen.Example\Archigen.Example.csproj", "{4F72A841-2B84-43C4-80EF-08C14D35FBFA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EE1EDF08-9374-4FE7-AF4D-1F94281F2F87} | ||
EndGlobalSection | ||
EndGlobal |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Version>0.9.0-alpha</Version> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<PackageProjectUrl>https://github.com/kesac/Archigen</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/kesac/Archigen</RepositoryUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Archigen | ||
{ | ||
public class Generator<T> : IGenerator<T> where T : new() | ||
{ | ||
public Dictionary<string, GeneratorInfo> Generators { get; set; } | ||
|
||
public Generator() | ||
{ | ||
this.Generators = new Dictionary<string, GeneratorInfo>(); | ||
} | ||
|
||
public Generator<T> ForProperty<U>(Expression<Func<T, U>> expression, IGenerator<U> generator) | ||
{ | ||
var type = generator.GetType(); | ||
var next = type.GetMethod("Next"); | ||
|
||
var memberExpression = (MemberExpression) expression.Body; | ||
var property = (PropertyInfo) memberExpression.Member; | ||
|
||
this.Generators.Add(property.Name, new GeneratorInfo(generator, next)); | ||
return this; | ||
} | ||
|
||
|
||
public T Next() | ||
{ | ||
var result = new T(); | ||
|
||
foreach(var targetProperty in this.Generators.Keys) | ||
{ | ||
var property = result.GetType().GetProperty(targetProperty); | ||
var gInfo = this.Generators[targetProperty]; | ||
|
||
property.SetValue(result, gInfo.Next.Invoke(gInfo.Generator, null)); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Archigen | ||
{ | ||
public class GeneratorInfo | ||
{ | ||
public IGenerator Generator { get; set; } | ||
public MethodInfo Next { get; set; } | ||
|
||
public GeneratorInfo(IGenerator g, MethodInfo next) | ||
{ | ||
this.Generator = g; | ||
this.Next = next; | ||
} | ||
|
||
} | ||
} |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Archigen | ||
{ | ||
|
||
public interface IGenerator { } | ||
|
||
// Represents anything that can procedurally | ||
// generate something | ||
public interface IGenerator<T> : IGenerator | ||
{ | ||
T Next(); | ||
} | ||
} |