當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。