public static ReflectionMemberImportDefinition CreateMemberImportDefinition(MemberInfo member, ICompositionElement origin) { Requires.NotNull(member, "member"); ReflectionWritableMember reflectionMember = member.ToReflectionWritableMember(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionMember, member); ImportType importType = new ImportType(reflectionMember.ReturnType, attributedImport.Cardinality); if (importType.IsPartCreator) { return new PartCreatorMemberImportDefinition( new LazyMemberInfo(member), origin, new ContractBasedImportDefinition( attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.AllowRecomposition, false, CreationPolicy.NonShared)); } else { return new ReflectionMemberImportDefinition( new LazyMemberInfo(member), attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.AllowRecomposition, attributedImport.RequiredCreationPolicy, origin); } }
/// <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> /// <exception cref="ArgumentNullException"> /// <paramref name="codeBase"/> 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) { Requires.NotNullOrEmpty(codeBase, "codeBase"); InitializeAssemblyCatalog(LoadAssembly(codeBase)); this._definitionOrigin = this; }
public static ReflectionParameterImportDefinition CreateParameterImportDefinition(ParameterInfo parameter, ICompositionElement origin) { Requires.NotNull(parameter, "parameter"); ReflectionParameter reflectionParameter = parameter.ToReflectionParameter(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionParameter, parameter); ImportType importType = new ImportType(reflectionParameter.ReturnType, attributedImport.Cardinality); if (importType.IsPartCreator) { return new PartCreatorParameterImportDefinition( new Lazy<ParameterInfo>(() => parameter), origin, new ContractBasedImportDefinition( attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, false, true, CreationPolicy.NonShared)); } else { return new ReflectionParameterImportDefinition( new Lazy<ParameterInfo>(() => parameter), attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.RequiredCreationPolicy, origin); } }
internal TypeCatalog(IEnumerable<Type> types, ICompositionElement definitionOrigin) { Requires.NotNull(types, "types"); foreach (Type type in types) { if (type == null) { throw ExceptionBuilder.CreateContainsNullElement("types"); } #if !SILVERLIGHT if (type.Assembly.ReflectionOnly) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Argument_ElementReflectionOnlyType, "types"), "types"); } #endif } this._types = types.ToArray(); this._definitionOrigin = definitionOrigin ?? this; #if !SILVERLIGHT this._contractPartIndex = new Lazy<IDictionary<string, List<ComposablePartDefinition>>>(this.CreateIndex, true); #else this._contractPartIndex = new Lazy<IDictionary<string, List<ComposablePartDefinition>>>(this.CreateIndex); #endif }
public ReflectionMemberExportDefinition(LazyMemberInfo member, ExportDefinition exportDefinition, ICompositionElement origin) { Assumes.NotNull(exportDefinition); this._member = member; this._exportDefinition = exportDefinition; this._origin = origin; }
public static ReflectionComposablePartDefinition CreatePartDefinition(Type type, PartCreationPolicyAttribute partCreationPolicy, bool ignoreConstructorImports, ICompositionElement origin) { Assumes.NotNull(type); AttributedPartCreationInfo creationInfo = new AttributedPartCreationInfo(type, partCreationPolicy, ignoreConstructorImports, origin); return new ReflectionComposablePartDefinition(creationInfo); }
public SerializableCompositionElement(string displayName, ICompositionElement origin) { #if FEATURE_SERIALIZATION Assumes.IsTrue(origin == null || origin.GetType().IsSerializable); #endif this._displayName = displayName ?? string.Empty; this._origin = origin; }
public AttributedPartCreationInfo(Type type, PartCreationPolicyAttribute partCreationPolicy, bool ignoreConstructorImports, ICompositionElement origin) { Assumes.NotNull(type); this._type = type; this._ignoreConstructorImports = ignoreConstructorImports; this._partCreationPolicy = partCreationPolicy; this._origin = origin; }
public SerializableCompositionElement(string displayName, ICompositionElement origin) { //#if !SILVERLIGHT // Assumes.IsTrue(origin == null); // || origin.GetType().IsSerializable); //#endif this._displayName = displayName ?? string.Empty; this._origin = origin; }
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="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> /// <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"/>. /// <para> /// -or- /// </para> /// <paramref name="types"/> contains an element that was loaded in the reflection-only context. /// </exception> public TypeCatalog(IEnumerable<Type> types) { Requires.NotNull(types, "types"); InitializeTypeCatalog(types); this._definitionOrigin = this; this._contractPartIndex = new Lazy<IDictionary<string, List<ComposablePartDefinition>>>(this.CreateIndex, true); }
public static ComposablePartDefinition CreatePartDefinitionIfDiscoverable(Type type, ICompositionElement origin) { AttributedPartCreationInfo creationInfo = new AttributedPartCreationInfo(type, null, false, origin); if (!creationInfo.IsPartDiscoverable()) { return null; } return new ReflectionComposablePartDefinition(creationInfo); }
public PartCreatorMemberImportDefinition( LazyMemberInfo importingLazyMember, ICompositionElement origin, ContractBasedImportDefinition productImportDefinition) : base(importingLazyMember, CompositionConstants.PartCreatorContractName, CompositionConstants.PartCreatorTypeIdentity, productImportDefinition.RequiredMetadata, productImportDefinition.Cardinality, productImportDefinition.IsRecomposable, CreationPolicy.Any, origin) { Assumes.NotNull(productImportDefinition); this._productImportDefinition = productImportDefinition; }
public DisposableWrapperPartDefinition(ComposablePartDefinition innerPartDefinition, bool isNonSharedDisposable) { if (innerPartDefinition == null) throw new ArgumentNullException(nameof(innerPartDefinition)); InnerPartDefinition = innerPartDefinition; _isNonSharedDisposable = isNonSharedDisposable; _compositionOrigin = innerPartDefinition as ICompositionElement; }
public static void AreEqual(ICompositionElement expected, ICompositionElement actual) { if (expected == null || actual == null) { Assert.AreEqual(expected, actual); return; } Assert.AreEqual(expected.DisplayName, actual.DisplayName); ElementAssert.AreEqual(expected.Origin, actual.Origin); }
public static ContractBasedImportDefinition CreateImportDefinition( Lazy<ParameterInfo> parameter, string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string, Type>> requiredMetadata, ImportCardinality cardinality, CreationPolicy requiredCreationPolicy, bool isExportFactory, ICompositionElement origin) { return ReflectionModelServices.CreateImportDefinition(parameter, contractName, requiredTypeIdentity, requiredMetadata, cardinality, requiredCreationPolicy, isExportFactory, origin); }
public static ContractBasedImportDefinition CreateImportDefinition( LazyMemberInfo importingMember, string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string, Type>> requiredMetadata, ImportCardinality cardinality, bool isRecomposable, CreationPolicy requiredCreationPolicy, ICompositionElement origin) { return CreateImportDefinition(importingMember, contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, requiredCreationPolicy, false, origin); }
private ReflectionComposablePartDefinition CreateReflectionPartDefinition( Lazy<Type> partType, bool requiresDisposal, Func<IEnumerable<ImportDefinition>> imports, Func<IEnumerable<ExportDefinition>>exports, IDictionary<string, object> metadata, ICompositionElement origin) { return (ReflectionComposablePartDefinition)ReflectionModelServices.CreatePartDefinition(partType, requiresDisposal, new Lazy<IEnumerable<ImportDefinition>>(imports, false), new Lazy<IEnumerable<ExportDefinition>>(exports, false), metadata.AsLazy(), origin); }
public static ICompositionElement FromICompositionElement(ICompositionElement element) { if (element == null) { // Null is always serializable return null; } ICompositionElement origin = FromICompositionElement(element.Origin); // Otherwise, we need to create a serializable wrapper return new SerializableCompositionElement(element.DisplayName, origin); }
public ReflectionImportDefinition( string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string, Type>> requiredMetadata, ImportCardinality cardinality, bool isRecomposable, bool isPrerequisite, CreationPolicy requiredCreationPolicy, ICompositionElement origin) : base(contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, isPrerequisite, requiredCreationPolicy) { this._origin = origin; }
public static ExportDefinition CreateExportDefinition( LazyMemberInfo exportingMember, string contractName, Lazy<IDictionary<string, object>> metadata, ICompositionElement origin) { Requires.NotNullOrEmpty(contractName, "contractName"); Requires.IsInMembertypeSet(exportingMember.MemberType, "exportingMember", MemberTypes.Field | MemberTypes.Property | MemberTypes.NestedType | MemberTypes.TypeInfo | MemberTypes.Method); return new ReflectionMemberExportDefinition( exportingMember, new LazyExportDefinition(contractName, metadata), origin); }
public ReflectionParameterImportDefinition( Lazy<ParameterInfo> importingLazyParameter, string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string,Type>> requiredMetadata, ImportCardinality cardinality, CreationPolicy requiredCreationPolicy, ICompositionElement origin) : base(contractName, requiredTypeIdentity, requiredMetadata, cardinality, false, true, requiredCreationPolicy, origin) { Assumes.NotNull(importingLazyParameter); this._importingLazyParameter = importingLazyParameter; }
public ReflectionMemberImportDefinition( LazyMemberInfo importingLazyMember, string contractName, string requiredTypeIdentity, IEnumerable<string> requiredMetadata, ImportCardinality cardinality, bool isRecomposable, CreationPolicy requiredCreationPolicy, ICompositionElement origin) : base(contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, false, requiredCreationPolicy, origin) { Assumes.NotNull(contractName); this._importingLazyMember = importingLazyMember; }
public DisposableWrapperCatalog(ComposablePartCatalog innerCatalog, bool isThreadSafe) { if (innerCatalog == null) throw new ArgumentNullException(nameof(innerCatalog)); _lock = new Lock(isThreadSafe, LockRecursionPolicy.NoRecursion); _cache = new Dictionary<ComposablePartDefinition, ComposablePartDefinition>(); _innerCatalog = innerCatalog; _compositionOrigin = innerCatalog as ICompositionElement; var notify = innerCatalog as INotifyComposablePartCatalogChanged; if (notify == null) return; notify.Changed += OnChanged; notify.Changing += OnChanging; }
public static ReflectionParameterImportDefinition CreateParameterImportDefinition(ParameterInfo parameter, ICompositionElement origin) { Requires.NotNull(parameter, "parameter"); ReflectionParameter reflectionParameter = parameter.ToReflectionParameter(); AttributedImportDefinitionCreationInfo importCreationInfo = AttributedModelDiscovery.GetImportDefinitionCreationInfo(reflectionParameter, parameter); return new ReflectionParameterImportDefinition( parameter.AsLazy(), importCreationInfo.ContractName, importCreationInfo.RequiredTypeIdentity, importCreationInfo.RequiredMetadata, importCreationInfo.Cardinality, importCreationInfo.RequiredCreationPolicy, origin); }
public static ReflectionMemberImportDefinition CreateMemberImportDefinition(MemberInfo member, ICompositionElement origin) { Requires.NotNull(member, "member"); ReflectionWritableMember reflectionMember = member.ToReflectionWritableMember(); AttributedImportDefinitionCreationInfo importCreationInfo = AttributedModelDiscovery.GetImportDefinitionCreationInfo(reflectionMember, member); return new ReflectionMemberImportDefinition( new LazyMemberInfo(member), importCreationInfo.ContractName, importCreationInfo.RequiredTypeIdentity, importCreationInfo.RequiredMetadata, importCreationInfo.Cardinality, importCreationInfo.IsRecomposable, importCreationInfo.RequiredCreationPolicy, origin); }
public ReflectionMemberImportDefinition( LazyMemberInfo importingLazyMember, string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string, Type>> requiredMetadata, ImportCardinality cardinality, bool isRecomposable, bool isPrerequisite, CreationPolicy requiredCreationPolicy, IDictionary<string, object> metadata, ICompositionElement origin) : base(contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, isPrerequisite, requiredCreationPolicy, metadata, origin) { Assumes.NotNull(contractName); this._importingLazyMember = importingLazyMember; }
public static ContractBasedImportDefinition CreateImportDefinition( LazyMemberInfo importingMember, string contractName, string requiredTypeIdentity, IEnumerable<KeyValuePair<string, Type>> requiredMetadata, ImportCardinality cardinality, bool isRecomposable, CreationPolicy requiredCreationPolicy, bool isPartCreator, ICompositionElement origin) { Requires.NotNullOrEmpty(contractName, "contractName"); Requires.NullOrNotNullElements(requiredMetadata, "requiredMetadata"); Requires.IsInMembertypeSet(importingMember.MemberType, "importingMember", MemberTypes.Property | MemberTypes.Field); if (isPartCreator) { #if SILVERLIGHT return new PartCreatorMemberImportDefinition( importingMember, origin, new ContractBasedImportDefinition( contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, false, CreationPolicy.NonShared)); #else throw new ArgumentException("PartCreator is only support in Silverlight version of MEF", "isPartCreator"); #endif } else { return new ReflectionMemberImportDefinition( importingMember, contractName, requiredTypeIdentity, requiredMetadata, cardinality, isRecomposable, requiredCreationPolicy, origin); } }
public static ReflectionParameterImportDefinition CreateParameterImportDefinition(ParameterInfo parameter, ICompositionElement origin) { Requires.NotNull(parameter, "parameter"); ReflectionParameter reflectionParameter = parameter.ToReflectionParameter(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionParameter, parameter); ImportType importType = new ImportType(reflectionParameter.ReturnType, attributedImport.Cardinality); if (importType.IsPartCreator) { return new PartCreatorParameterImportDefinition( new Lazy<ParameterInfo>(() => parameter), origin, new ContractBasedImportDefinition( attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, false, true, (attributedImport.RequiredCreationPolicy != CreationPolicy.NewScope) ? CreationPolicy.NonShared : CreationPolicy.NewScope, CompositionServices.GetImportMetadata(importType, attributedImport))); } else { // A Standard import is not allowed to be marked as requiring NewScope at this time. if(attributedImport.RequiredCreationPolicy == CreationPolicy.NewScope) { throw new ComposablePartException( String.Format(CultureInfo.CurrentCulture, Strings.InvalidPartCreationPolicyOnImport, attributedImport.RequiredCreationPolicy), origin); } return new ReflectionParameterImportDefinition( new Lazy<ParameterInfo>(() => parameter), attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.RequiredCreationPolicy, CompositionServices.GetImportMetadata(importType, attributedImport), origin); } }
private IEnumerable<ImportDefinition> GetImportMembers(Type type, ICompositionElement creationInfo) { if (type == typeofObject) { return Enumerable.Empty<ImportDefinition>(); } var originalType = type; var results = new List<ImportDefinition>(); do { bool shouldBreak = false; var members = GetDeclaredOnlyImportMembers(type, out shouldBreak); if (shouldBreak) { break; } #if !PARALLEL foreach (var member in members) { var importDefinition = CreateImportDefinition(type, member, creationInfo); results.Add(importDefinition); } #else Parallel.ForEach(members, new ParallelOptions { MaxDegreeOfParallelism = 1 }, member => { var importDefinition = CreateImportDefinition(type, member, creationInfo); lock (results) { results.Add(importDefinition); } }); #endif type = type.BaseType; } while (type != null && type != typeofObject); return results; }
public static ICompositionElement Create(string displayName, ICompositionElement origin) { return(new CompositionElement(displayName, origin)); }
public CompositionElement(string displayName, ICompositionElement origin) { _displayName = displayName ?? string.Empty; _origin = origin; }
protected ComposablePartException(SerializationInfo info, StreamingContext context) : base(info, context) { _element = info.GetValue <ICompositionElement>("Element"); }
private static ReflectionMemberExportDefinition CreateReflectionExportDefinition(LazyMemberInfo exportMember, string contractname, IDictionary <string, object> metadata, ICompositionElement origin) { return((ReflectionMemberExportDefinition)ReflectionModelServices.CreateExportDefinition( exportMember, contractname, CreateLazyMetadata(metadata), origin)); }
/// <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, nameof(types)); Requires.NotNull(reflectionContext, nameof(reflectionContext)); Requires.NotNull(definitionOrigin, nameof(definitionOrigin)); InitializeTypeCatalog(types, reflectionContext); _definitionOrigin = definitionOrigin; _contractPartIndex = new Lazy <IDictionary <string, List <ComposablePartDefinition> > >(CreateIndex, true); }
public static ReflectionMemberImportDefinition CreateMemberImportDefinition(MemberInfo member, ICompositionElement origin) { Requires.NotNull(member, nameof(member)); ReflectionWritableMember reflectionMember = member.ToReflectionWritableMember(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionMember, member); ImportType importType = new ImportType(reflectionMember.ReturnType, attributedImport.Cardinality); if (importType.IsPartCreator) { return(new PartCreatorMemberImportDefinition( new LazyMemberInfo(member), origin, new ContractBasedImportDefinition( attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.AllowRecomposition, false, CreationPolicy.NonShared, CompositionServices.GetImportMetadata(importType, attributedImport)))); } else { //Does this Import re-export the value if so, make it a rpe-requisite bool isPrerequisite = member.GetAttributes <ExportAttribute>().Length > 0; return(new ReflectionMemberImportDefinition( new LazyMemberInfo(member), attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.AllowRecomposition, isPrerequisite, attributedImport.RequiredCreationPolicy, CompositionServices.GetImportMetadata(importType, attributedImport), origin)); } }
internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, Exception exception, string format, params object[] parameters) { return(new CompositionError(id, string.Format(CultureInfo.CurrentCulture, format, parameters), element, exception)); }
/// <summary> /// Initializes a new instance of the <see cref="CompositionError"/> class /// with the specified error message, and composition element and exception that /// is the cause of the composition error. /// </summary> /// <param name="message"> /// A <see cref="String"/> containing a message that describes the /// <see cref="CompositionError"/>; or <see langword="null"/> to set the /// <see cref="Description"/> property to an empty string (""). /// </param> /// <param name="element"> /// The <see cref="ICompositionElement"/> that is the cause of the /// <see cref="CompositionError"/>; or <see langword="null"/> to set /// the <see cref="CompositionError.Element"/> property to /// <see langword="null"/>. /// </param> /// <param name="exception"> /// The <see cref="Exception"/> that is the underlying cause of the /// <see cref="CompositionError"/>; or <see langword="null"/> to set /// the <see cref="CompositionError.Exception"/> property to <see langword="null"/>. /// </param> public CompositionError(string message, ICompositionElement element, Exception exception) : this(CompositionErrorId.Unknown, message, element, exception) { }
public static ICompositionElement ToSerializableElement(this ICompositionElement element) { return(SerializableCompositionElement.FromICompositionElement(element)); }
internal AssemblyCatalog(string codeBase, ICompositionElement definitionOrigin) : this(LoadAssembly(codeBase), definitionOrigin) { }
public TypeOrigin(Type type, ICompositionElement origin) { this._type = type; this._orgin = origin; }
private ReflectionComposablePartDefinition CreateEmptyDefinition(Type type, ConstructorInfo constructor, IDictionary <string, object> metadata, ICompositionElement origin) { return((ReflectionComposablePartDefinition)ReflectionModelServices.CreatePartDefinition( (type != null) ? type.AsLazy() : null, false, Enumerable.Empty <ImportDefinition>().AsLazy(), Enumerable.Empty <ExportDefinition>().AsLazy(), metadata.AsLazy(), origin)); }
public static ReflectionParameterImportDefinition CreateParameterImportDefinition(ParameterInfo parameter, ICompositionElement origin) { Requires.NotNull(parameter, nameof(parameter)); ReflectionParameter reflectionParameter = parameter.ToReflectionParameter(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(reflectionParameter, parameter); ImportType importType = new ImportType(reflectionParameter.ReturnType, attributedImport.Cardinality); if (importType.IsPartCreator) { return(new PartCreatorParameterImportDefinition( new Lazy <ParameterInfo>(() => parameter), origin, new ContractBasedImportDefinition( attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, false, true, CreationPolicy.NonShared, CompositionServices.GetImportMetadata(importType, attributedImport)))); } else { return(new ReflectionParameterImportDefinition( new Lazy <ParameterInfo>(() => parameter), attributedImport.GetContractNameFromImport(importType), attributedImport.GetTypeIdentityFromImport(importType), CompositionServices.GetRequiredMetadata(importType.MetadataViewType), attributedImport.Cardinality, attributedImport.RequiredCreationPolicy, CompositionServices.GetImportMetadata(importType, attributedImport), origin)); } }
public static ReflectionComposablePartDefinition CreatePartDefinition(Type type, PartCreationPolicyAttribute partCreationPolicy, bool ignoreConstructorImports, ICompositionElement origin) { if (type == null) { throw new ArgumentNullException(nameof(type)); } AttributedPartCreationInfo creationInfo = new AttributedPartCreationInfo(type, partCreationPolicy, ignoreConstructorImports, origin); return(new ReflectionComposablePartDefinition(creationInfo)); }
public AttributedPartCreationInfo(Type type, PartCreationPolicyAttribute partCreationPolicy, bool ignoreConstructorImports, ICompositionElement origin) { if (type == null) { throw new ArgumentNullException(nameof(type)); } _type = type; _ignoreConstructorImports = ignoreConstructorImports; _partCreationPolicy = partCreationPolicy; _origin = origin; }
/// <summary> /// Initializes a new instance of the <see cref="CompositionError"/> class /// with the specified error message and composition element that is the /// cause of the composition error. /// </summary> /// <param name="element"> /// The <see cref="ICompositionElement"/> that is the cause of the /// <see cref="CompositionError"/>; or <see langword="null"/> to set /// the <see cref="CompositionError.Element"/> property to /// <see langword="null"/>. /// </param> /// <param name="message"> /// A <see cref="String"/> containing a message that describes the /// <see cref="CompositionError"/>; or <see langword="null"/> to set the /// <see cref="Description"/> property to an empty string (""). /// </param> public CompositionError(string message, ICompositionElement element) : this(CompositionErrorId.Unknown, message, element, (Exception)null) { }
public static ICompositionElement Create(ICompositionElement origin) { return(Create("Unknown Display Name", origin)); }
internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, string format, params object[] parameters) { return(Create(id, element, (Exception)null, format, parameters)); }
public ApplicationCatalog(ICompositionElement definitionOrigin) { Requires.NotNull(definitionOrigin, nameof(definitionOrigin)); _definitionOrigin = definitionOrigin; }
public static ImportDefinition CreateParameterImport(ParameterInfo parameter, ICompositionElement origin) { ReflectionParameter reflectionParameter = new ReflectionParameter(parameter); IAttributedImport attributedImport = ReflectionPartCreation.GetAttributedImport((ICustomAttributeProvider)parameter); if (string.IsNullOrEmpty(attributedImport.ContractName)) { return(new ImportDefinition(parameter.Name, parameter.ParameterType)); } return(new ContractBasedImportDefinition(parameter.Name, parameter.ParameterType, attributedImport.ContractName)); }
public static ComposablePartDefinition CreatePartDefinition(Type type, ICompositionElement origin) { Requires.NotNull(type, "type"); return(AttributedModelServices.CreatePartDefinition(type, origin, false)); }
public ReflectionMemberExportDefinition(LazyMemberInfo member, ExportDefinition exportDefinition, ICompositionElement origin) { Assumes.NotNull(exportDefinition); _member = member; _exportDefinition = exportDefinition; _origin = origin; }
public ReportTemplateSection() { /* Use an empty element by default to avoid null. */ RootElement = new EmptyElement(); }
/// <summary> /// Initializes a new instance of the <see cref="ComposablePartException"/> class /// with the specified error message and composition element that is the cause of /// the exception. /// </summary> /// <param name="message"> /// A <see cref="String"/> containing a message that describes the /// <see cref="ComposablePartException"/>; or <see langword="null"/> to set /// the <see cref="Exception.Message"/> property to its default value. /// </param> public ComposablePartException(string message, ICompositionElement element) : this(message, element, (Exception)null) { }
public ReflectionMemberExportDefinition(LazyMemberInfo member, ExportDefinition exportDefinition, ICompositionElement origin) { if (exportDefinition == null) { throw new ArgumentNullException(nameof(exportDefinition)); } _member = member; _exportDefinition = exportDefinition; _origin = origin; }
/// <summary> /// Initializes a new instance of the <see cref="ComposablePartException"/> class /// with the specified error message, and composition element and exception that /// are the cause of the exception. /// </summary> /// <param name="message"> /// A <see cref="String"/> containing a message that describes the /// <see cref="ComposablePartException"/>; or <see langword="null"/> to set /// the <see cref="Exception.Message"/> property to its default value. /// </param> /// <param name="element"> /// The <see cref="ICompositionElement"/> that is the cause of the /// <see cref="ComposablePartException"/>; or <see langword="null"/> to set /// the <see cref="ComposablePartException.Element"/> property to /// <see langword="null"/>. /// </param> /// <param name="innerException"> /// The <see cref="Exception"/> that is the underlying cause of the /// <see cref="ComposablePartException"/>; or <see langword="null"/> to set /// the <see cref="Exception.InnerException"/> property to <see langword="null"/>. /// </param> public ComposablePartException(string message, ICompositionElement element, Exception innerException) : base(message, innerException) { _element = element; }
private static SerializableCompositionElement CreateSerializableCompositionElement(ICompositionElement element) { return((SerializableCompositionElement)SerializableCompositionElement.FromICompositionElement(element)); }
public static ComposablePartDefinition CreatePartDefinitionIfDiscoverable(Type type, ICompositionElement origin) { AttributedPartCreationInfo creationInfo = new AttributedPartCreationInfo(type, null, false, origin); if (!creationInfo.IsPartDiscoverable()) { return(null); } return(new ReflectionComposablePartDefinition(creationInfo)); }
/// <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, nameof(assembly)); Requires.NotNull(reflectionContext, nameof(reflectionContext)); Requires.NotNull(definitionOrigin, nameof(definitionOrigin)); InitializeAssemblyCatalog(assembly); _reflectionContext = reflectionContext; _definitionOrigin = definitionOrigin; }