private static List FieldsFor()

in src/JetBrains.Space.Common/Types/Partials/Partial.cs [143:195]


    private static List<string> FieldsFor(Type forType, int currentDepth = 0, int maxDepth = 2)
    {
        var fieldNames = new List<string>();

        if (forType.IsGenericType && forType.Name == CommonTypesBatchName)
        {
            maxDepth++;
        }
        if (forType.IsGenericType && forType.Namespace != CommonTypesNamespace)
        {
            forType = forType.GetGenericArguments().First();
        }

        foreach (var propertyInfo in forType.GetProperties())
        {
            if (propertyInfo.GetCustomAttribute(typeof(JsonPropertyNameAttribute)) is JsonPropertyNameAttribute jsonPropertyName)
            {
                var fieldNameToAdd = jsonPropertyName.Name;
                var innerType = propertyInfo.PropertyType;
                if (innerType.IsGenericType)
                {
                    // Follow e.g. generic lists
                    innerType = innerType.GenericTypeArguments[0];
                }
                if ((innerType.Namespace == forType.Namespace || forType.Namespace == CommonTypesNamespace) && currentDepth < maxDepth)
                {
                    var derivedInnerTypes = FindAllDerivedTypes(innerType);
                    if (derivedInnerTypes.Count > 0)
                    {
                        // Follow all derived types of innerType
                        var innerFieldsToAdd = string.Join(",", derivedInnerTypes.SelectMany(it => FieldsFor(it, currentDepth + 1, maxDepth)));
                        if (!string.IsNullOrEmpty(innerFieldsToAdd))
                        {
                            fieldNameToAdd = $"{fieldNameToAdd}({innerFieldsToAdd})";
                        }
                    }
                    else
                    {
                        // Follow just innerType
                        var innerFieldsToAdd = string.Join(",", FieldsFor(innerType, currentDepth + 1, maxDepth));
                        if (!string.IsNullOrEmpty(innerFieldsToAdd))
                        {
                            fieldNameToAdd = $"{fieldNameToAdd}({innerFieldsToAdd})";
                        }
                    }
                }

                fieldNames.Add(fieldNameToAdd);
            }
        }

        return fieldNames;
    }