/// <summary> /// Gets an <see cref="ImportDefinition"/> for a <see cref="MemberInfo"/> instance using the provided <see cref="IImportConvention"/> instance. /// </summary> /// <param name="importConvention"><see cref="IImportConvention"/> instances that should be used to create the <see cref="ImportDefinition"/> instances.</param> /// <param name="member">The <see cref="MemberInfo"/> for which the <see cref="ImportDefinition"/> instances should be created.</param> /// <returns>An <see cref="ImportDefinition"/> instance.</returns> private ImportDefinition GetImportDefinition(IImportConvention importConvention, MemberInfo member) { return(ReflectionModelServices.CreateImportDefinition( member.ToLazyMemberInfo(), this.ContractService.GetImportContractName(importConvention, member), this.ContractService.GetImportTypeIdentity(importConvention, member), importConvention.RequiredMetadata.Select(x => new KeyValuePair <string, Type>(x.Name, x.Type)), member.GetCardinality(importConvention.AllowDefaultValue), importConvention.Recomposable, importConvention.CreationPolicy, null)); }
/// <summary> /// Gets an <see cref="ImportDefinition"/> for a <see cref="ParameterInfo"/> instance using the provided <see cref="IImportConvention"/> instance. /// </summary> /// <param name="importConvention"><see cref="IImportConvention"/> instances that should be used to create the <see cref="ImportDefinition"/> instances.</param> /// <param name="parameter">The <see cref="ParameterInfo"/> for which the <see cref="ImportDefinition"/> instances should be created.</param> /// <returns>An <see cref="ImportDefinition"/> instance.</returns> private ImportDefinition GetImportParameterDefinition(IImportConvention importConvention, ParameterInfo parameter) { var actualType = parameter.ParameterType.GetActualType(); return(ReflectionModelServices.CreateImportDefinition( new Lazy <ParameterInfo>(() => parameter), this.ContractService.GetImportContractName(importConvention, actualType), this.ContractService.GetImportTypeIdentity(importConvention, actualType), null, parameter.ParameterType.GetCardinality(importConvention.AllowDefaultValue), importConvention.CreationPolicy, null)); }
/// <summary> /// Gets type identity for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the type identity should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the type identity for the imported.</returns> /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception> public virtual string GetImportTypeIdentity(IImportConvention importConvention, MemberInfo member) { if (importConvention == null) { throw new ArgumentNullException("importConvention", "The import convention cannot be null."); } if (member == null) { throw new ArgumentNullException("member", "The member cannot be null."); } return(ContractServices.GetImportTypeIdentity( (importConvention.ContractType == null) ? null : importConvention.ContractType.Invoke(member), member)); }
/// <summary> /// Gets contract name for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the contract name should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the contract name for the import.</returns> /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception> public override string GetImportContractName(IImportConvention importConvention, MemberInfo member) { if (member == null) { throw new ArgumentNullException("member", "The member cannot be null."); } var contractMember = member.GetContractMember(); var defaultContractName = this.DefaultConventions.Where(x => x.TargetType.Equals(contractMember)) .Select(x => x.ContractName).LastOrDefault(); return(defaultContractName ?? base.GetImportContractName(importConvention, member)); }
/// <summary> /// Gets contract name for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the contract name should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the contract name for the import.</returns> /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception> public virtual string GetImportContractName(IImportConvention importConvention, MemberInfo member) { if (importConvention == null) { throw new ArgumentNullException("importConvention", "The import convention cannot be null."); } if (member == null) { throw new ArgumentNullException("member", "The member cannot be null."); } return ContractServices.GetImportContractName( (importConvention.ContractName == null) ? null : importConvention.ContractName.Invoke(member), (importConvention.ContractType == null) ? null : importConvention.ContractType.Invoke(member), member); }
/// <summary> /// Gets an <see cref="ImportDefinition"/> for a <see cref="MemberInfo"/> instance using the provided <see cref="IImportConvention"/> instance. /// </summary> /// <param name="importConvention"><see cref="IImportConvention"/> instances that should be used to create the <see cref="ImportDefinition"/> instances.</param> /// <param name="member">The <see cref="MemberInfo"/> for which the <see cref="ImportDefinition"/> instances should be created.</param> /// <returns>An <see cref="ImportDefinition"/> instance.</returns> private ImportDefinition GetImportDefinition(IImportConvention importConvention, MemberInfo member) { return ReflectionModelServices.CreateImportDefinition( member.ToLazyMemberInfo(), this.ContractService.GetImportContractName(importConvention, member), this.ContractService.GetImportTypeIdentity(importConvention, member), importConvention.RequiredMetadata.Select(x => new KeyValuePair<string, Type>(x.Name, x.Type)), member.GetCardinality(importConvention.AllowDefaultValue), importConvention.Recomposable, importConvention.CreationPolicy, null); }
/// <summary> /// Gets an <see cref="ImportDefinition"/> for a <see cref="ParameterInfo"/> instance using the provided <see cref="IImportConvention"/> instance. /// </summary> /// <param name="importConvention"><see cref="IImportConvention"/> instances that should be used to create the <see cref="ImportDefinition"/> instances.</param> /// <param name="parameter">The <see cref="ParameterInfo"/> for which the <see cref="ImportDefinition"/> instances should be created.</param> /// <returns>An <see cref="ImportDefinition"/> instance.</returns> private ImportDefinition GetImportParameterDefinition(IImportConvention importConvention, ParameterInfo parameter) { var actualType = parameter.ParameterType.GetActualType(); return ReflectionModelServices.CreateImportDefinition( new Lazy<ParameterInfo>(() => parameter), this.ContractService.GetImportContractName(importConvention, actualType), this.ContractService.GetImportTypeIdentity(importConvention, actualType), null, parameter.ParameterType.GetCardinality(importConvention.AllowDefaultValue), importConvention.CreationPolicy, null); }
/// <summary> /// Gets type identity for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the type identity should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the type identity for the imported.</returns> private static string GetImportTypeIdentity(IImportConvention importConvention, MemberInfo member) { if (importConvention.ContractType == null) { return AttributedModelServices.GetTypeIdentity(member.GetContractMember()); } if (importConvention.ContractType.Invoke(member).Equals(typeof(object))) { return null; } var memberType = member.GetContractMember(); return memberType.IsSubclassOf(typeof(Delegate)) ? AttributedModelServices.GetTypeIdentity(memberType.GetMethod("Invoke")) : AttributedModelServices.GetTypeIdentity(importConvention.ContractType.Invoke(member)); }
/// <summary> /// Gets contract name for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the contract name should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the contract name for the import.</returns> private static string GetImportContractName(IImportConvention importConvention, MemberInfo member) { if (importConvention.ContractName != null) { return importConvention.ContractName.Invoke(member); } return importConvention.ContractType != null ? AttributedModelServices.GetTypeIdentity(importConvention.ContractType.Invoke(member)) : AttributedModelServices.GetTypeIdentity(member.GetContractMember()); }
/// <summary> /// Gets type identity for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the type identity should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the type identity for the imported.</returns> /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception> public override string GetImportTypeIdentity(IImportConvention importConvention, MemberInfo member) { if (member == null) { throw new ArgumentNullException("member", "The member cannot be null."); } var contractMember = member.GetContractMember(); var defaultContractType = this.DefaultConventions.Where(x => x.TargetType.Equals(contractMember)) .Select(x => x.ContractType).LastOrDefault(); return defaultContractType != null ? AttributedModelServices.GetTypeIdentity(defaultContractType) : base.GetImportTypeIdentity(importConvention, member); }
/// <summary> /// Gets contract name for the provided <see cref="IImportConvention"/>. /// </summary> /// <param name="importConvention">The <see cref="IImportConvention"/> that the contract name should be retreived for.</param> /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param> /// <returns>A <see cref="string"/> containing the contract name for the import.</returns> /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception> public override string GetImportContractName(IImportConvention importConvention, MemberInfo member) { if (member == null) { throw new ArgumentNullException("member", "The member cannot be null."); } var contractMember = member.GetContractMember(); var defaultContractName = this.DefaultConventions.Where(x => x.TargetType.Equals(contractMember)) .Select(x => x.ContractName).LastOrDefault(); return defaultContractName ?? base.GetImportContractName(importConvention, member); }