Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Apr 27, 2024
1 parent 835000e commit 31610e7
Show file tree
Hide file tree
Showing 84 changed files with 2,749 additions and 2,743 deletions.
14 changes: 10 additions & 4 deletions build/ReadmeTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private static async Task AddClassDiagram(string logsDirectory, string exampleNa

private static async Task AddExample(string logsDirectory, string exampleSearchPattern, TextWriter examplesWriter)
{
var salt = $"M{DateTime.Now.Month:00}D{DateTime.Now.Day:00}di";
foreach (var generatedCodeFile in Directory.GetFiles(Path.Combine(logsDirectory, "Pure.DI", "Pure.DI.SourceGenerator"), exampleSearchPattern).OrderBy(i => i))
{
var ns = string.Join('.', Path.GetFileName(generatedCodeFile).Split('.').Reverse().Skip(3).Reverse()) + ".";
Expand Down Expand Up @@ -352,10 +353,15 @@ private static async Task AddExample(string logsDirectory, string exampleSearchP
.Select(i => i
.TrimEnd()
.Replace("\t", " ")
.Replace("global::System.", "")
.Replace("Runtime.CompilerServices.", "")
.Replace("global::Pure.DI.", "")
.Replace(ns, "")));
.Replace(ns, "")
.Replace("global::", "")
.Replace("System.Threading.Tasks.", "")
.Replace("System.Threading.", "")
.Replace("System.Runtime.CompilerServices.", "")
.Replace("System.Collections.Generic.", "")
.Replace("System.", "")
.Replace("Pure.DI.", "")
.Replace(salt, "")));
await examplesWriter.WriteLineAsync(generatedCode);
await examplesWriter.WriteLineAsync("```");
await examplesWriter.WriteLineAsync("");
Expand Down
64 changes: 32 additions & 32 deletions readme/ArrayDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,51 +88,51 @@ classDiagram
```c#
partial class Array
{
private readonly Array _rootM04D27di;
private readonly Array _root;

public Array()
{
_rootM04D27di = this;
_root = this;
}

internal Array(Array baseComposition)
{
_rootM04D27di = baseComposition._rootM04D27di;
_root = baseComposition._root;
}

[MethodImpl((MethodImplOptions)0x100)]
public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR()
public partial Benchmarks.Model.CompositionRoot TestPureDIByCR()
{
return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) })), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) })), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
}

[MethodImpl((MethodImplOptions)0x100)]
public T Resolve<T>()
{
return ResolverM04D27di<T>.Value.Resolve(this);
return Resolver<T>.Value.Resolve(this);
}

[MethodImpl((MethodImplOptions)0x100)]
public T Resolve<T>(object? tag)
{
return ResolverM04D27di<T>.Value.ResolveByTag(this, tag);
return Resolver<T>.Value.ResolveByTag(this, tag);
}

[MethodImpl((MethodImplOptions)0x100)]
public object Resolve(Type type)
{
var index = (int)(_bucketSizeM04D27di * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM04D27di[index];
return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index);
var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _buckets[index];
return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index);
}

[MethodImpl((MethodImplOptions)0x8)]
private object ResolveM04D27di(Type type, int index)
private object Resolve(Type type, int index)
{
var finish = index + _bucketSizeM04D27di;
var finish = index + _bucketSize;
while (++index < finish)
{
ref var pair = ref _bucketsM04D27di[index];
ref var pair = ref _buckets[index];
if (pair.Key == type)
{
return pair.Value.Resolve(this);
Expand All @@ -145,18 +145,18 @@ partial class Array
[MethodImpl((MethodImplOptions)0x100)]
public object Resolve(Type type, object? tag)
{
var index = (int)(_bucketSizeM04D27di * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM04D27di[index];
return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index);
var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _buckets[index];
return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index);
}

[MethodImpl((MethodImplOptions)0x8)]
private object ResolveM04D27di(Type type, object? tag, int index)
private object Resolve(Type type, object? tag, int index)
{
var finish = index + _bucketSizeM04D27di;
var finish = index + _bucketSize;
while (++index < finish)
{
ref var pair = ref _bucketsM04D27di[index];
ref var pair = ref _buckets[index];
if (pair.Key == type)
{
return pair.Value.ResolveByTag(this, tag);
Expand Down Expand Up @@ -245,25 +245,25 @@ partial class Array
" ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3";
}

private readonly static int _bucketSizeM04D27di;
private readonly static Pair<Type, IResolver<Array, object>>[] _bucketsM04D27di;
private readonly static int _bucketSize;
private readonly static Pair<Type, IResolver<Array, object>>[] _buckets;

static Array()
{
var valResolverM04D27di_0000 = new ResolverM04D27di_0000();
ResolverM04D27di<Pure.DI.Benchmarks.Model.CompositionRoot>.Value = valResolverM04D27di_0000;
_bucketsM04D27di = Buckets<Type, IResolver<Array, object>>.Create(
var valResolver_0000 = new Resolver_0000();
Resolver<Benchmarks.Model.CompositionRoot>.Value = valResolver_0000;
_buckets = Buckets<Type, IResolver<Array, object>>.Create(
1,
out _bucketSizeM04D27di,
out _bucketSize,
new Pair<Type, IResolver<Array, object>>[1]
{
new Pair<Type, IResolver<Array, object>>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000)
new Pair<Type, IResolver<Array, object>>(typeof(Benchmarks.Model.CompositionRoot), valResolver_0000)
});
}

private sealed class ResolverM04D27di<T>: IResolver<Array, T>
private sealed class Resolver<T>: IResolver<Array, T>
{
public static IResolver<Array, T> Value = new ResolverM04D27di<T>();
public static IResolver<Array, T> Value = new Resolver<T>();

public T Resolve(Array composite)
{
Expand All @@ -276,21 +276,21 @@ partial class Array
}
}

private sealed class ResolverM04D27di_0000: IResolver<Array, Pure.DI.Benchmarks.Model.CompositionRoot>
private sealed class Resolver_0000: IResolver<Array, Benchmarks.Model.CompositionRoot>
{
public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Array composition)
public Benchmarks.Model.CompositionRoot Resolve(Array composition)
{
return composition.TestPureDIByCR();
}

public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Array composition, object tag)
public Benchmarks.Model.CompositionRoot ResolveByTag(Array composition, object tag)
{
switch (tag)
{
case null:
return composition.TestPureDIByCR();
default:
throw new InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot.");
throw new InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Benchmarks.Model.CompositionRoot.");
}
}
}
Expand Down
76 changes: 38 additions & 38 deletions readme/EnumDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,60 +88,60 @@ classDiagram
```c#
partial class Enum
{
private readonly Enum _rootM04D27di;
private readonly Enum _root;

public Enum()
{
_rootM04D27di = this;
_root = this;
}

internal Enum(Enum baseComposition)
{
_rootM04D27di = baseComposition._rootM04D27di;
_root = baseComposition._root;
}

[MethodImpl((MethodImplOptions)0x100)]
public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR()
public partial Benchmarks.Model.CompositionRoot TestPureDIByCR()
{
[MethodImpl((MethodImplOptions)0x200)]
System.Collections.Generic.IEnumerable<Pure.DI.Benchmarks.Model.IService3> LocalperBlockM04D27di10_IEnumerable()
IEnumerable<Benchmarks.Model.IService3> LocalperBlock10_IEnumerable()
{
yield return new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
yield return new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
yield return new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
yield return new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
yield return new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
yield return new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
yield return new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
yield return new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
}
System.Collections.Generic.IEnumerable<Pure.DI.Benchmarks.Model.IService3> perBlockM04D27di10_IEnumerable = LocalperBlockM04D27di10_IEnumerable();
return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable)), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4());
IEnumerable<Benchmarks.Model.IService3> perBlock10_IEnumerable = LocalperBlock10_IEnumerable();
return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable)), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
}

[MethodImpl((MethodImplOptions)0x100)]
public T Resolve<T>()
{
return ResolverM04D27di<T>.Value.Resolve(this);
return Resolver<T>.Value.Resolve(this);
}

[MethodImpl((MethodImplOptions)0x100)]
public T Resolve<T>(object? tag)
{
return ResolverM04D27di<T>.Value.ResolveByTag(this, tag);
return Resolver<T>.Value.ResolveByTag(this, tag);
}

[MethodImpl((MethodImplOptions)0x100)]
public object Resolve(Type type)
{
var index = (int)(_bucketSizeM04D27di * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM04D27di[index];
return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index);
var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _buckets[index];
return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index);
}

[MethodImpl((MethodImplOptions)0x8)]
private object ResolveM04D27di(Type type, int index)
private object Resolve(Type type, int index)
{
var finish = index + _bucketSizeM04D27di;
var finish = index + _bucketSize;
while (++index < finish)
{
ref var pair = ref _bucketsM04D27di[index];
ref var pair = ref _buckets[index];
if (pair.Key == type)
{
return pair.Value.Resolve(this);
Expand All @@ -154,18 +154,18 @@ partial class Enum
[MethodImpl((MethodImplOptions)0x100)]
public object Resolve(Type type, object? tag)
{
var index = (int)(_bucketSizeM04D27di * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM04D27di[index];
return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index);
var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _buckets[index];
return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index);
}

[MethodImpl((MethodImplOptions)0x8)]
private object ResolveM04D27di(Type type, object? tag, int index)
private object Resolve(Type type, object? tag, int index)
{
var finish = index + _bucketSizeM04D27di;
var finish = index + _bucketSize;
while (++index < finish)
{
ref var pair = ref _bucketsM04D27di[index];
ref var pair = ref _buckets[index];
if (pair.Key == type)
{
return pair.Value.ResolveByTag(this, tag);
Expand Down Expand Up @@ -254,25 +254,25 @@ partial class Enum
" IEnumerableᐸIService3ᐳ *-- Service3v4 : 4 IService3";
}

private readonly static int _bucketSizeM04D27di;
private readonly static Pair<Type, IResolver<Enum, object>>[] _bucketsM04D27di;
private readonly static int _bucketSize;
private readonly static Pair<Type, IResolver<Enum, object>>[] _buckets;

static Enum()
{
var valResolverM04D27di_0000 = new ResolverM04D27di_0000();
ResolverM04D27di<Pure.DI.Benchmarks.Model.CompositionRoot>.Value = valResolverM04D27di_0000;
_bucketsM04D27di = Buckets<Type, IResolver<Enum, object>>.Create(
var valResolver_0000 = new Resolver_0000();
Resolver<Benchmarks.Model.CompositionRoot>.Value = valResolver_0000;
_buckets = Buckets<Type, IResolver<Enum, object>>.Create(
1,
out _bucketSizeM04D27di,
out _bucketSize,
new Pair<Type, IResolver<Enum, object>>[1]
{
new Pair<Type, IResolver<Enum, object>>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000)
new Pair<Type, IResolver<Enum, object>>(typeof(Benchmarks.Model.CompositionRoot), valResolver_0000)
});
}

private sealed class ResolverM04D27di<T>: IResolver<Enum, T>
private sealed class Resolver<T>: IResolver<Enum, T>
{
public static IResolver<Enum, T> Value = new ResolverM04D27di<T>();
public static IResolver<Enum, T> Value = new Resolver<T>();

public T Resolve(Enum composite)
{
Expand All @@ -285,21 +285,21 @@ partial class Enum
}
}

private sealed class ResolverM04D27di_0000: IResolver<Enum, Pure.DI.Benchmarks.Model.CompositionRoot>
private sealed class Resolver_0000: IResolver<Enum, Benchmarks.Model.CompositionRoot>
{
public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Enum composition)
public Benchmarks.Model.CompositionRoot Resolve(Enum composition)
{
return composition.TestPureDIByCR();
}

public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Enum composition, object tag)
public Benchmarks.Model.CompositionRoot ResolveByTag(Enum composition, object tag)
{
switch (tag)
{
case null:
return composition.TestPureDIByCR();
default:
throw new InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot.");
throw new InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Benchmarks.Model.CompositionRoot.");
}
}
}
Expand Down
Loading

0 comments on commit 31610e7

Please sign in to comment.