Skip to content

Commit 35b5d08

Browse files
EppNet.Data: Add Network Arguments collection system for storing a collection of 1-7 network types.
IObjectService: Add interface for ObjectService. Clients will use a dictionary while servers will use pagination.
1 parent 3ef70cc commit 35b5d08

File tree

11 files changed

+648
-7
lines changed

11 files changed

+648
-7
lines changed

EppNet-SourceGen/Source/ExecutionContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88

99
using System.Collections.Concurrent;
10-
using System.Collections.Generic;
1110

1211
namespace EppNet.SourceGen
1312
{

EppNet-SourceGen/Source/Models/ResolverModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public readonly struct ResolverModel(ISymbol symbol, ITypeSymbol typeSymbol) : I
2323
/// </summary>
2424
public string Namespace { get; } = symbol.ContainingNamespace?.Name ?? string.Empty;
2525

26+
public string FullyQualifiedName { get; } = symbol.ToDisplayString(Globals.DisplayFormat);
27+
2628
/// <summary>
2729
/// The fully qualified name of the type this resolver resolves.
2830
/// </summary>
@@ -35,6 +37,7 @@ obj is ResolverModel model &&
3537
public bool Equals(ResolverModel other) =>
3638
Name == other.Name &&
3739
Namespace == other.Namespace &&
40+
FullyQualifiedName == other.FullyQualifiedName &&
3841
ResolvedTypeFullName == other.ResolvedTypeFullName;
3942

4043
public override string ToString() =>
@@ -43,6 +46,7 @@ public override string ToString() =>
4346
public override int GetHashCode() =>
4447
Name.GetHashCode() ^
4548
Namespace.GetHashCode() ^
49+
FullyQualifiedName.GetHashCode() ^
4650
ResolvedTypeFullName.GetHashCode();
4751

4852
public static bool operator ==(ResolverModel left, ResolverModel right) =>

EppNet-SourceGen/Source/RegisterObjectsGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4141
)
4242
.Where(static r => r is not null)
4343
.Collect()
44-
.Select(static (list, _) => list.ToDictionary(r => r!.Value.ResolvedTypeFullName, r => r!.Value.Name));
44+
.Select(static (list, _) => list.ToDictionary(r => r!.Value.ResolvedTypeFullName, r => r!.Value.FullyQualifiedName));
4545

4646
var netObjects = context.SyntaxProvider
4747
.ForAttributeWithMetadataName(
@@ -85,8 +85,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
8585
StringBuilder availableMethods = new();
8686

8787
Dictionary<string, EquatableHashSet<NetworkMethodModel>> fullMethods = new();
88-
List<string> hierarchy = new(model.NetObjectHierarchy);
89-
hierarchy.Add(fqn);
88+
List<string> hierarchy = [.. model.NetObjectHierarchy, fqn];
9089

9190
bool invalid = false;
9291

@@ -135,7 +134,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
135134

136135
StringBuilder resolverBuilder = new();
137136
foreach (string resolverType in resolverDict.Keys)
138-
resolverBuilder.AppendLine($"// {resolverType}");
137+
resolverBuilder.AppendLine($"// {resolverType} @ {resolverDict[resolverType]}");
139138

140139
StringBuilder builder = new($$"""
141140
// <auto-generated/>

Source/Data/ICloneable.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
///////////////////////////////////////////////////////
2+
/// Filename: ICloneable.cs
3+
/// Date: March 28, 2025
4+
/// Author: Maverick Liberty
5+
///////////////////////////////////////////////////////
6+
7+
namespace EppNet.Data
8+
{
9+
10+
/// <summary>
11+
/// Not to be confused with <see cref="System.ICloneable"/>, this creates a type-safe clone.<br/>
12+
/// Output should <b>NEVER</b> be null
13+
/// </summary>
14+
/// <typeparam name="T"></typeparam>
15+
16+
public interface ICloneable<T>
17+
{
18+
19+
/// <summary>
20+
/// Creates a type-safe clone
21+
/// </summary>
22+
/// <returns>Copy; <b>NEVER</b> null</returns>
23+
T Clone();
24+
}
25+
26+
}
27+

Source/Data/INameable.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ namespace EppNet.Data
1010
public interface INameable
1111
{
1212

13-
public string Name { set; get; }
13+
public string Name { get; }
1414

1515
/// <summary>
1616
/// Checks if the name associated with this is valid<br/>
1717
/// Default is !<see cref="string.IsNullOrEmpty(string?)"/>
1818
/// </summary>
1919
/// <returns></returns>
20-
public bool IsNameValid() => !string.IsNullOrEmpty(Name);
20+
public bool IsNameValid() =>
21+
!string.IsNullOrEmpty(Name);
2122

2223
}
2324

Source/Data/INetworkArg.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
///////////////////////////////////////////////////////
2+
/// Filename: INetworkArg.cs
3+
/// Date: March 28, 2025
4+
/// Author: Maverick Liberty
5+
///////////////////////////////////////////////////////
6+
using System;
7+
8+
namespace EppNet.Data
9+
{
10+
11+
public interface INetworkArg : ICloneable<INetworkArg>, IEquatable<INetworkArg>, ISignatureEquatable<INetworkArg>
12+
{
13+
public Type Type { get; }
14+
15+
public object BoxedValue { get; }
16+
17+
public object Get() =>
18+
BoxedValue;
19+
}
20+
21+
public interface INetworkArg<TArg> : INetworkArg
22+
{
23+
public TArg Value { get; }
24+
25+
public new TArg Get() =>
26+
Value;
27+
}
28+
29+
}

Source/Data/ISignatureEquatable.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
///////////////////////////////////////////////////////
2+
/// Filename: ISignatureEquatable.cs
3+
/// Date: March 28, 2025
4+
/// Author: Maverick Liberty
5+
///////////////////////////////////////////////////////
6+
7+
namespace EppNet.Data
8+
{
9+
10+
/// <summary>
11+
/// When dealing with generics, this ensures that the types are equivalent
12+
/// </summary>
13+
/// <typeparam name="T"></typeparam>
14+
15+
public interface ISignatureEquatable<T>
16+
{
17+
18+
/// <summary>
19+
/// Checks for type equivalence
20+
/// </summary>
21+
/// <param name="other"></param>
22+
/// <returns></returns>
23+
bool SignatureEquals(T other);
24+
}
25+
26+
}

Source/Data/NetworkArg.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
///////////////////////////////////////////////////////
2+
/// Filename: NetworkArg.cs
3+
/// Date: March 28, 2025
4+
/// Author: Maverick Liberty
5+
///////////////////////////////////////////////////////
6+
7+
using System;
8+
9+
namespace EppNet.Data
10+
{
11+
12+
public sealed class NetworkArg<TArg> : INetworkArg<TArg>
13+
{
14+
15+
public TArg Value { set; get; }
16+
17+
public object BoxedValue
18+
{
19+
set
20+
{
21+
if (value is TArg arg)
22+
Value = arg;
23+
else
24+
throw new ArgumentException("arg");
25+
}
26+
27+
get => Value;
28+
}
29+
30+
public IResolver<TArg> Resolver { private set; get; }
31+
32+
public Type Type { get => typeof(TArg); }
33+
34+
public NetworkArg() { }
35+
36+
public NetworkArg(TArg value)
37+
{
38+
this.Value = value;
39+
}
40+
41+
public INetworkArg Clone() =>
42+
new NetworkArg<TArg>(Value);
43+
44+
public bool Equals(INetworkArg other) =>
45+
other is not null &&
46+
other is NetworkArg<TArg> oNetArg &&
47+
Value.Equals(oNetArg.Value);
48+
49+
public bool SignatureEquals(INetworkArg other) =>
50+
other is not null &&
51+
other is NetworkArg<TArg>;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)