コード例 #1
0
        /// <summary>
        /// Retrieve the best matching alias for the provided set of aliases
        /// </summary>
        /// <remarks>If an exact type/usage match is not available, then this will
        /// return the closest usage match over the closest type match. The closest
        /// matches are determined by walking up the parent hierarchy of name generators.</remarks>
        /// <param name="aliases">A set of alias elements. The best match is returned.</param>
        /// <returns>A <see cref="NameAlias"/>, or <see langword="null"/> if none is available.</returns>
        public NameAlias FindMatchingAlias(IEnumerable <NameAlias> aliases)
        {
            NameAlias       bestUsageMatch       = null;
            NameAlias       bestTypeMatch        = null;
            Type            usageType            = NameUsageType;
            DomainClassInfo thisClassInfo        = GetDomainClass();
            int             closestTypeDistance  = int.MaxValue;
            int             closestUsageDistance = int.MaxValue;

            foreach (NameAlias alias in aliases)
            {
                DomainClassInfo testClassInfo = alias.NameConsumerDomainClass;
                Type            testUsageType = alias.NameUsageType;
                if (testClassInfo == thisClassInfo)
                {
                    if (usageType == testUsageType)                     // intentionally handles two null values
                    {
                        bestUsageMatch = alias;
                        break;
                    }
                    else if (usageType != null && testUsageType == null)
                    {
                        closestTypeDistance = 0;                         // Matched self, can't get any closer
                        bestTypeMatch       = alias;
                        // Keep going to see if we get a higher priority usage match
                    }
                }
                else
                {
                    DomainClassInfo iterateClassInfo = thisClassInfo.BaseDomainClass;
                    int             testDistance     = 0;
                    do
                    {
                        ++testDistance;
                        if (iterateClassInfo == testClassInfo)
                        {
                            if (usageType == testUsageType)                             // intentionally handles two null values
                            {
                                if (testDistance < closestUsageDistance)
                                {
                                    closestUsageDistance = testDistance;
                                    bestUsageMatch       = alias;
                                }
                            }
                            else if (usageType != null && testUsageType == null)
                            {
                                if (testDistance < closestTypeDistance)
                                {
                                    closestTypeDistance = testDistance;
                                    bestTypeMatch       = alias;
                                }
                            }
                            break;
                        }
                        iterateClassInfo = iterateClassInfo.BaseDomainClass;
                    } while (iterateClassInfo != null);
                }
            }
            return(bestUsageMatch ?? bestTypeMatch);
        }
コード例 #2
0
ファイル: ModificationTracker.cs プロジェクト: ozialien/NORMA
 /// <summary>
 /// ChangeRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.NameAlias)
 /// Regenerate names when an abbreviation is changed
 /// </summary>
 private static void AbbreviationChangedRule(ElementPropertyChangedEventArgs e)
 {
     if (e.DomainProperty.Id == ORMCore.NameAlias.NameDomainPropertyId)
     {
         ORMCore.NameAlias abbreviation = (ORMCore.NameAlias)e.ModelElement;
         Store             store        = abbreviation.Store;
         if (store.DomainDataDirectory.GetDomainClass(RelationalNameGenerator.DomainClassId).IsDerivedFrom(abbreviation.NameConsumerDomainClass))
         {
             foreach (Schema schema in store.ElementDirectory.FindElements <Schema>(true))
             {
                 ValidateSchemaNamesChanged(schema);
             }
         }
     }
 }