当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.GetExportedTypes方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:hernangm,项目名称:punch.metadata,代码行数:10,代码来源:StringlyScopeExtensions.cs

示例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;
 }
开发者ID:bpenrod,项目名称:emacs.d,代码行数:10,代码来源:assembly_tags.cs

示例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);
                }
            }
        }
    }
开发者ID:pasnox,项目名称:monkeystudio2,代码行数:37,代码来源:genapi.cs

示例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
 }
开发者ID:edg3,项目名称:afru,代码行数:34,代码来源:ScriptingProvider.cs

示例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);
   }
开发者ID:Helen1987,项目名称:edu,代码行数:17,代码来源:Ch27-1-ComputeOps.cs

示例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;
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:49,代码来源:ScriptRunner.cs

示例7: GetExportedTypes

 public static Type[] GetExportedTypes(Assembly assembly)
 {
     Requires.NotNull(assembly, "assembly");
     return assembly.GetExportedTypes();
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:5,代码来源:TypeExtensions.CoreCLR.cs

示例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;
    }
开发者ID:ATouhou,项目名称:QuranCode,代码行数:50,代码来源:ScriptRunner.cs


注:本文中的Assembly.GetExportedTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。