Exemple #1
0
        public override Type?GetType(string name, bool throwOnError, bool ignoreCase)
        {
            // throw on null strings regardless of the value of "throwOnError"
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            RuntimeType?        type      = null;
            object?             keepAlive = null;
            AssemblyLoadContext?assemblyLoadContextStack = AssemblyLoadContext.CurrentContextualReflectionContext;

            RuntimeAssembly runtimeAssembly = this;

            GetType(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly),
                    name,
                    throwOnError,
                    ignoreCase,
                    JitHelpers.GetObjectHandleOnStack(ref type),
                    JitHelpers.GetObjectHandleOnStack(ref keepAlive),
                    JitHelpers.GetObjectHandleOnStack(ref assemblyLoadContextStack));
            GC.KeepAlive(keepAlive);

            return(type);
        }
Exemple #2
0
        // Returns the load context in which the specified assembly has been loaded
        public static AssemblyLoadContext?GetLoadContext(Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            AssemblyLoadContext?loadContextForAssembly = null;

            RuntimeAssembly?rtAsm = assembly as RuntimeAssembly;

            // We only support looking up load context for runtime assemblies.
            if (rtAsm != null)
            {
                RuntimeAssembly runtimeAssembly        = rtAsm;
                IntPtr          ptrAssemblyLoadContext = GetLoadContextForAssembly(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly));
                if (ptrAssemblyLoadContext == IntPtr.Zero)
                {
                    // If the load context is returned null, then the assembly was bound using the TPA binder
                    // and we shall return reference to the active "Default" binder - which could be the TPA binder
                    // or an overridden CLRPrivBinderAssemblyLoadContext instance.
                    loadContextForAssembly = AssemblyLoadContext.Default;
                }
                else
                {
                    loadContextForAssembly = (AssemblyLoadContext)(GCHandle.FromIntPtr(ptrAssemblyLoadContext).Target) !;
                }
            }

            return(loadContextForAssembly);
        }
Exemple #3
0
        internal string?GetCodeBase(bool copiedName)
        {
            string?         codeBase        = null;
            RuntimeAssembly runtimeAssembly = this;

            GetCodeBase(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), copiedName, JitHelpers.GetStringHandleOnStack(ref codeBase));
            return(codeBase);
        }
Exemple #4
0
        public override Module?GetModule(string name)
        {
            Module?         retModule       = null;
            RuntimeAssembly runtimeAssembly = this;

            GetModule(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), name, JitHelpers.GetObjectHandleOnStack(ref retModule));
            return(retModule);
        }
Exemple #5
0
        public override Type[] GetExportedTypes()
        {
            Type[]? types = null;
            RuntimeAssembly runtimeAssembly = this;

            GetExportedTypes(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetObjectHandleOnStack(ref types));
            return(types !);
        }
        internal static IntPtr LoadLibraryByName(string libraryName, Assembly assembly, DllImportSearchPath?searchPath, bool throwOnError)
        {
            RuntimeAssembly rtAsm = (RuntimeAssembly)assembly;

            return(LoadByName(libraryName,
                              JitHelpers.GetQCallAssemblyOnStack(ref rtAsm),
                              searchPath.HasValue,
                              (uint)searchPath.GetValueOrDefault(),
                              throwOnError));
        }
Exemple #7
0
        public unsafe override Stream?GetManifestResourceStream(string name)
        {
            uint            length             = 0;
            RuntimeAssembly runtimeAssembly    = this;
            byte *          pbInMemoryResource = GetResource(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), name, out length);

            if (pbInMemoryResource != null)
            {
                return(new ManifestResourceStream(this, pbInMemoryResource, length, length, FileAccess.Read));
            }

            return(null);
        }
Exemple #8
0
        public override ManifestResourceInfo?GetManifestResourceInfo(string resourceName)
        {
            RuntimeAssembly?retAssembly     = null;
            string?         fileName        = null;
            RuntimeAssembly runtimeAssembly = this;
            int             location        = GetManifestResourceInfo(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), resourceName,
                                                                      JitHelpers.GetObjectHandleOnStack(ref retAssembly),
                                                                      JitHelpers.GetStringHandleOnStack(ref fileName));

            if (location == -1)
            {
                return(null);
            }

            return(new ManifestResourceInfo(retAssembly !, fileName !,
                                            (ResourceLocation)location));
        }
Exemple #9
0
        [CLSCompliant(false)] // out byte* blob
        public static unsafe bool TryGetRawMetadata(this Assembly assembly, out byte *blob, out int length)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            blob = null;

            length = 0;

            var runtimeAssembly = assembly as RuntimeAssembly;

            if (runtimeAssembly == null)
            {
                return(false);
            }

            RuntimeAssembly rtAsm = runtimeAssembly;

            return(InternalTryGetRawMetadata(JitHelpers.GetQCallAssemblyOnStack(ref rtAsm), ref blob, ref length));
        }