66using System . Reflection ;
77using System . Runtime . Loader ;
88using System . Text ;
9+ using MattSourceGenHelpers . Abstractions ;
910
1011namespace MattSourceGenHelpers . Generators ;
1112
@@ -60,30 +61,32 @@ internal static (SwitchBodyData? record, string? error) ExecuteFluentGeneratorMe
6061
6162 Assembly assembly = loadContext . LoadFromStream ( stream ) ;
6263
64+ string abstractionAssemblyName = typeof ( Generate ) . Assembly . GetName ( ) . Name ! ;
65+
6366 PortableExecutableReference ? abstractionsReference = compilation . References
6467 . OfType < PortableExecutableReference > ( )
6568 . FirstOrDefault ( reference => reference . FilePath is not null && string . Equals (
6669 Path . GetFileNameWithoutExtension ( reference . FilePath ) ,
67- "MattSourceGenHelpers.Abstractions" ,
70+ abstractionAssemblyName ,
6871 StringComparison . OrdinalIgnoreCase ) ) ;
6972
7073 if ( abstractionsReference ? . FilePath == null )
7174 {
72- return ( null , "Could not find MattSourceGenHelpers.Abstractions reference in compilation" ) ;
75+ return ( null , $ "Could not find { abstractionAssemblyName } reference in compilation") ;
7376 }
7477
7578 string abstractionsAssemblyPath = ResolveImplementationAssemblyPath ( abstractionsReference . FilePath ) ;
7679 Assembly abstractionsAssembly = loadContext . LoadFromAssemblyPath ( abstractionsAssemblyPath ) ;
77-
78- Type ? generatorStaticType = abstractionsAssembly . GetType ( "MattSourceGenHelpers.Abstractions.Generator" ) ;
79- Type ? recordingFactoryType = abstractionsAssembly . GetType ( "MattSourceGenHelpers.Abstractions. RecordingGeneratorsFactory" ) ;
80+
81+ Type ? generatorStaticType = abstractionsAssembly . GetType ( typeof ( Generate ) . FullName ! ) ;
82+ Type ? recordingFactoryType = abstractionsAssembly . GetType ( typeof ( RecordingGeneratorsFactory ) . FullName ! ) ;
8083 if ( generatorStaticType == null || recordingFactoryType == null )
8184 {
82- return ( null , "Could not find Generator or RecordingGeneratorsFactory types in Abstractions assembly" ) ;
85+ return ( null , $ "Could not find { typeof ( Generate ) . FullName } or { typeof ( RecordingGeneratorsFactory ) . FullName } types in Abstractions assembly") ;
8386 }
8487
8588 object ? recordingFactory = Activator . CreateInstance ( recordingFactoryType ) ;
86- PropertyInfo ? currentGeneratorProperty = generatorStaticType . GetProperty ( " CurrentGenerator" , BindingFlags . Public | BindingFlags . Static ) ;
89+ PropertyInfo ? currentGeneratorProperty = generatorStaticType . GetProperty ( nameof ( Generate . CurrentGenerator ) , BindingFlags . Public | BindingFlags . Static ) ;
8790 currentGeneratorProperty ? . SetValue ( null , recordingFactory ) ;
8891
8992 string typeName = generatorMethod . ContainingType . ToDisplayString ( ) ;
@@ -101,7 +104,7 @@ internal static (SwitchBodyData? record, string? error) ExecuteFluentGeneratorMe
101104
102105 generatorMethodInfo . Invoke ( null , null ) ;
103106
104- PropertyInfo ? lastRecordProperty = recordingFactoryType . GetProperty ( " LastRecord" ) ;
107+ PropertyInfo ? lastRecordProperty = recordingFactoryType . GetProperty ( nameof ( RecordingGeneratorsFactory . LastRecord ) ) ;
105108 object ? lastRecord = lastRecordProperty ? . GetValue ( recordingFactory ) ;
106109 if ( lastRecord == null )
107110 {
0 commit comments