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


C# Assembly.GetLoadableTypes方法代码示例

本文整理汇总了C#中System.Reflection.Assembly.GetLoadableTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetLoadableTypes方法的具体用法?C# Assembly.GetLoadableTypes怎么用?C# Assembly.GetLoadableTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Assembly的用法示例。


在下文中一共展示了Assembly.GetLoadableTypes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Scan

 /// <summary>
 /// All IRouteRegistration instances and all delegates
 /// </summary>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public IEnumerable<IRouteRegistration> Scan(Assembly assembly)
 {
     return Enumerable.Concat(
             assembly.GetLoadableTypes().SelectMany(t => Enumerable.Concat(new[] { t }, t.GetLoadableNestedTypes()))
                 .Where(IsConstructableRouteRegistration)
                 .Select(t => (IRouteRegistration)Activator.CreateInstance(t)),
             assembly.GetLoadableTypes().Where(t => typeof(Handler).IsAssignableFrom(t))
                 .SelectMany(t => t.GetFields(BindingFlags.NonPublic | BindingFlags.Static)
                     .Where(IsRegister)
                     .Select(f => new DelegatedRouteRegistration((Handler.Register)f.GetValue(null)))
                 ));
 }
开发者ID:nhsevidence,项目名称:Snooze,代码行数:17,代码来源:RoutingRegistrationDiscovery.cs

示例2: InitDotVVM

        public static DotvvmConfiguration InitDotVVM(Assembly webSiteAssembly, string rootPath)
        {
            var dotvvmStartups = webSiteAssembly.GetLoadableTypes()
                .Where(t => typeof(IDotvvmStartup).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null).ToArray();

            if (dotvvmStartups.Length == 0) throw new Exception("Could not find any implementation of IDotvvmStartup.");
            if (dotvvmStartups.Length > 1) throw new Exception($"Found more than one implementation of IDotvvmStartup ({string.Join(", ", dotvvmStartups.Select(s => s.Name)) }).");

            var startup = (IDotvvmStartup)Activator.CreateInstance(dotvvmStartups[0]);
            var config = OwinExtensions.CreateConfiguration(rootPath);
            startup.Configure(config, rootPath);
            config.CompiledViewsAssemblies = null;
            return config;
        }
开发者ID:darilek,项目名称:dotvvm,代码行数:14,代码来源:OwinInitializer.cs

示例3: LoadConfiguration

        private static object LoadConfiguration(
            Assembly configAssembly,
            DashingSettings dashingSettings,
            ConnectionStringSettings connectionStringSettings) {
            // fetch the to state
            var configType = configAssembly.GetLoadableTypes().SingleOrDefault(t => t.FullName == dashingSettings.ConfigurationName);

            if (configType == null) {
                using (Color(ConsoleColor.Red)) {
                    var candidates = configAssembly.GetLoadableTypes().Where(t => t.GetInterface(typeof(IConfiguration).FullName) != null).ToArray();
                    if (candidates.Any()) {
                        throw new CatchyException(
                            "Could not locate {0}, but found candidates: {1}",
                            dashingSettings.ConfigurationName,
                            string.Join(", ", candidates.Select(c => c.FullName)));
                    }

                    throw new CatchyException("Could not locate {0}, and found no candidate configurations", dashingSettings.ConfigurationName);
                }
            }

            // attempt to find the call to ConfigurationManager and overwrite the connection string
            InjectConnectionString(dashingSettings, connectionStringSettings);

            // TODO add in a factory way of generating the config for cases where constructor not empty
            return Activator.CreateInstance(configType);
        }
开发者ID:gitter-badger,项目名称:dashing,代码行数:27,代码来源:Program.cs

示例4: GetTypesSafe

 private IEnumerable<Type> GetTypesSafe(Assembly a)
 {
     try
     {
         return a.GetLoadableTypes();
     }
     catch (Exception ex)
     {
         _trace.TraceWarning("None of the classes from assembly '{0}' could be loaded when searching for Hubs. [{1}]",
                            a.FullName,
                            a.Location,
                            ex.GetType().Name,
                            ex.Message);
         return Enumerable.Empty<Type>();
     }
 }
开发者ID:karpinskiy,项目名称:vc-community,代码行数:16,代码来源:SignalRStartup.cs

示例5: ConfigureAssembly

        private void ConfigureAssembly(Assembly assembly) {
            var types = assembly.GetLoadableTypes().Where(type =>
                type.IsPublic &&
                type.IsSubclassOf(typeof(DirectController)) &&
                !type.HasAttribute<DirectIgnoreAttribute>()
            );

            foreach (Type type in types) {
                var action = new DirectAction(type);
                if (_actions.ContainsKey(action.Name)) {
                    throw new Exception(String.Format(DirectResources.DirectProvider_ActionExists, action.Name));
                }
                _actions.Add(action.Name, action);
            }
        }
开发者ID:gongyunjing,项目名称:ext-direct-mvc,代码行数:15,代码来源:DirectProvider.cs

示例6: ClassScanner

 public ClassScanner(Assembly assembly, Func<Type, bool> filter)
 {
     Throw.IfNullArgument(assembly, "assembly");
     Types = new List<Type>(assembly.GetLoadableTypes().Where(filter));
 }
开发者ID:kamaelyoung,项目名称:Carcass,代码行数:5,代码来源:ClassScanner.cs

示例7: RegisterFunctions

        internal void RegisterFunctions(Assembly assembly)
        {
            foreach(Type type in assembly.GetLoadableTypes())
            {
                // Not a class or abstract?
                if(!type.IsClass || type.IsAbstract)
                {
                    continue;
                }
                // Is the type not assignable from the function base class?
                if(!typeof(MathExpressionFunction).IsAssignableFrom(type))
                {
                    continue;
                }

                // Make sure there is at least one parameterless constructor.
                ConstructorInfo[] constructors = type.GetConstructors();
                ConstructorInfo constructor = constructors.FirstOrDefault(x => x.GetParameters().Length == 0);
                if(constructor == null)
                {
                    string message = string.Format("Function of type '{0}' has no parameterless constructor.", type.FullName);
                    throw new MathExpressionException(message);
                }

                // Register the function.
                MathExpressionFunction function = Activator.CreateInstance(type) as MathExpressionFunction;
                this.RegisterFunction(function);
            }
        }
开发者ID:patriksvensson,项目名称:arithmetica,代码行数:29,代码来源:MathExpressionFunctionFactory.cs


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