/// <summary> /// Calculates the target rank. /// </summary> /// <param name="metadata">The metadata.</param> /// <returns>The rank.</returns> public virtual int?CalculateTargetRank(UIComponentMetadata metadata) { if (!IsNameApplicable(metadata.Name)) { return(null); } int?depthOfTypeInheritance = GetDepthOfInheritance(TargetTypes, metadata.ComponentType); if (depthOfTypeInheritance == null) { return(null); } int?depthOfParentTypeInheritance = GetDepthOfInheritance(TargetParentTypes, metadata.ParentComponentType); if (depthOfParentTypeInheritance == null) { return(null); } int rank = 0; int rankFactor = 100000; if (TargetNames != null && TargetNames.Any()) { rank += rankFactor; } rankFactor /= 2; if (depthOfTypeInheritance >= 0) { rank += Math.Max(rankFactor - (depthOfTypeInheritance.Value * 100), 0); } rankFactor /= 2; if (depthOfParentTypeInheritance >= 0) { rank += Math.Max(rankFactor - (depthOfParentTypeInheritance.Value * 100), 0); } return(rank); }
/// <summary> /// Determines whether the component name applies the name criteria. /// </summary> /// <param name="name">The component name.</param> /// <returns> /// <c>true</c> if the name applies the criteria; otherwise, <c>false</c>. /// </returns> public bool IsNameApplicable(string name) { return(TargetNames == null || !TargetNames.Any() || TargetNames.Contains(name)); }