src/TypeCatalogGen/TypeCatalogGen.cs
/// <summary>
/// Generate the CSharp source code that initialize the type catalog.
/// </summary>
Generate the CSharp source code that initialize the type catalog.
Generate the CSharp source code that initialize the type catalog .
private static void WritePowerShellAssemblyLoadContextPartialClass(string targetFilePath, Dictionary<string, string> typeNameToAssemblyMap)
        {
            const string SourceFormat = "            typeCatalog[\"{0}\"] = \"{1}\";";
            const string SourceHead = @"//
// This file is auto-generated by TypeCatalogGen.exe during build of Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
// This file will be compiled into Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
//
// In CoreCLR, there is no way to get all loaded TPA assemblies (.NET Framework Assemblies). In order to get type based on type 
// name, powershell needs to know what .NET types are available and in which TPA assemblies. So we have to generate this type
// catalog based on the reference assemblies of .NET Core.
//
using System.Collections.Generic;
using System.Runtime.Loader;
namespace System.Management.Automation
{{
    internal partial class PowerShellAssemblyLoadContext : AssemblyLoadContext
    {{
        private Dictionary<string, string> InitializeTypeCatalog()
        {{
            Dictionary<string, string> typeCatalog = new Dictionary<string, string>({0}, StringComparer.OrdinalIgnoreCase);
";
            const string SourceEnd = @"
            return typeCatalog;
        }
    }
}
";
            StringBuilder sourceCode = new StringBuilder(string.Format(CultureInfo.InvariantCulture, SourceHead, typeNameToAssemblyMap.Count));
            foreach (KeyValuePair<string, string> pair in typeNameToAssemblyMap)
            {
                sourceCode.AppendLine(string.Format(CultureInfo.InvariantCulture, SourceFormat, pair.Key, pair.Value));
            }
            sourceCode.Append(SourceEnd);
            using (FileStream stream = new FileStream(targetFilePath, FileMode.Create, FileAccess.Write))
            using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII))
            {
                writer.Write(sourceCode.ToString());
            }
        }
private static void WritePowerShellAssemblyLoadContextPartialClass ( string targetFilePath , Dictionary < string , string > typeNameToAssemblyMap ) { const string SourceFormat = " \" \" \" \" " ; const string SourceHead = @"//
// This file is auto-generated by TypeCatalogGen.exe during build of Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
// This file will be compiled into Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
//
// In CoreCLR, there is no way to get all loaded TPA assemblies (.NET Framework Assemblies). In order to get type based on type 
// name, powershell needs to know what .NET types are available and in which TPA assemblies. So we have to generate this type
// catalog based on the reference assemblies of .NET Core.
//
using System.Collections.Generic;
using System.Runtime.Loader;

namespace System.Management.Automation
{{
    internal partial class PowerShellAssemblyLoadContext : AssemblyLoadContext
    {{
        private Dictionary<string, string> InitializeTypeCatalog()
        {{
            Dictionary<string, string> typeCatalog = new Dictionary<string, string>({0}, StringComparer.OrdinalIgnoreCase);
" ; const string SourceEnd = @"
            return typeCatalog;
        }
    }
}
" ; StringBuilder sourceCode = new StringBuilder ( string . Format ( CultureInfo . InvariantCulture , SourceHead , typeNameToAssemblyMap . Count ) ) ; foreach ( KeyValuePair < string , string > pair in typeNameToAssemblyMap ) { sourceCode . AppendLine ( string . Format ( CultureInfo . InvariantCulture , SourceFormat , pair . Key , pair . Value ) ) ; } sourceCode . Append ( SourceEnd ) ; using ( FileStream stream = new FileStream ( targetFilePath , FileMode . Create , FileAccess . Write ) ) using ( StreamWriter writer = new StreamWriter ( stream , Encoding . ASCII ) ) { writer . Write ( sourceCode . ToString ( ) ) ; } }
Generate the CSharp source code that initialize the type catalog.
Generate the CSharp source code that initialize the type catalog .
targetFilePath
string
typeNameToAssemblyMap
Dictionary<string, string>