Exemplo n.º 1
0
        public IFrame Merge(IFrame frame0, IFrame frame1, Guid newFrameId)
        {
            BasicFrame merged = null;
            if (frame0.RowCount != frame1.RowCount)
            {
                throw new ArgumentException(string.Format("The input frames must have the same number of rows before being merged."));
            }
            if (!(frame0 is BasicFrame))
                throw new ArgumentException(string.Format("Invalid type: must be of type {0}.", typeof(BasicFrame).Name), "frame0");
            if (!(frame1 is BasicFrame))
                throw new ArgumentException(string.Format("Invalid type: must be of type {0}.", typeof(BasicFrame).Name), "frame1");
            if (frame0 == frame1)
            {
                throw new ArgumentException(string.Format("Both input frame parameters represent the same instance.  A frame cannot be merged with itself."));
            }

            BasicFrame baseFrame0 = frame0 as BasicFrame;
            BasicFrame baseFrame1 = frame1 as BasicFrame;

            merged = frame0.GetCopy(newFrameId) as BasicFrame;

            int[] colIndices = new int[baseFrame1.Columns.Count];
            for (int i = 0; i < baseFrame1.Columns.Count; i++)
            {
                string [] existingColNames = merged.ColumnNames;
                DataColumn column = new DataColumn(
                    NamingHelper.MakeUnique(existingColNames, baseFrame1.Columns[i].ColumnName),
                    baseFrame1.Columns[i].DataType);
                colIndices[i] = merged.Columns.Count;
                merged.Columns.Add(column);
            }
            for (int i = 0; i < merged.Rows.Count; i++)
            {
                for (int j = 0; j < colIndices.Length; j++)
                {
                    merged.Rows[i][colIndices[j]] = baseFrame1.Rows[i][j];
                }
            }

            merged.AcceptChanges();
            return merged;
        }