src/Inflatable/ClassMapper/TypeGraph/Generator.cs
/// <summary>
/// Generates the specified mapping type.
/// </summary>
/// <param name="mappingType">Type of the mapping.</param>
/// <param name="mappings">The mappings.</param>
/// <returns>The type graph associated with the type.</returns>
Generates the specified mapping type.
Generates the specified mapping type .
public static Tree<Type>? Generate(Type mappingType, Dictionary<Type, IMapping> mappings)
        {
            if (mappingType is null || !(mappings?.Keys.Contains(mappingType) ?? false))
                return null;
            var TempTypeGraph = new Tree<Type>(mappingType);
            mappingType = mappingType.BaseType;
            TreeNode<Type>? CurrentNode = TempTypeGraph.Root;
            while (!(mappingType is null))
            {
                if (mappings.Keys.Contains(mappingType))
                {
                    CurrentNode = CurrentNode.AddNode(mappingType);
                }
                mappingType = mappingType.BaseType;
            }
            while (!(CurrentNode is null))
            {
                var CurrentInterfaces = CurrentNode.Data.GetInterfaces();
                var MaxLength = CurrentInterfaces.Length;
                if (MaxLength != 0)
                {
                    var PotentialNodes = new Tree<Type>?[MaxLength];
                    for (var x = 0; x < MaxLength; x++)
                    {
                        var Interface = CurrentInterfaces[x];
                        if (!TempTypeGraph.ContainsNode(Interface, (z, y) => z == y))
                        {
                            PotentialNodes[x] = Generate(Interface, mappings);
                        }
                    }
                    for (var x = 0; x < MaxLength; ++x)
                    {
                        var PotentialNode = PotentialNodes[x];
                        if (PotentialNode is null)
                        {
                            continue;
                        }
                        for (var y = 0; y < MaxLength; ++y)
                        {
                            if (x != y && PotentialNode.ContainsNode(CurrentInterfaces[y], (i, j) => i == j))
                            {
                                PotentialNodes[y] = null;
                            }
                        }
                    }
                    for (var x = 0; x < MaxLength; ++x)
                    {
                        var PotentialNode = PotentialNodes[x];
                        if (PotentialNode is null)
                            continue;
                        PotentialNode.Root.Parent = CurrentNode;
                        CurrentNode.Nodes.Add(PotentialNode.Root);
                    }
                }
                CurrentNode = CurrentNode.Parent;
            }
            return TempTypeGraph;
        }
public static Tree < Type > ? Generate ( Type mappingType , Dictionary < Type , IMapping > mappings ) { if ( mappingType is null || ! ( mappings ? . Keys . Contains ( mappingType ) ?? false ) ) return null ; var TempTypeGraph = new Tree < Type > ( mappingType ) ; mappingType = mappingType . BaseType ; TreeNode < Type > ? CurrentNode = TempTypeGraph . Root ; while ( ! ( mappingType is null ) ) { if ( mappings . Keys . Contains ( mappingType ) ) { CurrentNode = CurrentNode . AddNode ( mappingType ) ; } mappingType = mappingType . BaseType ; } while ( ! ( CurrentNode is null ) ) { var CurrentInterfaces = CurrentNode . Data . GetInterfaces ( ) ; var MaxLength = CurrentInterfaces . Length ; if ( MaxLength != 0 ) { var PotentialNodes = new Tree < Type > ? [ MaxLength ] ; for ( var x = 0 ; x < MaxLength ; x ++ ) { var Interface = CurrentInterfaces [ x ] ; if ( ! TempTypeGraph . ContainsNode ( Interface , ( z , y ) => z == y ) ) { PotentialNodes [ x ] = Generate ( Interface , mappings ) ; } } for ( var x = 0 ; x < MaxLength ; ++ x ) { var PotentialNode = PotentialNodes [ x ] ; if ( PotentialNode is null ) { continue ; } for ( var y = 0 ; y < MaxLength ; ++ y ) { if ( x != y && PotentialNode . ContainsNode ( CurrentInterfaces [ y ] , ( i , j ) => i == j ) ) { PotentialNodes [ y ] = null ; } } } for ( var x = 0 ; x < MaxLength ; ++ x ) { var PotentialNode = PotentialNodes [ x ] ; if ( PotentialNode is null ) continue ; PotentialNode . Root . Parent = CurrentNode ; CurrentNode . Nodes . Add ( PotentialNode . Root ) ; } } CurrentNode = CurrentNode . Parent ; } return TempTypeGraph ; }
Generates the specified mapping type.
Generates the specified mapping type .
The type graph associated with the type.
The type graph associated with the type .
mappingType
Type
Type of the mapping.
Type of the mapping .
mappings
Dictionary<Type, IMapping>
None