Skip to content

Commit 11dc36f

Browse files
committed
use SourceGeneration.Reflection instead of normal reflection
1 parent bd3dd12 commit 11dc36f

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

FTMS.NET.Contracts/FTMS.NET.Contracts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="DynamicData" Version="9.1.2" />
9+
<PackageReference Include="SourceGeneration.Reflection" Version="1.0.0-beta2.241113.1" PrivateAssets="All" />
910
</ItemGroup>
1011

1112
</Project>

FTMS.NET.Contracts/FtmsUuids.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace FTMS.NET;
2+
3+
using SourceGeneration.Reflection;
24
using System;
35
using System.Collections.Frozen;
4-
using System.Reflection;
56

7+
[SourceReflection]
68
public static class FtmsUuids
79
{
810
private static readonly FrozenDictionary<Guid, string> allFieldsByUuid;
@@ -26,6 +28,7 @@ public static class FtmsUuids
2628
public readonly static Guid RowerData = Guid.ParseExact("00002ad1-0000-1000-8000-00805f9b34fb", "d");
2729
public readonly static Guid IndoorBikeData = Guid.ParseExact("00002ad2-0000-1000-8000-00805f9b34fb", "d");
2830

31+
[SourceReflection]
2932
public static class IndoorBike
3033
{
3134
public static readonly Guid InstantaneousSpeed = new("765050cd-a033-4972-a71b-29c013c0845b");
@@ -49,12 +52,11 @@ static FtmsUuids()
4952
{
5053
var thisType = typeof(FtmsUuids);
5154
var guidType = typeof(Guid);
52-
allFieldsByUuid = thisType.GetNestedTypes()
53-
.Prepend(thisType)
54-
.SelectMany(type => type
55-
.GetFields(BindingFlags.Static | BindingFlags.Public)
56-
.Where(f => f.FieldType == guidType))
57-
.ToFrozenDictionary(f => (Guid)f.GetValue(null)!, f => f.Name);
55+
allFieldsByUuid = SourceReflector.GetTypes()
56+
.SelectMany(t => t.GetFieldsAndProperties()
57+
.Where(fop => fop.IsStatic && fop.Accessibility == SourceAccessibility.Public)
58+
.Where(fop => fop.MemberType == guidType))
59+
.ToFrozenDictionary(fop => (Guid)fop.GetValue(null)!, fop => fop.Name);
5860
}
5961

6062
public static string GetName(Guid uuid)

0 commit comments

Comments
 (0)