本文整理汇总了C#中System.Reflection.Assembly.GetExportedTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetExportedTypes方法的具体用法?C# Assembly.GetExportedTypes怎么用?C# Assembly.GetExportedTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetExportedTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindMigrationsIn
public IEnumerable<MigrationMetadata> FindMigrationsIn(Assembly assembly, string @namespace)
{
IEnumerable<Type> matchedTypes = assembly.GetExportedTypes().Where(t => Conventions.TypeIsMigration(t));
if (!string.IsNullOrEmpty(@namespace))
matchedTypes = assembly.GetExportedTypes().Where(t => t.Namespace == @namespace && Conventions.TypeIsMigration(t));
foreach (Type type in matchedTypes)
yield return Conventions.GetMetadataForMigration(type);
}
示例2: ScanAssembly
public void ScanAssembly(Assembly assembly)
{
assembly
.GetExportedTypes()
.Where(x => x.CanBeCastTo<StringToken>())
.Each(ScanStringTokenType);
assembly
.GetExportedTypes()
.Where(x => x.IsConcreteTypeOf<ILocalizedProperties>())
.Each(type => ScanProperties(type.Create<ILocalizedProperties>()));
}
示例3: RunScript
static string RunScript(Assembly script)
{
string res = "Error";
foreach (Type type in script.GetExportedTypes())
foreach (Type iface in type.GetInterfaces())
if (iface == typeof(IScript))
{
ConstructorInfo constructor = type.GetConstructor(System.Type.EmptyTypes);
if (constructor != null && constructor.IsPublic)
{
IScript scriptObject = constructor.Invoke(null) as IScript;
if (scriptObject != null)
{
res = scriptObject.RunScript();
}
else
{
}
}
else
{
}
}
return res;
}
示例4: AddTypes
/// <summary>
/// Stellt sicher, dass der Serialisierer alle benötigten Datentypen kennt.
/// </summary>
/// <param name="assembly">Eine Erweiterungsbibliothek.</param>
internal static void AddTypes( Assembly assembly )
{
// Nothing to do
if (assembly == null)
return;
// Process all
lock (m_ExtraTypes)
{
// Check for update
bool mustUpdate = false;
// Check all
foreach (var type in assembly.GetExportedTypes())
{
// Resolve to base
var genericBase = FindCustomActionBase( type );
if (genericBase != null)
if (m_ExtraTypes.Add( typeof( CustomActionRequest<,> ).MakeGenericType( genericBase.GetGenericArguments() ) ))
mustUpdate = true;
}
// Reload serializer
if (mustUpdate)
CreateSerializer();
}
}
示例5: 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);
}
}
示例6: ExtensionInfoBuilder
/// <summary>
/// Initializes a new instance of the ExtensionInfoBuilder class for the given assembly.
/// </summary>
/// <param name="fileName">The file name and path to the assembly to check.</param>
public ExtensionInfoBuilder(string fileName)
{
ExtensionInfo ei;
Type[] types;
resultExtensions = new ExtensionInfoCollection();
Type ropt = typeof(Extension);
sourceAssembly = Assembly.ReflectionOnlyLoadFrom(fileName);
ropt = ReflectionOnlyTypeFromAssembly(sourceAssembly, ropt);
try
{
types = sourceAssembly.GetExportedTypes();
foreach (Type t in types)
{
try
{
if (t.IsSubclassOf(ropt) && !t.IsAbstract)
{
ei = new ExtensionInfo(t);
resultExtensions.Add(ei);
}
}
catch (ArgumentOutOfRangeException)
{
ei = null;
}
}
}
catch (ReflectionTypeLoadException)
{
return;
}
}
示例7: Verify
/// <summary>
/// Calls <see cref="Verify(Type[])" /> for each public Type in
/// <paramref name="assembly" />.
/// </summary>
/// <param name="assembly">The assembly.</param>
public virtual void Verify(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
this.Verify(assembly.GetExportedTypes());
}
示例8: GetLoadableTypes
private static IEnumerable<Type> GetLoadableTypes(Assembly assembly)
{
if (assembly == null) throw new ArgumentNullException("assembly");
try
{
return assembly.GetExportedTypes();
}
catch (TypeLoadException)
{
return new Type[0];
}
catch (FileNotFoundException)
{
return new Type[0];
}
catch (ReflectionTypeLoadException ex)
{
var types = ex.Types;
IList<Type> list = new List<Type>(types.Length);
foreach (var t in types)
if (t != null && t.IsPublic)
list.Add(t);
return list;
}
}
示例9: FindSpecificationSupplementsIn
public IEnumerable<ISupplementSpecificationResults> FindSpecificationSupplementsIn(Assembly assembly)
{
return assembly.GetExportedTypes()
.Where(x =>
x.GetInterfaces().Contains(typeof(ISupplementSpecificationResults)))
.Select(x => (ISupplementSpecificationResults) Activator.CreateInstance(x));
}
示例10: FindAssemblyWideContextCleanupsIn
public IEnumerable<ICleanupAfterEveryContextInAssembly> FindAssemblyWideContextCleanupsIn(Assembly assembly)
{
return assembly.GetExportedTypes()
.Where(x =>
x.GetInterfaces().Contains(typeof(ICleanupAfterEveryContextInAssembly)))
.Select(x => (ICleanupAfterEveryContextInAssembly) Activator.CreateInstance(x));
}
示例11: MapAttributeRoutesInAssembly
public static void MapAttributeRoutesInAssembly(this RouteCollection routes, Assembly assembly, IInlineConstraintResolver constraintResolver, IDirectRouteProvider routeProvider)
{
var controllers = (assembly.GetExportedTypes()
.Where(IsControllerType)).ToList();
MapAttributeRoutesInControllers(routes, controllers, constraintResolver, routeProvider);
}
示例12: EventTypeResolver
public EventTypeResolver(Assembly assembly)
{
_typeMap = assembly
.GetExportedTypes()
.Where(x => x.Name.EndsWith("Event", StringComparison.OrdinalIgnoreCase))
.ToDictionary(x => x.Name);
}
示例13: RegisterViewModelsWithLocator
private static void RegisterViewModelsWithLocator(Assembly assembly)
{
foreach (var viewModel in assembly.GetExportedTypes().Where(x => x.IsPublic && !x.IsInterface && x.Name.EndsWith("ViewModel")))
{
RegisterKnownViewModel(viewModel);
}
}
开发者ID:mikoskinen,项目名称:Caliburn.Micro.WP71.Recipes.ExternalModules,代码行数:7,代码来源:StaticViewModelLocator.cs
示例14: DiscoverTypes
protected void DiscoverTypes( Assembly assembly )
{
Type[] types = null;
try
{
types = assembly.GetExportedTypes();
}
catch(Exception)
{
// Ok, Dynamic assemblies don't support GetExportedTypes
types = new Type[0];
}
foreach( Type type in types )
{
String nameSpace = type.Namespace;
if (nameSpace == null)
{
continue;
}
Tree.DefineNamespace( nameSpace ).AddType( type );
}
}
示例15: MapMvcAttributeRoutes
public static void MapMvcAttributeRoutes(
this RouteCollection routeCollection,
Assembly controllerAssembly,
IInlineConstraintResolver constraintResolver = null)
{
var controllerTypes = (from type in controllerAssembly.GetExportedTypes()
where
type != null && type.IsPublic
&& type.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase)
&& !type.IsAbstract && typeof(IController).IsAssignableFrom(type)
select type).ToList();
routeCollection.MapMvcAttributeRoutes();
var attributeRoutingAssembly = typeof(RouteCollectionAttributeRoutingExtensions).Assembly;
var attributeRoutingMapperType =
attributeRoutingAssembly.GetType("System.Web.Mvc.Routing.AttributeRoutingMapper");
var mapAttributeRoutesMethod = attributeRoutingMapperType.GetMethod(
"MapAttributeRoutes",
BindingFlags.Public | BindingFlags.Static,
null,
new[] { typeof(RouteCollection), typeof(IEnumerable<Type>), typeof(IInlineConstraintResolver) },
null);
constraintResolver = constraintResolver ?? new DefaultInlineConstraintResolver();
mapAttributeRoutesMethod.Invoke(null, new object[] { routeCollection, controllerTypes, constraintResolver });
}