@@ -1080,6 +1080,59 @@ public virtual (string, SerializedType, SerializedType)? DataTypeFromImportName(
10801080 public virtual void WriteMetadata ( Program program , string path )
10811081 {
10821082 }
1083+
1084+ /// <summary>
1085+ /// Helper method used to obtain an <see cref="IPlatform"/> implementation,
1086+ /// given an optional override.
1087+ /// </summary>
1088+ /// <param name="services"><see cref="IServiceProvider"/> instance to use.</param>
1089+ /// <param name="platform"><see cref="IPlatform"/> instance to use if no <paramref name="sPlatformOverride" />
1090+ /// <param name="sPlatformOverride">Name of platform to use. If null, the method falls
1091+ /// back to using the provided <paramref name="platform"/>.</param>
1092+ /// is provided.</param>
1093+ /// <param name="arch">Processor architecture to use when obtaining the <see cref="IPlatform"/>
1094+ /// instance</param>
1095+ /// <returns>An <see cref="IPlatform"/> instance.</returns>
1096+ public static IPlatform Load (
1097+ IServiceProvider services ,
1098+ IPlatform ? platform ,
1099+ string ? sPlatformOverride ,
1100+ IProcessorArchitecture arch )
1101+ {
1102+ if ( string . IsNullOrWhiteSpace ( sPlatformOverride ) && platform is not null )
1103+ return platform ;
1104+ var cfgSvc = services . RequireService < IConfigurationService > ( ) ;
1105+ var platform2 = cfgSvc . GetEnvironment ( sPlatformOverride )
1106+ . Load ( services , arch ) ;
1107+ return platform2 ;
1108+ }
1109+
1110+ /// <summary>
1111+ /// Helper method used to obtain an <see cref="IPlatform"/> implementation,
1112+ /// given an optional override.
1113+ /// </summary>
1114+ /// <param name="services"><see cref="IServiceProvider"/> instance to use.</param>
1115+ /// <param name="sPlatform">Name of the platform to use if no <paramref name="sPlatformOverride" /> was provided.
1116+ /// </param>
1117+ /// <param name="sPlatformOverride">Name of platform to use. If null, the method falls
1118+ /// back to using the provided <paramref name="sPlatform"/>.</param>
1119+ /// <param name="arch">Processor architecture to use when obtaining the <see cref="IPlatform"/>
1120+ /// instance</param>
1121+ /// <returns>An <see cref="IPlatform"/> instance.</returns>
1122+ public static IPlatform Load (
1123+ IServiceProvider services ,
1124+ string ? sPlatform ,
1125+ string ? sPlatformOverride ,
1126+ IProcessorArchitecture arch )
1127+ {
1128+ if ( ! string . IsNullOrWhiteSpace ( sPlatformOverride ) )
1129+ sPlatform = sPlatformOverride ;
1130+ var cfgSvc = services . RequireService < IConfigurationService > ( ) ;
1131+ var platform = cfgSvc . GetEnvironment ( sPlatform )
1132+ . Load ( services , arch ) ;
1133+ return platform ;
1134+ }
1135+
10831136 }
10841137
10851138 /// <summary>
0 commit comments