質問

I have an extension method for calculating the distance between a base type and a derived type, such that the same type would have return a value of 0 and a direct subtype would return a value of 1. What is the most concise and commonly used term to describe this scalar quantity?

To be more specific, what could I name the following method that would make sense and effectively communicate the intention?

    public static int? CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(this Type baseType, Type descendantType)
    {
        baseType = baseType ?? typeof(System.Object);
        descendantType = descendantType ?? typeof(System.Object);
        if (!baseType.IsAssignableFrom(descendantType))
            return descendantType.IsAssignableFrom(baseType)
                       ? -1*CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(descendantType, baseType)
                       : null;
        if (baseType == descendantType)
            return 0;
        return CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(baseType, descendantType.BaseType) + 1;
    }
役に立ちましたか?

解決

I think the term you're looking for is Depth of Inheritance.

Depth of inheritance, also called depth of inheritance tree (DIT), is defined as “the maximum length from the node to the root of the tree”

他のヒント

Bill the Lizard may be on to something. However, as a generalized option relating to Graph Theory, you could refer to it as LengthOfPathToDerivedClass.

Length of a Link, Connection or Path. Refers to the label associated with a link, a connection or a path. This label can be distance, the amount of traffic, the capacity or any attribute of that link. The length of a path is the number of links (or connections) in this path.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top