Esempio n. 1
0
            public DmdTypeDef?GetTypeDef(IDmdAssemblyName?assemblyName, List <string> typeNames)
            {
                if (typeNames.Count == 0)
                {
                    return(null);
                }

                DmdModuleImpl?  targetModule   = module;
                DmdAssemblyImpl?targetAssembly = targetModule.assembly;

                if (!(assemblyName is null) && !module.assembly.AppDomainImpl.AssemblyNameEqualityComparer.Equals(targetAssembly.GetName(), assemblyName))
                {
                    targetAssembly = (DmdAssemblyImpl?)targetAssembly.AppDomain.GetAssembly(assemblyName);
                    targetModule   = (DmdModuleImpl?)targetAssembly?.ManifestModule;
                    if (targetModule is null)
                    {
                        return(null);
                    }
                }

                DmdTypeDef?type;

                DmdTypeUtilities.SplitFullName(typeNames[0], out var @namespace, out var name);

                var typeRef = new DmdParsedTypeRef(targetModule, null, DmdTypeScope.Invalid, @namespace, name, null);

                type = targetModule.GetType(typeRef, ignoreCase);

                if (type is null)
                {
                    return(null);
                }
                for (int i = 1; i < typeNames.Count; i++)
                {
                    var flags = DmdBindingFlags.Public | DmdBindingFlags.NonPublic;
                    if (ignoreCase)
                    {
                        flags |= DmdBindingFlags.IgnoreCase;
                    }
                    type = (DmdTypeDef?)type.GetNestedType(typeNames[i], flags);
                    if (type is null)
                    {
                        return(null);
                    }
                }
                return(type);
            }
Esempio n. 2
0
            public DmdTypeDef GetTypeDef(IDmdAssemblyName assemblyName, List <string> typeNames)
            {
                if (typeNames.Count == 0)
                {
                    return(null);
                }

                if (assemblyName != null && !AssemblyNameEqualityComparer.Instance.Equals(module.Assembly.GetName(), assemblyName))
                {
                    return(null);
                }

                DmdTypeDef type;

                DmdTypeUtilities.SplitFullName(typeNames[0], out string @namespace, out string name);

                var typeRef = new DmdParsedTypeRef(module, null, DmdTypeScope.Invalid, @namespace, name, null);

                type = module.GetType(typeRef, ignoreCase);

                if ((object)type == null)
                {
                    return(null);
                }
                for (int i = 1; i < typeNames.Count; i++)
                {
                    var flags = DmdBindingFlags.Public | DmdBindingFlags.NonPublic;
                    if (ignoreCase)
                    {
                        flags |= DmdBindingFlags.IgnoreCase;
                    }
                    type = (DmdTypeDef)type.GetNestedType(typeNames[i], flags);
                    if ((object)type == null)
                    {
                        return(null);
                    }
                }
                return(type);
            }