コード例 #1
0
    public int CompareTo(ApiModel other)
    {
        if (other == default)
        {
            return(1);
        }

        if (Kind.IsType() && other.Kind.IsMember())
        {
            return(-1);
        }

        if (Kind.IsMember() && other.Kind.IsType())
        {
            return(1);
        }

        if (Kind.IsMember() && other.Kind.IsMember())
        {
            var result = Kind.CompareTo(other.Kind);
            if (result != 0)
            {
                return(result);
            }
        }

        if (Kind == ApiKind.Namespace && other.Kind == ApiKind.Namespace)
        {
            var orderReversed = new[]
            {
                "Windows",
                "Microsoft",
                "System",
            };

            var topLevel      = GetTopLevelNamespace(Name);
            var otherTopLevel = GetTopLevelNamespace(other.Name);

            var topLevelIndex      = Array.IndexOf(orderReversed, topLevel);
            var otherTopLevelIndex = Array.IndexOf(orderReversed, otherTopLevel);

            var result = -topLevelIndex.CompareTo(otherTopLevelIndex);
            if (result != 0)
            {
                return(result);
            }
        }

        if (GetMemberName(Name) == GetMemberName(other.Name))
        {
            var typeParameterCount      = GetTypeParameterCount(Name);
            var otherTypeParameterCount = GetTypeParameterCount(other.Name);

            var result = typeParameterCount.CompareTo(otherTypeParameterCount);
            if (result != 0)
            {
                return(result);
            }

            var parameterCount      = GetParameterCount(Name);
            var otherParameterCount = GetParameterCount(other.Name);

            result = parameterCount.CompareTo(otherParameterCount);
            if (result != 0)
            {
                return(result);
            }
        }

        return(Name.CompareTo(other.Name));
コード例 #2
0
 public string GetMemberName()
 {
     return(Kind.IsMember()
             ? Name
             : string.Empty);
 }