本文整理汇总了C#中System.Reflection.Assembly.GetModules方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetModules方法的具体用法?C# Assembly.GetModules怎么用?C# Assembly.GetModules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetModules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAsseblyMetadata
private static MetadataTables[] GetAsseblyMetadata(Assembly assembly)
{
if (_metadataCache == null) {
_metadataCache = new Dictionary<Assembly, MetadataTables[]>();
}
lock (_metadataCache) {
MetadataTables[] metadata;
if (!_metadataCache.TryGetValue(assembly, out metadata)) {
var modules = assembly.GetModules(false);
metadata = new MetadataTables[modules.Length];
int i = 1;
foreach (var module in modules) {
var tables = MetadataTables.OpenModule(module);
if (tables.AssemblyDef.Record.IsNull) {
metadata[i++] = MetadataTables.OpenModule(module);
} else {
metadata[0] = tables;
}
}
_metadataCache.Add(assembly, metadata);
}
return metadata;
}
}
示例2: OnAssemblyLoaded
internal void OnAssemblyLoaded(Assembly assembly)
{
foreach (var module in assembly.GetModules()) {
NamespaceTree tree = new NamespaceTree();
tree.Add(module.GetMetadataTables());
ObjectModule.AddClrModules(tree.Root);
}
}
示例3: ImportAssembly
public void ImportAssembly(Assembly assembly)
{
var module = assembly.GetModules();
foreach (var m in module)
{
ImportModule(m);
}
}
示例4: RegisterAssembly
public static void RegisterAssembly(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
foreach (Module module in assembly.GetModules())
{
RegisterModule(module);
}
}
示例5: LoadInstallInfosFromAssembly
/// <summary>
/// 加载服务安装信息
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public ServiceInstallInfoListModel LoadInstallInfosFromAssembly(Assembly assembly)
{
ServiceInstallInfoListModel retVal = new ServiceInstallInfoListModel();
List<Module> moduleList = new List<Module>(assembly.GetModules());
List<ServiceInstaller> serviceInstallerList;
List<ServiceProcessInstaller> serviceProcessInstallerList;
this.LoadInstallInfosFromModuleList(moduleList, out serviceInstallerList, out serviceProcessInstallerList);
List<ServiceInstallInfo> installInfoList = this.GetInstallInfoList(assembly, serviceInstallerList, serviceProcessInstallerList);
retVal.ServiceInstallInfos = installInfoList.ToArray();
return retVal;
}
示例6: LoadCommands
private static IEnumerable<ICommand> LoadCommands(Assembly assembly)
{
List<ICommand> retVal = new List<ICommand>(5);
Module[] modules = assembly.GetModules(false);
foreach (Module module in modules)
{
retVal.AddRange(HandleModule(module));
}
return retVal;
}
示例7: CheckAssembly
private static void CheckAssembly(Assembly asm)
{
_checkedAssemblies.Add(asm.FullName);
if (_isVerbose)
{
WriteLine(ConsoleColor.Cyan, "Checking assembly: " + asm.FullName);
}
try
{
foreach (var module in asm.GetModules())
{
if (_isVerbose)
{
Console.WriteLine("\t" + module.ToString());
}
foreach (var type in module.GetTypes())
{
if (_isVerbose)
{
Console.WriteLine("\t\t" + type.ToString());
}
}
}
}
catch (Exception exception)
{
WriteException(asm.FullName, exception);
throw;
}
foreach (var name in asm.GetReferencedAssemblies())
{
if (!_checkedAssemblies.Contains(name.FullName))
{
Assembly assembly = null;
try
{
assembly = Assembly.Load(name.FullName);
}
catch (Exception exception2)
{
WriteException((assembly == null) ? name.FullName : assembly.FullName, exception2);
throw;
}
CheckAssembly(assembly);
}
}
}
示例8: GetStaticExecuteMethod
/// <summary>
/// 得到所给汇编中所有具有<see cref="ExecuteAttribute"/>特性的静态方法
/// </summary>
public static List<MethodInfo> GetStaticExecuteMethod(Assembly assembly)
{
var ret = new List<MethodInfo>();
foreach (Module module in assembly.GetModules())
{
foreach (Type type in module.GetTypes())
{
ret.AddRange(GetStaticExecuteMethod(type));
}
}
return ret;
}
示例9: RegisterCommands
public static void RegisterCommands(Assembly assembly)
{
lock(commands_)
{
foreach(Module module in assembly.GetModules())
{
foreach(Type command in module.FindTypes(TpmCommandFilter, null))
{
TPMCommandsAttribute pattr = (TPMCommandsAttribute)Attribute.GetCustomAttribute(command, typeof(TPMCommandsAttribute));
if(!commands_.Keys.Contains(pattr.CommandName))
commands_.Add(pattr.CommandName, command);
}
}
}
}
示例10: AnalyzeAssembly
public static void AnalyzeAssembly(Assembly assembly)
{
Console.WriteLine("程序集名称:" + assembly.FullName);
Console.WriteLine("程序集位置:" + assembly.Location);
Console.WriteLine("程序集是否在GAC中:" + assembly.GlobalAssemblyCache.ToString());
Console.WriteLine("包含程序集的模块名" +
assembly.ManifestModule.Name);
Console.WriteLine("运行程序集需要的CLR版本:" +
assembly.ImageRuntimeVersion);
Console.WriteLine("现在开始分析程序集中的模块");
Module[] modules = assembly.GetModules();
foreach (Module module in modules)
{
AnalyzeModule(module);
}
}
示例11: ExploreAssembly
private static void ExploreAssembly(Assembly assembly)
{
Console.WriteLine("Modules in the assembly:");
foreach (Module module in assembly.GetModules())
{
Console.WriteLine("{0}", module);
foreach (Type type in module.GetTypes())
{
Console.WriteLine("t{0}", type.Name);
foreach (MethodInfo info in type.GetMethods())
{
Console.WriteLine("tt{0}", info.Name);
}
}
}
}
示例12: AddAssemblyToView
private void AddAssemblyToView(Assembly a)
{
if (a != null)
{
PlugTemplateDumper.Dump(a);
try
{
TreeNode nd = new AssemblyTreeNode(a);
treeView1.Nodes.Add(nd);
foreach (Module md in a.GetModules())
{
LoadModule(nd, md);
}
treeView1.Sort();
}
catch {}
}
}
示例13: ResolveModule
public static Module ResolveModule(Assembly assembly, int metadataToken)
{
Assumes.NotNull(assembly);
Assumes.IsTrue(metadataToken != 0);
// TODO: This likely cause all modules in the assembly to be loaded
// perhaps we should load via file name (how will that work on SL)?
foreach (Module module in assembly.GetModules())
{
if (module.MetadataToken == metadataToken)
{
return module;
}
}
Assumes.Fail("");
return null;
}
示例14: Reflect
/// <summary>
/// Reflect informormation about assembly
/// </summary>
/// <param name="asm">Current assembly</param>
/// <returns>Information about current assembly</returns>
public static string Reflect(Assembly asm)
{
string res = "";
foreach (Module m in asm.GetModules())
{
res += String.Format("{0}:\n", m.Name);
foreach (Type t in m.GetTypes())
{
string mods = "";
if (t.IsPublic) mods += "public ";
else if (t.IsNotPublic) mods += "private ";
else mods += "internal ";
if (t.IsSealed) mods += "sealed ";
if (t.IsAbstract && !t.IsInterface) mods += "abstract ";
if (t.IsClass) mods += "class ";
if (t.IsEnum) mods += "enum ";
if (t.IsInterface) mods += "interface ";
res += String.Format("\n{0}{1}\n", mods, t.Name);
bool hasMethods = false;
foreach (MethodInfo mi in t.GetMethods())
if (mi.DeclaringType == t)
{
hasMethods = true;
string n = mi.Name;
string mmods = "";
if (mi.IsPublic) mmods += "public ";
if (mi.IsPrivate) mmods += "private ";
if (mi.IsConstructor) mmods += "constructor ";
if (mi.IsGenericMethod) n += "<>";
if (mi.IsStatic) mmods += "static ";
if (mi.IsVirtual) mmods += "virtual ";
List<string> prms = new List<string>();
foreach (ParameterInfo pi in mi.GetParameters())
prms.Add(pi.ParameterType.Name);
res += String.Format("\t{0}{1} {2}({3})\n", mmods, mi.ReturnType.Name, n, string.Join(", ", prms));
}
if (hasMethods)
res += "\n";
}
}
res += "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
return res;
}
示例15: LoadAssembly
static public void LoadAssembly()
{
try
{
if (asm == null)
{
try
{
asm = Assembly.LoadWithPartialName("Npgsql");
Module[] mods = asm.GetModules(false);
mod = mods[0];
}
catch
{
throw new Exception("Make sure the Npgsql.dll is registered in the Gac or is located in the MyGeneration folder.");
}
}
}
catch { }
}