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)); } }
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)); } }
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, (attributedImport.RequiredCreationPolicy != CreationPolicy.NewScope) ? CreationPolicy.NonShared : CreationPolicy.NewScope, CompositionServices.GetImportMetadata(importType, attributedImport)))); } else { // A Standard parameter 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); } //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)); } }
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)); } }
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)); } }
// // Import definition creation helpers // private static AttributedImportDefinitionCreationInfo GetImportDefinitionCreationInfo(ReflectionItem item, ICustomAttributeProvider attributeProvider) { Assumes.NotNull(item, attributeProvider); AttributedImportDefinitionCreationInfo importCreationInfo = new AttributedImportDefinitionCreationInfo(); IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(item, attributeProvider); ImportType importType = new ImportType(item.ReturnType, attributedImport.Cardinality); DisplayDebugWarnings(attributedImport.Cardinality, item, importType); importCreationInfo.RequiredMetadata = importType.IsLazy ? CompositionServices.GetRequiredMetadata(importType.LazyType.MetadataViewType) : Enumerable.Empty <string>(); importCreationInfo.Cardinality = attributedImport.Cardinality; importCreationInfo.ContractName = attributedImport.GetContractNameFromImport(importType); importCreationInfo.RequiredTypeIdentity = attributedImport.GetTypeIdentityFromImport(importType); importCreationInfo.IsRecomposable = (item.ItemType == ReflectionItemType.Parameter) ? false : attributedImport.AllowRecomposition; importCreationInfo.RequiredCreationPolicy = attributedImport.RequiredCreationPolicy; return(importCreationInfo); }