示例#1
0
 /// <summary>
 /// Recupera a string da especialização do tipo informado.
 /// </summary>
 /// <param name="specialization"></param>
 /// <param name="pTypeName"></param>
 /// <returns></returns>
 private string GetSpecializationString(string specialization, Colosoft.Reflection.TypeName pTypeName)
 {
     if (!InstanceStateManager.ContainsSpecializationError(pTypeName))
     {
         string[] path = specialization.Split('.').Where(f => (!String.IsNullOrEmpty(f))).ToArray();
         object   obj  = _entity;
         for (int index = 0; index < path.Length - 1; index++)
         {
             if (obj != null)
             {
                 obj = obj.GetType().GetProperty(path[index]).GetValue(obj, null);
             }
         }
         return(_validationManager.LoadSpecilization(pTypeName).GetInstanceSpecilizationString(obj));
     }
     return(null);
 }
示例#2
0
        /// <summary>
        /// Recupera os identificadores da especialização.
        /// </summary>
        /// <param name="entityTypeName">Tipo da entidade.</param>
        /// <param name="startString"></param>
        /// <param name="clearPath">Caminho usado para limpeza na comparação</param>
        /// <param name="startPropertyName">Nome da propriedade de inicio para recuperar</param>
        /// <param name="nestedTypes">Relação dos tipos aninhadas encontrados.</param>
        /// <returns></returns>
        private Dictionary <string, string> GetIdentifierSpecialize(Colosoft.Reflection.TypeName entityTypeName, string startString, string clearPath, string startPropertyName, List <Colosoft.Reflection.TypeName> nestedTypes = null)
        {
            var result = new Dictionary <string, string>();

            if (!InstanceStateManager.ContainsSpecializationError(entityTypeName))
            {
                if (!startString.EndsWith("."))
                {
                    startString = startString + ".";
                }
                if (!clearPath.EndsWith("."))
                {
                    clearPath = clearPath + ".";
                }
                if (nestedTypes == null)
                {
                    nestedTypes = new List <Colosoft.Reflection.TypeName>();
                }
                nestedTypes.Add(entityTypeName);
                Colosoft.Validation.IEntitySpecialization specialization = null;
                try
                {
                    specialization = _validationManager.LoadSpecilization(entityTypeName);
                }
                catch (Exception ex)
                {
                    InstanceStateManager.RegisterSpecializationError(entityTypeName, null, ex);
                }
                if (specialization != null)
                {
                    if (!_specializedList.ContainsKey(clearPath))
                    {
                        _specializedList.Add(clearPath, entityTypeName);
                    }
                    var      existsAllSpecialization = false;
                    string[] specializations         = null;
                    try
                    {
                        specializations = specialization.GetSpecializations().ToArray();
                    }
                    catch (Exception ex)
                    {
                        InstanceStateManager.RegisterSpecializationError(entityTypeName, null, ex);
                        specializations = new string[0];
                    }
                    foreach (string currentSpecilizeString in specializations)
                    {
                        if (currentSpecilizeString == "*" && existsAllSpecialization)
                        {
                            existsAllSpecialization = true;
                        }
                        PutsPropertiesIdentifier(entityTypeName, nestedTypes, result, startString, clearPath, startPropertyName, currentSpecilizeString);
                    }
                    if (!existsAllSpecialization)
                    {
                        PutsPropertiesIdentifier(entityTypeName, nestedTypes, result, startString, clearPath, startPropertyName, "*");
                    }
                }
                else
                {
                    PutsPropertiesIdentifier(entityTypeName, nestedTypes, result, startString, clearPath, startPropertyName, string.Empty);
                }
                nestedTypes.Remove(entityTypeName);
            }
            return(result);
        }