本文整理匯總了C#中Assembly.GetModules方法的典型用法代碼示例。如果您正苦於以下問題:C# Assembly.GetModules方法的具體用法?C# Assembly.GetModules怎麽用?C# Assembly.GetModules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Assembly
的用法示例。
在下文中一共展示了Assembly.GetModules方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AssemblyLoader
internal AssemblyLoader(Assembly assembly)
{
this.assembly = assembly;
modules = assembly.GetModules(false);
isJavaModule = new bool[modules.Length];
for (int i = 0; i < modules.Length; i++)
{
object[] attr = AttributeHelper.GetJavaModuleAttributes(modules[i]);
if (attr.Length > 0)
{
isJavaModule[i] = true;
foreach (JavaModuleAttribute jma in attr)
{
string[] map = jma.GetClassMap();
if (map != null)
{
if (nameMap == null)
{
nameMap = new Dictionary<string, string>();
}
for (int j = 0; j < map.Length; j += 2)
{
string key = map[j];
string val = map[j + 1];
// TODO if there is a name clash between modules, this will throw.
// Figure out how to handle that.
nameMap.Add(key, val);
}
}
string[] jars = jma.Jars;
if (jars != null)
{
if (jarList == null)
{
jarList = jars;
}
else
{
string[] newList = new string[jarList.Length + jars.Length];
Array.Copy(jarList, newList, jarList.Length);
Array.Copy(jars, 0, newList, jarList.Length, jars.Length);
jarList = newList;
}
}
}
}
else
{
hasDotNetModule = true;
}
}
}
示例2: AssemblyLoader
internal AssemblyLoader(Assembly assembly)
{
this.assembly = assembly;
modules = assembly.GetModules(false);
isJavaModule = new bool[modules.Length];
for (int i = 0; i < modules.Length; i++)
{
object[] attr;
try
{
attr = AttributeHelper.GetJavaModuleAttributes(modules[i]);
}
catch (Exception x)
{
// HACK we handle exceptions here, because there is at least one obfuscator that produces
// invalid assemblies that cause Module.GetCustomAttributes() to throw an exception
JVM.CriticalFailure("Unexpected exception", x);
throw null;
}
if (attr.Length > 0)
{
isJavaModule[i] = true;
foreach (JavaModuleAttribute jma in attr)
{
string[] map = jma.GetClassMap();
if (map != null)
{
if (nameMap == null)
{
nameMap = new Dictionary<string, string>();
}
for (int j = 0; j < map.Length; j += 2)
{
string key = map[j];
string val = map[j + 1];
// TODO if there is a name clash between modules, this will throw.
// Figure out how to handle that.
nameMap.Add(key, val);
}
}
}
}
else
{
hasDotNetModule = true;
}
}
}
示例3: Print
static void Print(Assembly assembly)
{
Console.WriteLine("Assembly: "+assembly.FullName+"/"+assembly.GetName());
foreach (string s in assembly.GetManifestResourceNames())
{
Console.WriteLine("Resource: "+s);
}
foreach (AssemblyName a in assembly.GetReferencedAssemblies())
{
Console.WriteLine("ReferencedAssembly: "+a.Name);
}
foreach (Module m in assembly.GetModules())
{
Console.WriteLine("Module: "+m);
foreach (Type t in m.GetTypes())
{
Console.WriteLine("Type: "+t);
foreach (MemberInfo mi in t.GetMembers())
{
Console.WriteLine(String.Format("\t{0}: {1} ", mi.MemberType, mi.Name));
}
}
}
}
示例4: GetModules
public static Module[] GetModules(Assembly assembly)
{
Requires.NotNull(assembly, "assembly");
return assembly.GetModules();
}
示例5: PrintAssembly
void PrintAssembly(Assembly asm)
{
// assembly name
AssemblyName[] asms = asm.GetReferencedAssemblies();
// Pre-Load the referenced assemblies first
// user can specify customerized reference through /asmpath option
foreach (AssemblyName a in asms)
{
if (TryLoadAssembly(a) == null)
{
throw new ApplicationException("Fail to Find " + a.Name);
}
}
Console.WriteLine("Loaded Assemblies");
Assembly[] asmss = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies();
foreach (Assembly assembly in asmss)
Console.WriteLine(assembly);
Array.Sort(asms, sc);
foreach (AssemblyName a in asms)
PrintAssemblyName(null, a, true);
PrintAssemblyName(asm, asm.GetName(), false);
// module
Module amod = asm.ManifestModule;
Module[] mods = asm.GetModules(true);
Array.Sort(mods, sc);
foreach (Module mod in mods)
{
if (!mod.Name.Equals(amod.Name))
sw.WriteLine(".module manifest " + mod.Name);
else if (!mod.IsResource())
sw.WriteLine(".module " + mod.Name);
else sw.WriteLine(".resource " + mod.Name);
PrintCustomAttributes(CustomAttributeData.GetCustomAttributes(mod));
}
// file
FileStream[] files = asm.GetFiles();
Array.Sort(files, sc);
foreach (FileStream file in files)
sw.WriteLine(".file " + Path.GetFileName(file.Name)); // TODO seems the file api has provided less than CLI such as hashcode
// .subsystem (Console or UI)We cannot get it from reflection
// .corflags ( 64, 32 or IL platforms)
PortableExecutableKinds PEKind = (PortableExecutableKinds)0;
ImageFileMachine Machine = (ImageFileMachine)0;
asm.ManifestModule.GetPEKind(out PEKind, out Machine);
sw.WriteLine(".pekind " + PEKind);
sw.WriteLine(".imageMachine " + Machine);
// .class
Type[] ts = amod.GetTypes();
Array.Sort(ts, sc);
foreach (Type t in ts)
PrintType(t, false);
// .field and .method (only the manifest module ... )
FieldInfo[] fis = amod.GetFields(bf);
Array.Sort(fis, sc);
foreach (FieldInfo fi in fis) // global fields
PrintField(fi);
MethodInfo[] mis = amod.GetMethods(bf);
Array.Sort(mis, sc);
foreach (MethodInfo mi in mis) // global methods
PrintMethod(mi);
Console.WriteLine("Loaded Assemblies");
asmss = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies();
foreach (Assembly assembly in asmss)
Console.WriteLine(assembly);
}