System.Data.DataTable.CloneHierarchy C# (CSharp) Method

CloneHierarchy() private method

private CloneHierarchy ( DataTable sourceTable, DataSet ds, Hashtable visitedMap ) : DataTable
sourceTable DataTable
ds DataSet
visitedMap Hashtable
return DataTable
        private DataTable CloneHierarchy(DataTable sourceTable, DataSet ds, Hashtable visitedMap)
        {
            if (visitedMap == null)
            {
                visitedMap = new Hashtable();
            }
            if (visitedMap.Contains(sourceTable))
            {
                return ((DataTable)visitedMap[sourceTable]);
            }

            DataTable destinationTable = ds.Tables[sourceTable.TableName, sourceTable.Namespace];

            if ((destinationTable != null && destinationTable.Columns.Count > 0))
            {
                destinationTable = IncrementalCloneTo(sourceTable, destinationTable);
                // get extra columns from source into destination , increamental read
            }
            else
            {
                if (destinationTable == null)
                {
                    destinationTable = new DataTable();
                    // fxcop: new DataTable values for CaseSensitive, Locale, Namespace will come from CloneTo
                    ds.Tables.Add(destinationTable);
                }
                destinationTable = sourceTable.CloneTo(destinationTable, ds, true);
            }
            visitedMap[sourceTable] = destinationTable;

            // start cloning relation
            foreach (DataRelation r in sourceTable.ChildRelations)
            {
                DataTable childTable = CloneHierarchy(r.ChildTable, ds, visitedMap);
            }

            return destinationTable;
        }
DataTable