本文整理汇总了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)))
));
}
示例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;
}
示例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);
}
示例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>();
}
}
示例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);
}
}
示例6: ClassScanner
public ClassScanner(Assembly assembly, Func<Type, bool> filter)
{
Throw.IfNullArgument(assembly, "assembly");
Types = new List<Type>(assembly.GetLoadableTypes().Where(filter));
}
示例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);
}
}