Beispiel #1
0
        /// <inheritdoc/>
        public AssemblyRef FindAssemblyRef(TypeRef nonNestedTypeRef)
        {
            var modAsm = module.Assembly;

            if (modAsm != null)
            {
                var type = modAsm.Find(nonNestedTypeRef);
                if (type != null)
                {
                    return(module.UpdateRowId(new AssemblyRefUser(modAsm)));
                }
            }
            else if (module.Find(nonNestedTypeRef) != null)
            {
                return(AssemblyRef.CurrentAssembly);
            }

            var corLibAsm = module.Context.AssemblyResolver.Resolve(module.CorLibTypes.AssemblyRef, module);

            if (corLibAsm != null)
            {
                var type = corLibAsm.Find(nonNestedTypeRef);
                if (type != null)
                {
                    return(module.CorLibTypes.AssemblyRef);
                }
            }

            if (modAsm != null)
            {
                return(module.UpdateRowId(new AssemblyRefUser(modAsm)));
            }
            return(AssemblyRef.CurrentAssembly);
        }
        ITypeDefOrRef CreateCorLibTypeRef(bool isCorLib, string name)
        {
            var tr = new TypeRefUser(module, "System", name, corLibAssemblyRef);

            if (isCorLib)
            {
                var td = module.Find(tr);
                if (td != null)
                {
                    return(td);
                }
            }
            return(module.UpdateRowId(tr));
        }