本文整理匯總了C#中Assembly.GetExportedTypes方法的典型用法代碼示例。如果您正苦於以下問題:C# Assembly.GetExportedTypes方法的具體用法?C# Assembly.GetExportedTypes怎麽用?C# Assembly.GetExportedTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Assembly
的用法示例。
在下文中一共展示了Assembly.GetExportedTypes方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddTypes
/// <summary>
/// Adds all the exported (public) types in the given assembly to the scope of used types.
/// </summary>
public static void AddTypes(this IStringlyScope scope, Assembly assembly)
{
foreach (var type in assembly.GetExportedTypes())
{
scope.AddType(type);
}
}
示例2: LoadAllTypes
static public ArrayList LoadAllTypes(Assembly assembly)
{
Type []types = assembly.GetExportedTypes();
ArrayList typeList = new ArrayList();
foreach(Type type in types)
{
typeList.Add(type);
}
return typeList;
}
示例3: AnalyzeAssembly
static void AnalyzeAssembly(Assembly a)
{
Regex re=new Regex(@".*`\d+");
Type[] types=a.GetExportedTypes();
foreach (Type t in types) {
if (!re.IsMatch(t.Name)) {
Console.WriteLine(t.Name);
PropertyInfo[] api=t.GetProperties(BindingFlags.Instance|BindingFlags.Public|BindingFlags.Static);
foreach (PropertyInfo pi in api)
if (!re.IsMatch(pi.Name))
Console.WriteLine("{0}",pi.Name);
MethodInfo[] ami=t.GetMethods(BindingFlags.Instance|BindingFlags.Public|BindingFlags.Static);
foreach (MethodInfo mi in ami)
if (!re.IsMatch(mi.Name) && !mi.IsSpecialName) {
Console.Write("{0}(",mi.Name);
ParameterInfo[] apai=mi.GetParameters();
bool bFirst=true;
foreach (ParameterInfo pai in apai) {
if (!bFirst) Console.Write(",");
Console.Write("{0} {1}",
dic.ContainsKey(pai.ParameterType.FullName)?dic[pai.ParameterType.FullName]:pai.ParameterType.Name,
pai.Name);
bFirst=false;
}
Console.WriteLine(")");
}
EventInfo[] aei=t.GetEvents(BindingFlags.Instance|BindingFlags.Public|BindingFlags.Static);
foreach (EventInfo ei in aei) {
Console.WriteLine(ei.Name);
}
}
}
}
示例4: RunScript
private int RunScript(Assembly script, int param)
{
//every class
if (script == null)
{
return -3;
}
foreach (Type type in script.GetExportedTypes())
{
//every interface
foreach (Type iface in type.GetInterfaces())
{
//There was a script interface:
ConstructorInfo construct = type.GetConstructor(System.Type.EmptyTypes);
if (construct != null && construct.IsPublic)
{
ScriptingInterface.IEdgeScript scriptObject = construct.Invoke(null) as ScriptingInterface.IEdgeScript;
if (scriptObject != null)
{
return scriptObject.RunScript(param);
}
else
{
Messages.Add("[E] - Unable to run assembly: " + type.FullName);
}
}
else
{
Messages.Add("[E] - Unable to run script, there was no valid constructor. Constructors cannot take arguments. " + type.FullName);
}
}
}
return -1; //nothing was run at all
}
示例5: ObsoleteMethods
private static void ObsoleteMethods(Assembly assembly) {
var query =
from type in assembly.GetExportedTypes().AsParallel()
from method in type.GetMethods(BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static)
let obsoleteAttrType = typeof(ObsoleteAttribute)
where Attribute.IsDefined(method, obsoleteAttrType)
orderby type.FullName
let obsoleteAttrObj = (ObsoleteAttribute)
Attribute.GetCustomAttribute(method, obsoleteAttrType)
select String.Format("Type={0}\nMethod={1}\nMessage={2}\n",
type.FullName, method.ToString(), obsoleteAttrObj.Message);
// Display the results
foreach (var result in query) Console.WriteLine(result);
// Alternate (not as fast): query.ForAll(Console.WriteLine);
}
示例6: get_interface
private static IScriptType1 get_interface(Assembly script)
{
// Now that we have a compiled script, lets run them
foreach (Type type in script.GetExportedTypes())
{
foreach (Type iface in type.GetInterfaces())
{
if (iface == typeof (IScriptType1))
{
// yay, we found a script interface, lets create it and run it!
// Get the constructor for the current type
// you can also specify what creation parameter types you want to pass to it,
// so you could possibly pass in data it might need, or a class that it can use to query the host application
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
if (constructor != null && constructor.IsPublic)
{
// lets be friendly and only do things legitimitely by only using valid constructors
// we specified that we wanted a constructor that doesn't take parameters, so don't pass parameters
var scriptObject =
constructor.Invoke(null) as IScriptType1;
if (scriptObject != null)
{
//Lets run our script and display its results
//MessageBox.Show(scriptObject.RunScript(50));
return scriptObject;
}
else
{
Logger.Instance.Write("Script object could not created");
// hmmm, for some reason it didn't create the object
// this shouldn't happen, as we have been doing checks all along, but we should
// inform the user something bad has happened, and possibly request them to send
// you the script so you can debug this problem
}
}
else
{
Logger.Instance.Write("Script object could not created");
// and even more friendly and explain that there was no valid constructor
// found and thats why this script object wasn't run
}
}
}
}
return null;
}
示例7: GetExportedTypes
public static Type[] GetExportedTypes(Assembly assembly)
{
Requires.NotNull(assembly, "assembly");
return assembly.GetExportedTypes();
}
示例8: Run
/// <summary>
/// Execute the IScriptRunner.Run method in the compiled_assembly
/// </summary>
/// <param name="compiled_assembly">compiled assembly</param>
/// <param name="args">method arguments</param>
/// <returns>object returned</returns>
public static object Run(Assembly compiled_assembly, object[] args, PermissionSet permission_set)
{
if (compiled_assembly != null)
{
// put security restrict in place (PermissionState.None)
permission_set.PermitOnly();
foreach (Type type in compiled_assembly.GetExportedTypes())
{
foreach (Type interface_type in type.GetInterfaces())
{
if (interface_type == typeof(IScriptRunner))
{
ConstructorInfo constructor = type.GetConstructor(System.Type.EmptyTypes);
if ((constructor != null) && (constructor.IsPublic))
{
// construct object using default constructor
IScriptRunner obj = constructor.Invoke(null) as IScriptRunner;
if (obj != null)
{
return obj.Run(args);
}
else
{
throw new Exception("Invalid C# code!");
}
}
else
{
throw new Exception("No default constructor was found!");
}
}
else
{
throw new Exception("IScriptRunner is not implemented!");
}
}
}
// lift security restrictions
CodeAccessPermission.RevertPermitOnly();
}
return null;
}