/// <summary> /// Initializes a new instance of the <see cref="WebPartsCatalog" /> class. Overloaded constructor allows caller to specify one or more assemblies and /// optionally MEF conventions for finding parts. /// </summary> /// <param name="assemblies">The assemblies.</param> /// <param name="reflectionContext">The reflection context.</param> public WebPartsCatalog(Assembly[] assemblies, ReflectionContext reflectionContext = null) { if (reflectionContext == null) reflectionContext = GetWebPartConventions(); catalog = new AggregateCatalog(assemblies.Select(a => new AssemblyCatalog(a, reflectionContext))); }
public ApplicationCatalog(ReflectionContext reflectionContext, ICompositionElement definitionOrigin) { Requires.NotNull(reflectionContext, "reflectionContext"); Requires.NotNull(definitionOrigin, "definitionOrigin"); this._reflectionContext = reflectionContext; this._definitionOrigin = definitionOrigin; }
/// <summary> /// Initializes a new instance of the <see cref="WebApplicationCatalog"/> class. /// </summary> /// <param name="assemblies">The assemblies.</param> /// <param name="reflectionContext">The reflection context.</param> protected WebApplicationCatalog(IEnumerable<Assembly> assemblies, ReflectionContext reflectionContext = null) { if (!IsInitialized) { if (reflectionContext == null) reflectionContext = DefineConventions(); applicationCatalog = new AggregateCatalog(assemblies.Select(a => new AssemblyCatalog(a, reflectionContext))); } }
public static ReflectionComposablePart CreatePart(object attributedPart, ReflectionContext reflectionContext) { Assumes.NotNull(attributedPart); Assumes.NotNull(reflectionContext); // If given an instance then we want to pass the default composition options because we treat it as a shared part // TODO: ICompositionElement Give this def an origin indicating that it was added directly to the ComposablePartExportProvider. var mappedType = reflectionContext.MapType(IntrospectionExtensions.GetTypeInfo(attributedPart.GetType())); if (mappedType.Assembly.ReflectionOnly) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Argument_ReflectionContextReturnsReflectionOnlyType, "reflectionContext"), "reflectionContext"); } ReflectionComposablePartDefinition definition = AttributedModelDiscovery.CreatePartDefinition(mappedType, PartCreationPolicyAttribute.Shared, true, (ICompositionElement)null); return CreatePart(definition, attributedPart); }
public ApplicationCatalog(ReflectionContext reflectionContext) { Requires.NotNull(reflectionContext, "reflectionContext"); this._reflectionContext = reflectionContext; }
/// <summary> /// Creates a catalog of <see cref="ComposablePartDefinition"/>s based on all the given searchPattern /// over the files in the given directory path. /// /// Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or /// <see cref="Assembly.Load(AssemblyName)"/> can throw. /// </summary> /// <param name="path"> /// Path to the directory to scan for assemblies to add to the catalog. /// The path needs to be absolute or relative to <see cref="AppDomain.BaseDirectory"/> /// </param> /// <param name="searchPattern"> /// Any valid searchPattern that <see cref="Directory.GetFiles(string, string)"/> will accept. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="path"/> is a zero-length string, contains only white space, or /// contains one or more implementation-specific invalid characters. Or <paramref name="searchPattern"/> /// does not contain a valid pattern. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/> /// or <paramref name="searchPattern"/> is <see langword="null"/>. /// or <paramref name="reflectionContext"/> is <see langword="null"/>. /// or <paramref name="definitionOrigin"/> is <see langword="null"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// The specified <paramref name="path"/> is invalid (for example, it is on an unmapped drive). /// </exception> /// <exception cref="PathTooLongException"> /// The specified <paramref name="path"/>, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must /// be less than 260 characters. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> public DirectoryCatalog(string path, string searchPattern, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) { Requires.NotNullOrEmpty(path, "path"); Requires.NotNullOrEmpty(searchPattern, "searchPattern"); Requires.NotNull(reflectionContext, "reflectionContext"); Requires.NotNull(definitionOrigin, "definitionOrigin"); this._reflectionContext = reflectionContext; this._definitionOrigin = definitionOrigin; this.Initialize(path, searchPattern); }
/// <summary> /// Creates a catalog of <see cref="ComposablePartDefinition"/>s based on all the given searchPattern /// over the files in the given directory path. /// /// Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or /// <see cref="Assembly.Load(AssemblyName)"/> can throw. /// </summary> /// <param name="path"> /// Path to the directory to scan for assemblies to add to the catalog. /// The path needs to be absolute or relative to <see cref="AppDomain.BaseDirectory"/> /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="path"/> is a zero-length string, contains only white space /// does not contain a valid pattern. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/> or /// <paramref name="reflectionContext"/> is <see langword="null"/> or /// <paramref name="definitionOrigin"/> is <see langword="null"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// The specified <paramref name="path"/> is invalid (for example, it is on an unmapped drive). /// </exception> /// <exception cref="PathTooLongException"> /// The specified <paramref name="path"/>, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must /// be less than 260 characters. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> public DirectoryCatalog(string path, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) : this(path, "*.dll", reflectionContext, definitionOrigin) { }
/// <summary> /// Creates a catalog of <see cref="ComposablePartDefinition"/>s based on all the *.dll files /// in the given directory path. /// /// Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or /// <see cref="Assembly.Load(AssemblyName)"/> can throw. /// </summary> /// <param name="path"> /// Path to the directory to scan for assemblies to add to the catalog. /// The path needs to be absolute or relative to <see cref="AppDomain.BaseDirectory"/> /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="path"/> is a zero-length string, contains only white space, or /// contains one or more implementation-specific invalid characters. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/> or /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// The specified <paramref name="path"/> is invalid (for example, it is on an unmapped drive). /// </exception> /// <exception cref="PathTooLongException"> /// The specified <paramref name="path"/>, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must /// be less than 260 characters. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> public DirectoryCatalog(string path, ReflectionContext reflectionContext) : this(path, "*.dll", reflectionContext) { }
private void InitializeTypeCatalog(IEnumerable<Type> types, ReflectionContext reflectionContext) { var typesList = new List<Type>(); foreach(var type in types) { if (type == null) { throw ExceptionBuilder.CreateContainsNullElement("types"); } if (type.Assembly.ReflectionOnly) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Argument_ElementReflectionOnlyType, "types"), "types"); } var typeInfo = type.GetTypeInfo(); var lclType = (reflectionContext != null) ? reflectionContext.MapType(typeInfo) : typeInfo; // It is valid for the reflectionContext to delete types by mapping them to null if(lclType != null) { // The final mapped type may be activated so we check to see if it is in a reflect only assembly if (lclType.Assembly.ReflectionOnly) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Argument_ReflectionContextReturnsReflectionOnlyType, "reflectionContext"), "reflectionContext"); } typesList.Add(lclType); } } this._types = typesList.ToArray(); }
/// <summary> /// Initializes a new instance of the <see cref="TypeCatalog"/> class /// with the specified types. /// </summary> /// <param name="types"> /// An <see cref="IEnumerable{T}"/> of attributed <see cref="Type"/> objects to add /// to the <see cref="TypeCatalog"/>. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="types"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="types"/> contains an element that is <see langword="null"/>. /// </exception> public TypeCatalog(IEnumerable<Type> types, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) { Requires.NotNull(types, "types"); Requires.NotNull(reflectionContext, "reflectionContext"); Requires.NotNull(definitionOrigin, "definitionOrigin"); InitializeTypeCatalog(types, reflectionContext); this._definitionOrigin = definitionOrigin; this._contractPartIndex = new Lazy<IDictionary<string, List<ComposablePartDefinition>>>(this.CreateIndex, true); }
/// <summary> /// Creates an <see cref="AttributedRobot"/> with a <see cref="ReflectionContext"/> object to find types through. /// </summary> /// <param name="reflectionContext">The context to find types through.</param> /// <remarks> /// This constructor only needed when using commands from a library that you cannot edit the source code for. Otherwise use the other constructor. /// </remarks> public AttributedRobot(ReflectionContext reflectionContext) { m_reflectionContext = reflectionContext; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCatalog"/> class /// with the specified assembly, reflectionContext and definitionOrigin. /// </summary> /// <param name="assembly"> /// The <see cref="Assembly"/> containing the attributed <see cref="Type"/> objects to /// add to the <see cref="AssemblyCatalog"/>. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="assembly"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="assembly"/> was loaded in the reflection-only context. /// <para> /// -or- /// </para> /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="definitionOrigin"/> is <see langword="null"/>. /// </exception> public AssemblyCatalog(Assembly assembly, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) { Requires.NotNull(assembly, "assembly"); Requires.NotNull(reflectionContext, "reflectionContext"); Requires.NotNull(definitionOrigin, "definitionOrigin"); InitializeAssemblyCatalog(assembly); this._reflectionContext = reflectionContext; this._definitionOrigin = definitionOrigin; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCatalog"/> class /// with the specified assembly and reflection context. /// </summary> /// <param name="assembly"> /// The <see cref="Assembly"/> containing the attributed <see cref="Type"/> objects to /// add to the <see cref="AssemblyCatalog"/>. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="assembly"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="assembly"/> was loaded in the reflection-only context. /// <para> /// -or- /// </para> /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> public AssemblyCatalog(Assembly assembly, ReflectionContext reflectionContext) { Requires.NotNull(assembly, "assembly"); Requires.NotNull(reflectionContext, "reflectionContext"); InitializeAssemblyCatalog(assembly); this._reflectionContext = reflectionContext; this._definitionOrigin = this; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCatalog"/> class /// with the specified code base. /// </summary> /// <param name="codeBase"> /// A <see cref="String"/> containing the code base of the assembly containing the /// attributed <see cref="Type"/> objects to add to the <see cref="AssemblyCatalog"/>. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition<see cref="AssemblyCatalog"/>. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="codeBase"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="definitionOrigin"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="codeBase"/> is a zero-length string, contains only white space, /// or contains one or more invalid characters as defined by <see cref="Path.InvalidPathChars"/>. /// </exception> /// <exception cref="PathTooLongException"> /// The specified path, file name, or both exceed the system-defined maximum length. /// </exception> /// <exception cref="SecurityException"> /// The caller does not have path discovery permission. /// </exception> /// <exception cref="FileNotFoundException"> /// <paramref name="codeBase"/> is not found. /// </exception> /// <exception cref="FileLoadException "> /// <paramref name="codeBase"/> could not be loaded. /// <para> /// -or- /// </para> /// <paramref name="codeBase"/> specified a directory. /// </exception> /// <exception cref="BadImageFormatException"> /// <paramref name="codeBase"/> is not a valid assembly /// -or- /// Version 2.0 or later of the common language runtime is currently loaded /// and <paramref name="codeBase"/> was compiled with a later version. /// </exception> /// <remarks> /// The assembly referenced by <paramref langword="codeBase"/> is loaded into the Load context. /// </remarks> public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) { Requires.NotNullOrEmpty(codeBase, "codeBase"); Requires.NotNull(reflectionContext, "reflectionContext"); Requires.NotNull(definitionOrigin, "definitionOrigin"); InitializeAssemblyCatalog(LoadAssembly(codeBase)); this._reflectionContext = reflectionContext; this._definitionOrigin = definitionOrigin; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCatalog"/> class /// with the specified code base. /// </summary> /// <param name="codeBase"> /// A <see cref="String"/> containing the code base of the assembly containing the /// attributed <see cref="Type"/> objects to add to the <see cref="AssemblyCatalog"/>. /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition<see cref="AssemblyCatalog"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="codeBase"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="codeBase"/> is a zero-length string, contains only white space, /// or contains one or more invalid characters as defined by <see cref="Path.InvalidPathChars"/>. /// </exception> /// <exception cref="PathTooLongException"> /// The specified path, file name, or both exceed the system-defined maximum length. /// </exception> /// <exception cref="SecurityException"> /// The caller does not have path discovery permission. /// </exception> /// <exception cref="FileNotFoundException"> /// <paramref name="codeBase"/> is not found. /// </exception> /// <exception cref="FileLoadException "> /// <paramref name="codeBase"/> could not be loaded. /// <para> /// -or- /// </para> /// <paramref name="codeBase"/> specified a directory. /// </exception> /// <exception cref="BadImageFormatException"> /// <paramref name="codeBase"/> is not a valid assembly /// -or- /// Version 2.0 or later of the common language runtime is currently loaded /// and <paramref name="codeBase"/> was compiled with a later version. /// </exception> /// <remarks> /// The assembly referenced by <paramref langword="codeBase"/> is loaded into the Load context. /// </remarks> public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext) { Requires.NotNullOrEmpty(codeBase, "codeBase"); Requires.NotNull(reflectionContext, "reflectionContext"); InitializeAssemblyCatalog(LoadAssembly(codeBase)); this._reflectionContext = reflectionContext; this._definitionOrigin = this; }
protected CustomReflectionContext (ReflectionContext source) { throw new NotImplementedException (); }