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)); } }
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)); } }