/// <summary> /// Export the part using <typeparamref name="T"/> as the contract. /// </summary> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export <T>() { var exportBuilder = new ExportConventionBuilder().AsContractType <T>(); this._typeExportBuilders.Add(exportBuilder); return(this); }
public void ConfigureExport(PropertyInfo propertyInfo, ExportConventionBuilder exportBuilder) { if (_configureExport != null) { _configureExport(exportBuilder); } }
/// <summary> /// Export the part using its own concrete type as the contract. /// </summary> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export() { var exportBuilder = new ExportConventionBuilder(); this._typeExportBuilders.Add(exportBuilder); return(this); }
/// <summary> /// Export the part. /// </summary> /// <param name="exportConfiguration">Configuration action for the export.</param> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export(Action <ExportConventionBuilder> exportConfiguration) { Requires.NotNull(exportConfiguration, "exportConfiguration"); var exportBuilder = new ExportConventionBuilder(); exportConfiguration(exportBuilder); this._typeExportBuilders.Add(exportBuilder); return(this); }
/// <summary> /// Export the class using <typeparamref name="T"/> as the contract. /// </summary> /// <param name="exportConfiguration">Configuration action for the export.</param> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export <T>(Action <ExportConventionBuilder> exportConfiguration) { Requires.NotNull(exportConfiguration, nameof(exportConfiguration)); var exportBuilder = new ExportConventionBuilder().AsContractType <T>(); exportConfiguration(exportBuilder); _typeExportBuilders.Add(exportBuilder); return(this); }
/// <summary> /// Export the part. /// </summary> /// <param name="exportConfiguration">Configuration action for the export.</param> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export(Action <ExportConventionBuilder> exportConfiguration) { if (exportConfiguration == null) { throw new ArgumentNullException(nameof(exportConfiguration)); } var exportBuilder = new ExportConventionBuilder(); exportConfiguration(exportBuilder); _typeExportBuilders.Add(exportBuilder); return(this); }
/// <summary> /// Export the class using <typeparamref name="T"/> as the contract. /// </summary> /// <param name="exportConfiguration">Configuration action for the export.</param> /// <returns>A part builder allowing further configuration of the part.</returns> public PartConventionBuilder Export <T>(Action <ExportConventionBuilder> exportConfiguration) { if (exportConfiguration is null) { throw new ArgumentNullException(nameof(exportConfiguration)); } ExportConventionBuilder exportBuilder = new ExportConventionBuilder().AsContractType <T>(); exportConfiguration(exportBuilder); _typeExportBuilders.Add(exportBuilder); return(this); }
internal void BuildPropertyAttributes(Type type, ref List <Tuple <object, List <Attribute> > > configuredMembers) { if (this._propertyImports.Any() || this._propertyExports.Any()) { foreach (var pi in type.GetRuntimeProperties()) { List <Attribute> attributes = null; int importsBuilt = 0; bool checkedIfConfigured = false; bool isConfigured = false; PropertyInfo underlyingPi = null; // Run through the import specifications see if any match foreach (var importSpecification in this._propertyImports) { if (underlyingPi == null) { underlyingPi = pi.DeclaringType.GetRuntimeProperty(pi.Name); } if (importSpecification.Item1 != null && importSpecification.Item1(underlyingPi)) { var importBuilder = new ImportConventionBuilder(); if (importSpecification.Item2 != null) { importSpecification.Item2(pi, importBuilder); } if (!checkedIfConfigured) { isConfigured = pi.GetFirstAttribute <ImportAttribute>() != null || pi.GetFirstAttribute <ImportManyAttribute>() != null; checkedIfConfigured = true; } if (isConfigured) { CompositionTrace.Registration_MemberImportConventionOverridden(type, pi); break; } else { importBuilder.BuildAttributes(pi.PropertyType, ref attributes); ++importsBuilt; } } if (importsBuilt > 1) { CompositionTrace.Registration_MemberImportConventionMatchedTwice(type, pi); } } checkedIfConfigured = false; isConfigured = false; // Run through the export specifications see if any match foreach (var exportSpecification in this._propertyExports) { if (underlyingPi == null) { underlyingPi = pi.DeclaringType.GetRuntimeProperty(pi.Name); } if (exportSpecification.Item1 != null && exportSpecification.Item1(underlyingPi)) { var exportBuilder = new ExportConventionBuilder(); if (exportSpecification.Item3 != null) { exportBuilder.AsContractType(exportSpecification.Item3); } if (exportSpecification.Item2 != null) { exportSpecification.Item2(pi, exportBuilder); } if (!checkedIfConfigured) { isConfigured = pi.GetFirstAttribute <ExportAttribute>() != null || MemberHasExportMetadata(pi); checkedIfConfigured = true; } if (isConfigured) { CompositionTrace.Registration_MemberExportConventionOverridden(type, pi); break; } else { exportBuilder.BuildAttributes(pi.PropertyType, ref attributes); } } } if (attributes != null) { if (configuredMembers == null) { configuredMembers = new List <Tuple <object, List <Attribute> > >(); } configuredMembers.Add(Tuple.Create((object)pi, attributes)); } } } return; }
internal IEnumerable <Attribute> BuildTypeAttributes(Type type) { var attributes = new List <Attribute>(); if (this._typeExportBuilders != null) { bool isConfigured = type.GetTypeInfo().GetFirstAttribute <ExportAttribute>() != null || MemberHasExportMetadata(type.GetTypeInfo()); if (isConfigured) { CompositionTrace.Registration_TypeExportConventionOverridden(type); } else { foreach (var export in this._typeExportBuilders) { export.BuildAttributes(type, ref attributes); } } } if (this._isShared) { // Check if there is already a SharedAttribute. If found Trace a warning and do not add this Shared // otherwise add new one bool isConfigured = type.GetTypeInfo().GetFirstAttribute <SharedAttribute>() != null; if (isConfigured) { CompositionTrace.Registration_PartCreationConventionOverridden(type); } else { attributes.Add(this._sharingBoundary == null ? new SharedAttribute() : new SharedAttribute(this._sharingBoundary)); } } //Add metadata attributes from direct specification if (this._metadataItems != null) { bool isConfigured = type.GetTypeInfo().GetFirstAttribute <PartMetadataAttribute>() != null; if (isConfigured) { CompositionTrace.Registration_PartMetadataConventionOverridden(type); } else { foreach (var item in this._metadataItems) { attributes.Add(new PartMetadataAttribute(item.Item1, item.Item2)); } } } //Add metadata attributes from func specification if (this._metadataItemFuncs != null) { bool isConfigured = type.GetTypeInfo().GetFirstAttribute <PartMetadataAttribute>() != null; if (isConfigured) { CompositionTrace.Registration_PartMetadataConventionOverridden(type); } else { foreach (var item in this._metadataItemFuncs) { var name = item.Item1; var value = (item.Item2 != null) ? item.Item2(type) : null; attributes.Add(new PartMetadataAttribute(name, value)); } } } if (this._interfaceExports.Any()) { if (this._typeExportBuilders != null) { bool isConfigured = type.GetTypeInfo().GetFirstAttribute <ExportAttribute>() != null || MemberHasExportMetadata(type.GetTypeInfo()); if (isConfigured) { CompositionTrace.Registration_TypeExportConventionOverridden(type); } else { foreach (var iface in type.GetTypeInfo().ImplementedInterfaces) { if (iface == typeof(IDisposable)) { continue; } // Run through the export specifications see if any match foreach (var exportSpecification in this._interfaceExports) { if (exportSpecification.Item1 != null && exportSpecification.Item1(iface)) { ExportConventionBuilder exportBuilder = new ExportConventionBuilder(); exportBuilder.AsContractType(iface); if (exportSpecification.Item2 != null) { exportSpecification.Item2(iface, exportBuilder); } exportBuilder.BuildAttributes(iface, ref attributes); } } } } } } return(attributes); }
public void ConfigureExport(PropertyInfo propertyInfo, ExportConventionBuilder exportBuilder) { _configureExport?.Invoke(exportBuilder); }