BO4E/BO/BusinessObject.cs
/// <summary>
///     recursive function to return all expandable fields for a given type <paramref name="type" />.
///     Set <paramref name="rootLevel" /> when calling from outside the function itself.
/// </summary>
/// <param name="type">Type inherited from Business Object</param>
/// <param name="rootLevel">true iff calling from outside the function itself / default</param>
/// <returns>HashSet of strings</returns>
recursive function to return all expandable fields for a given type .
Set  when calling from outside the function itself.
recursive function to return all expandable fields for a given type . Set when calling from outside the function itself .
protected static Dictionary<string, Type> GetExpandablePropertyNames(Type type, bool rootLevel = true)
        {
            if (rootLevel && !type.IsSubclassOf(typeof(BusinessObject)))
                throw new ArgumentException("Only allowed for BusinessObjects");
            var result = new Dictionary<string, Type>();
            foreach (var prop in type.GetProperties())
            {
                string fieldName;
                var jpa = prop.GetCustomAttribute<JsonPropertyAttribute>();
                if (jpa?.PropertyName != null)
                    fieldName = jpa.PropertyName;
                else
                    fieldName = prop.Name;
                if (prop.PropertyType.IsSubclassOf(typeof(BusinessObject)))
                {
                    foreach (var subResult in GetExpandablePropertyNames(prop.PropertyType, false))
                        result.Add(string.Join(".", fieldName, subResult.Key), subResult.Value);
                    result.Add(fieldName, prop.PropertyType);
                }
                else if (prop.PropertyType.IsSubclassOf(typeof(COM.COM)))
                {
                    result.Add(fieldName, prop.PropertyType);
                }
                else if (prop.PropertyType.IsGenericType &&
                         prop.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
                {
                    var listElementType = prop.PropertyType.GetGenericArguments()[0];
                    foreach (var subResult in GetExpandablePropertyNames(listElementType, false))
                        result.Add(string.Join(".", fieldName, subResult.Key), subResult.Value);
                    result.Add(fieldName, prop.PropertyType);
                }
            }
            return result;
        }
protected static Dictionary < string , Type > GetExpandablePropertyNames ( Type type , bool rootLevel = true ) { if ( rootLevel && ! type . IsSubclassOf ( typeof ( BusinessObject ) ) ) throw new ArgumentException ( " " ) ; var result = new Dictionary < string , Type > ( ) ; foreach ( var prop in type . GetProperties ( ) ) { string fieldName ; var jpa = prop . GetCustomAttribute < JsonPropertyAttribute > ( ) ; if ( jpa ? . PropertyName != null ) fieldName = jpa . PropertyName ; else fieldName = prop . Name ; if ( prop . PropertyType . IsSubclassOf ( typeof ( BusinessObject ) ) ) { foreach ( var subResult in GetExpandablePropertyNames ( prop . PropertyType , false ) ) result . Add ( string . Join ( " " , fieldName , subResult . Key ) , subResult . Value ) ; result . Add ( fieldName , prop . PropertyType ) ; } else if ( prop . PropertyType . IsSubclassOf ( typeof ( COM . COM ) ) ) { result . Add ( fieldName , prop . PropertyType ) ; } else if ( prop . PropertyType . IsGenericType && prop . PropertyType . GetGenericTypeDefinition ( ) == typeof ( List < > ) ) { var listElementType = prop . PropertyType . GetGenericArguments ( ) [ 0 ] ; foreach ( var subResult in GetExpandablePropertyNames ( listElementType , false ) ) result . Add ( string . Join ( " " , fieldName , subResult . Key ) , subResult . Value ) ; result . Add ( fieldName , prop . PropertyType ) ; } } return result ; }
recursive function to return all expandable fields for a given type .
recursive function to return all expandable fields for a given type .
// coms do not contain any exandable subfield since they're flat
HashSet of strings
HashSet of strings
type
Type
Type inherited from Business Object
Type inherited from Business Object
rootLevel
bool
true iff calling from outside the function itself / default
true iff calling from outside the function itself / default