本文整理匯總了C#中Assembly.GetTypes方法的典型用法代碼示例。如果您正苦於以下問題:C# Assembly.GetTypes方法的具體用法?C# Assembly.GetTypes怎麽用?C# Assembly.GetTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Assembly
的用法示例。
在下文中一共展示了Assembly.GetTypes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DumpAsm
static void DumpAsm(Assembly asm)
{
Dictionary<string,Namespace> nss = new Dictionary<string,Namespace>();
Console.WriteLine("using System;");
Console.WriteLine("using System.Collections;");
Console.WriteLine("using System.Collections.Generic;");
Console.WriteLine("");
foreach(var t in asm.GetTypes())
{
if(!t.IsVisible || t.IsNested)
{
continue;
}
if(!nss.ContainsKey(t.Namespace))
{
nss[t.Namespace] = new Namespace(t.Namespace);
}
nss[t.Namespace].Add(t);
}
foreach(Namespace ns in nss.Values)
{
ns.Dump();
}
}
示例2: ExecuteInstanceMethod
/// <summary>
/// Execute a public method_name(args) in compiled_assembly
/// </summary>
/// <param name="compiled_assembly">compiled assembly</param>
/// <param name="methode_name">method to execute</param>
/// <param name="args">method arguments</param>
/// <returns>method execution result</returns>
public static object ExecuteInstanceMethod(Assembly compiled_assembly, string methode_name, object[] args)
{
if (compiled_assembly != null)
{
foreach (Type type in compiled_assembly.GetTypes())
{
foreach (MethodInfo method in type.GetMethods())
{
if (method.Name == methode_name)
{
if ((method != null) && (method.IsPublic))
{
object obj = Activator.CreateInstance(type, null);
return method.Invoke(obj, args);
}
else
{
throw new Exception("Cannot invoke method :" + methode_name);
}
}
}
}
}
return null;
}
示例3: ProcessAssembly
private static void ProcessAssembly(TreeIter parent, Assembly asm)
{
string asm_name = asm.GetName ().Name;
foreach (System.Type t in asm.GetTypes ()) {
UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ());
TreeIter iter = store.AppendValues (parent, t.Name, t.ToString ());
ProcessType (iter, t);
}
}
示例4: GetTypes
static Type[] GetTypes(Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
return ex.Types;
}
}
示例5: GetClassesForPredicate
/// <summary>
/// Returns all types in the given assembly satisfying the given predicate,
/// </summary>
private static List<Type> GetClassesForPredicate(Assembly assembly, Predicate<Type> predicate)
{
List<Type> result = new List<Type>();
foreach (Type t in assembly.GetTypes())
{
if (predicate.Invoke(t))
{
result.Add(t);
}
}
return result;
}
示例6: GetTypesFromAssembly
Type[] GetTypesFromAssembly(Assembly Asm)
{
Type[] AllTypesWeCanGet;
try
{
AllTypesWeCanGet = Asm.GetTypes();
}
catch(ReflectionTypeLoadException Exc)
{
AllTypesWeCanGet = Exc.Types;
}
return AllTypesWeCanGet;
}
示例7: DisplayInfo
private static void DisplayInfo(Assembly a)
{
Console.WriteLine("****** Info about Assembly ******");
Console.WriteLine("Loaded from GAC? {0}", a.GlobalAssemblyCache);
Console.WriteLine("Asm Name: {0}", a.GetName().Name);
Console.WriteLine("Asm Version: {0}", a.GetName().Version);
Console.WriteLine("Asm Culture: {0}", a.GetName().CultureInfo.DisplayName);
Console.WriteLine("\nHere are the public enums:");
// use LINQ to find public enums
Type[] types = a.GetTypes();
var publicEnums = from pe in types where pe.IsEnum &&
pe.IsPublic select pe;
foreach (var pe in publicEnums) {
Console.WriteLine(pe);
}
}
示例8: GetTypes
static int GetTypes (Assembly a)
{
try {
Type[] ts = a.GetTypes ();
Console.WriteLine ("*1* Can get all types from assembly '{0}' loaded. {1} types present.", filename, ts.Length);
return 1;
}
catch (ReflectionTypeLoadException rtle) {
Console.WriteLine ("*0* Expected ReflectionTypeLoadException\n{0}", rtle);
Console.WriteLine ("Types ({0}):", rtle.Types.Length);
for (int i=0; i < rtle.Types.Length; i++) {
Console.WriteLine ("\t{0}", rtle.Types [i]);
}
Console.WriteLine ("LoaderExceptions ({0}):", rtle.LoaderExceptions.Length);
for (int i=0; i < rtle.LoaderExceptions.Length; i++) {
Console.WriteLine ("\t{0}", rtle.LoaderExceptions [i]);
}
return 0;
}
}
示例9: GetSpecificationTypes
private static IEnumerable<Type> GetSpecificationTypes(Assembly assembly, string example, out bool foundType)
{
var exampleTypes = from exampleText in example.SomeStringOrNone()
from assemblyValue in assembly.SomeOrNone()
from exampleType in assemblyValue.GetType(exampleText).SomeOrNone()
where exampleType.IsSubclassOf(typeof (Specification))
select exampleType;
foreach (var exampleType in exampleTypes)
{
foundType = true;
return new[] {exampleType};
}
foundType = false;
try {
return from type in assembly.GetTypes() where type.IsSubclassOf(typeof(Specification)) select type;
} catch {
return Enumerable.Empty<Type>();
}
}
示例10: GetTypes
static int GetTypes (Assembly a)
{
Type[] ts = a.GetTypes ();
Console.WriteLine ("*0* Can get all types from assembly '{0}' loaded. {1} types present.", filename, ts.Length);
return 0;
}
示例11: AssemblyGen
static void AssemblyGen (Assembly a)
{
Type[] types = a.GetTypes ();
Hashtable ns_types = new Hashtable ();
foreach (Type t in types) {
if (t.IsNotPublic) {
//Console.WriteLine ("Ignoring non-public type: " + t.Name);
//warnings_ignored++;
continue;
}
if (!t.IsClass && !t.IsInterface && !t.IsEnum) {
//Console.WriteLine ("Ignoring unrecognised type: " + t.Name);
warnings_ignored++;
continue;
}
RegisterType (t);
if (t.IsEnum)
RegisterByVal (t);
string tns = t.Namespace == null ? String.Empty : t.Namespace;
if (!ns_types.Contains (tns))
ns_types[tns] = new ArrayList ();
((ArrayList) ns_types[tns]).Add (t);
}
namespaces = (string[]) (new ArrayList (ns_types.Keys)).ToArray (typeof (string));
foreach (DictionaryEntry de in ns_types)
NamespaceGen ((string) de.Key, (Type[]) ((ArrayList) de.Value).ToArray (typeof (Type)));
}
示例12: OutputAllTypesInAssembly
public static void OutputAllTypesInAssembly(Assembly asm)
{
var alltypes = asm.GetTypes();
var writer = new StreamWriter(tempFile, false, Encoding.UTF8);
writer.WriteLine("// enum");
writer.WriteLine("");
for (int i = 0; i < alltypes.Length; i++)
{
if (!alltypes[i].IsPublic && !alltypes[i].IsNestedPublic)
continue;
if (alltypes[i].IsEnum)
writer.WriteLine(alltypes[i].ToString());
}
writer.WriteLine("");
writer.WriteLine("// interface");
writer.WriteLine("");
for (int i = 0; i < alltypes.Length; i++)
{
if (!alltypes[i].IsPublic && !alltypes[i].IsNestedPublic)
continue;
if (alltypes[i].IsInterface)
writer.WriteLine(alltypes[i].ToString());
}
writer.WriteLine("");
writer.WriteLine("// class");
writer.WriteLine("");
for (int i = 0; i < alltypes.Length; i++)
{
if (!alltypes[i].IsPublic && !alltypes[i].IsNestedPublic)
continue;
if ((!alltypes[i].IsEnum && !alltypes[i].IsInterface) &&
alltypes[i].IsClass)
{
string s = alltypes[i].GetConstructors().Length.ToString()
+ "/" +
alltypes[i].GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Length.ToString();
writer.WriteLine(alltypes[i].ToString() + " " + s);
}
}
writer.WriteLine("");
writer.WriteLine("// ValueType");
writer.WriteLine("");
for (int i = 0; i < alltypes.Length; i++)
{
if (!alltypes[i].IsPublic && !alltypes[i].IsNestedPublic)
continue;
if ((!alltypes[i].IsEnum && !alltypes[i].IsInterface) &&
!alltypes[i].IsClass && alltypes[i].IsValueType)
writer.WriteLine(alltypes[i].ToString());
}
writer.Close();
Debug.Log("Output All Types in UnityEngine finish, file: " + tempFile);
return;
}
示例13: ListAssemblyInfo
// private void ListAssemblyInfo(Assembly assembly) {{{2
private void ListAssemblyInfo(Assembly assembly)
{
Info.AppendFormat("Assembly: {0}\n", assembly.FullName); // Assembly name
// Various statistics about the assembly
if (OAAssemblyStats || OTAll) {
Info.AppendFormat("\tLoaded from GAC: {0}\n", assembly.GlobalAssemblyCache);
Info.AppendFormat("\tAsm Name: {0}\n", assembly.GetName().Name);
Info.AppendFormat("\tAsm Version: {0}\n", assembly.GetName().Version);
Info.AppendFormat("\tAsm Culture: {0}\n", assembly.GetName().CultureInfo.DisplayName);
}
if (OAListTypes) {
Type[] types = assembly.GetTypes();
foreach (Type type in types)
ListTypeInfo(type);
}
}
示例14: GetTypes
public static Type[] GetTypes(Assembly assembly)
{
Requires.NotNull(assembly, "assembly");
return assembly.GetTypes();
}
示例15: PrintAssembly
private static void PrintAssembly(Assembly ass)
{
Type[] types = ass.GetTypes();
outfile.WriteLine("# This file has been autogenerated by query.exe -- DO NOT EDIT");
outfile.WriteLine("from pypy.translator.cli.query import ClassDesc");
outfile.WriteLine("types = {}");
foreach(Type t in types) {
if (IgnoreType(t))
continue;
PrintType(t);
outfile.WriteLine("types['{0}'] = desc", t.FullName);
outfile.WriteLine("del desc");
}
}