internal static Assembly LoadFrom(string assemblyPath) { #if CORECLR return(PSAssemblyLoadContext.LoadFrom(assemblyPath)); #else return(Assembly.LoadFrom(assemblyPath)); #endif }
/// <summary> /// Facade for AppDomain.GetAssemblies /// </summary> /// <param name="namespaceQualifiedTypeName"> /// In CoreCLR context, if it's for string-to-type conversion and the namespace qualified type name is known, pass it in so that /// powershell can load the necessary TPA if the target type is from an unloaded TPA. /// </param> internal static IEnumerable <Assembly> GetAssemblies(string namespaceQualifiedTypeName = null) { #if CORECLR return(PSAssemblyLoadContext.GetAssemblies(namespaceQualifiedTypeName)); #else return(AppDomain.CurrentDomain.GetAssemblies().Where(a => !(a.FullName.Length > 0 && a.FullName[0] == FIRST_CHAR_PSASSEMBLY_MARK))); #endif }
/// <summary> /// Probe (look for) the assembly file with the specified short name. /// </summary> /// <remarks> /// In Core PowerShell, we need to analyze the metadata of assembly files for binary modules. Sometimes we /// need to find an assembly file that is referenced by the assembly file that is being processed. To find /// the reference assembly file, we need to probe the PSBase and the additional searching path if it's specified. /// </remarks> internal static string ProbeAssemblyPath(string assemblyShortName, string additionalSearchPath = null) { if (string.IsNullOrWhiteSpace(assemblyShortName)) { throw new ArgumentNullException("assemblyShortName"); } return(PSAssemblyLoadContext.ProbeAssemblyFileForMetadataAnalysis(assemblyShortName, additionalSearchPath)); }
/// <summary> /// Facade for EnumBuilder.CreateTypeInfo /// </summary> /// <remarks> /// In Core PowerShell, we need to track the dynamic assemblies that powershell generates. /// </remarks> internal static void CreateEnumType(EnumBuilder enumBuilder) { #if CORECLR // Create the enum type and add the dynamic assembly to assembly cache. TypeInfo enumTypeinfo = enumBuilder.CreateTypeInfo(); PSAssemblyLoadContext.TryAddAssemblyToCache(enumTypeinfo.Assembly); #else enumBuilder.CreateTypeInfo(); #endif }
/// <summary> /// Facade for AppDomain.GetAssemblies /// </summary> /// <param name="namespaceQualifiedTypeName"> /// In CoreCLR context, if it's for string-to-type conversion and the namespace qualified type name is known, pass it in so that /// powershell can load the necessary TPA if the target type is from an unloaded TPA. /// </param> internal static IEnumerable <Assembly> GetAssemblies(string namespaceQualifiedTypeName = null) { return(PSAssemblyLoadContext.GetAssembly(namespaceQualifiedTypeName) ?? AppDomain.CurrentDomain.GetAssemblies().Where(a => !TypeDefiner.DynamicClassAssemblyName.Equals(a.GetName().Name, StringComparison.Ordinal))); }
/// <summary> /// Load assembly from byte stream. /// </summary> internal static Assembly LoadFrom(Stream assembly) { return(PSAssemblyLoadContext.LoadFrom(assembly)); }
/// <summary> /// Get the namespace-qualified type names of all available CoreCLR .NET types. /// This is used for type name auto-completion in PS engine. /// </summary> internal static IEnumerable <string> GetAvailableCoreClrDotNetTypes() { return(PSAssemblyLoadContext.GetAvailableDotNetTypes()); }
/// <summary> /// Facade for AppDomain.GetAssemblies. /// </summary> /// <param name="namespaceQualifiedTypeName"> /// In CoreCLR context, if it's for string-to-type conversion and the namespace qualified type name is known, pass it in so that /// powershell can load the necessary TPA if the target type is from an unloaded TPA. /// </param> internal static IEnumerable <Assembly> GetAssemblies(string namespaceQualifiedTypeName = null) { return(PSAssemblyLoadContext.GetAssembly(namespaceQualifiedTypeName) ?? GetPSVisibleAssemblies()); }
/// <summary> /// Facade for AppDomain.GetAssemblies. /// </summary> /// <param name="namespaceQualifiedTypeName"> /// In CoreCLR context, if it's for string-to-type conversion and the namespace qualified type name is known, pass it in so that /// powershell can load the necessary TPA if the target type is from an unloaded TPA. /// </param> internal static IEnumerable <Assembly> GetAssemblies(string namespaceQualifiedTypeName = null) { return(PSAssemblyLoadContext.GetAssembly(namespaceQualifiedTypeName) ?? AssemblyLoadContext.Default.Assemblies.Where(a => !a.FullName.StartsWith(TypeDefiner.DynamicClassAssemblyFullNamePrefix, StringComparison.Ordinal))); }