예제 #1
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="member"></param>
 /// <param name="importDescription"></param>
 /// <param name="creationPolicy">Política de criação.</param>
 public ProviderImportDefinition(Lazy <MemberInfo> member, ImportDescription importDescription, System.ComponentModel.Composition.CreationPolicy creationPolicy) : base(CompositionServices.GetContractNameFromImportDescription(member, importDescription), CompositionServices.GetTypeIdentityFromImportDescription(member, importDescription), CompositionServices.GetMetadataFromImportDescription(member, importDescription), GetCardinality(member, importDescription.AllowDefault), importDescription.Recomposable, importDescription.Prerequisite, creationPolicy)
 {
     member.Require("member").NotNull();
     importDescription.Require("importDescription").NotNull();
     this.AllowDefault = importDescription.AllowDefault;
     _member           = member;
 }
예제 #2
0
 /// <summary>
 /// Recupera uma lista de todas as definições de import da parte.
 /// </summary>
 /// <param name="part"></param>
 /// <param name="providerParameterImportContainer"></param>
 /// <returns></returns>
 private Lazy <IEnumerable <ImportDefinition> > GetImportDefinitions(PartDescription part, ProviderParameterImportDefinitionContainer providerParameterImportContainer)
 {
     return(new Lazy <IEnumerable <ImportDefinition> >(() => {
         var imports = new List <ImportDefinition>();
         foreach (var i in part.Imports)
         {
             ImportDescription import = i;
             imports.Add(new ProviderImportDefinition(new Lazy <System.Reflection.MemberInfo>(() => GetMemberInfo(part.TypeName, import.MemberName), false), import, part.PartCreationPolicy));
         }
         foreach (var i in providerParameterImportContainer.GetImportDefinitions())
         {
             imports.Add(i);
         }
         return imports;
     }));
 }
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="parameter"></param>
 /// <param name="importDescription"></param>
 /// <param name="creationPolicy"></param>
 public ProviderParameterImportDefinition(System.Reflection.ParameterInfo parameter, ImportDescription importDescription, System.ComponentModel.Composition.CreationPolicy creationPolicy) : base(CompositionServices.GetContractNameFromImportDescription(parameter, importDescription), CompositionServices.GetTypeIdentityFromImportDescription(parameter, importDescription), CompositionServices.GetMetadataFromImportDescription(parameter, importDescription), System.ComponentModel.Composition.Primitives.ImportCardinality.ExactlyOne, importDescription.Recomposable, importDescription.Prerequisite, creationPolicy)
 {
     parameter.Require("parameter").NotNull();
     importDescription.Require("importDescription").NotNull();
     this.AllowDefault = importDescription.AllowDefault;
     this.Parameter    = parameter;
 }
예제 #4
0
        /// <summary>
        /// Recupera o nome do contrato do <see cref="MemberInfo"/> e <see cref="ImportDescription"/>.
        /// </summary>
        /// <param name="member">Informações do membro.</param>
        /// <param name="importDescription">Informações sobre a definição do import.</param>
        /// <returns>Nome do contrato.</returns>
        public static string GetContractNameFromImportDescription(Lazy <MemberInfo> member, ImportDescription importDescription)
        {
            member.Require("member").NotNull();
            importDescription.Require("importDescription").NotNull();
            if (!string.IsNullOrEmpty(importDescription.ContractName))
            {
                return(importDescription.ContractName);
            }
            if (importDescription.ContractType != null)
            {
                return(AttributedModelServices.GetContractName(importDescription.ContractType));
            }
            var memberValue = member.Value;

            if (memberValue == null)
            {
                throw new InvalidOperationException("member is null");
            }
            if (memberValue.MemberType == MemberTypes.Method)
            {
                return(AttributedModelServices.GetTypeIdentity((MethodInfo)memberValue));
            }
            else if (memberValue.MemberType == MemberTypes.Constructor)
            {
                return(AttributedModelServices.GetContractName(memberValue.GetDefaultTypeFromMember()));
            }
            return(AttributedModelServices.GetContractName(memberValue.GetDefaultTypeFromMember()));
        }
예제 #5
0
 /// <summary>
 /// Recupera a identidade do para paremtro.
 /// </summary>
 /// <param name="parameterInfo"></param>
 /// <param name="import"></param>
 /// <returns></returns>
 public static string GetTypeIdentityFromImportDescription(this ParameterInfo parameterInfo, ImportDescription import)
 {
     if (import.ContractTypeName != null)
     {
         return(import.ContractTypeName.FullName);
     }
     if (import.ContractType != null)
     {
         return(AttributedModelServices.GetTypeIdentity(import.ContractType));
     }
     return(AttributedModelServices.GetTypeIdentity(parameterInfo.ParameterType));
 }
예제 #6
0
        /// <summary>
        /// Recupera a identidade do tipo com base na descrição do import.
        /// </summary>
        /// <param name="member"></param>
        /// <param name="import"></param>
        /// <returns></returns>
        public static string GetTypeIdentityFromImportDescription(this Lazy <MemberInfo> member, ImportDescription import)
        {
            if (import.ContractTypeName != null)
            {
                return(import.ContractTypeName.FullName);
            }
            if (import.ContractType != null)
            {
                return(AttributedModelServices.GetTypeIdentity(import.ContractType));
            }
            var memberValue = member.Value;

            if (memberValue == null)
            {
                throw new InvalidOperationException("member is null");
            }
            if (memberValue.MemberType == MemberTypes.Method)
            {
                return(AttributedModelServices.GetTypeIdentity((MethodInfo)memberValue));
            }
            if (memberValue.MemberType == MemberTypes.Method)
            {
                return(AttributedModelServices.GetTypeIdentity((MethodInfo)memberValue));
            }
            return(AttributedModelServices.GetTypeIdentity(memberValue.GetDefaultTypeFromMember()));
        }
예제 #7
0
        /// <summary>
        /// Recupera os metadados de um descrição de import.
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="importDescription"></param>
        /// <returns></returns>
        public static IEnumerable <KeyValuePair <string, Type> > GetMetadataFromImportDescription(this ParameterInfo parameter, ImportDescription importDescription)
        {
            parameter.Require("parameter").NotNull();
            importDescription.Require("importDescription").NotNull();
            var metadata = new Dictionary <string, Type>();

            return(metadata);
        }
예제 #8
0
 /// <summary>
 /// Recupera o nome do contrato do <see cref="ParameterInfo"/> e <see cref="ExportDescription"/>
 /// </summary>
 /// <param name="member">Informações sobre o membro.</param>
 /// <param name="importDescription">Informações sobre a definição de export.</param>
 /// <returns>Nome do contrato.</returns>
 public static string GetContractNameFromImportDescription(ParameterInfo member, ImportDescription importDescription)
 {
     member.Require("member").NotNull();
     importDescription.Require("importDescription").NotNull();
     if (!string.IsNullOrEmpty(importDescription.ContractName))
     {
         return(importDescription.ContractName);
     }
     if (importDescription.ContractType != null)
     {
         return(AttributedModelServices.GetContractName(importDescription.ContractType));
     }
     return(AttributedModelServices.GetContractName(member.ParameterType));
 }