当前位置: 首页>>代码示例>>C#>>正文


C# DataColumn.GetType方法代码示例

本文整理汇总了C#中Altaxo.Data.DataColumn.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DataColumn.GetType方法的具体用法?C# DataColumn.GetType怎么用?C# DataColumn.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Altaxo.Data.DataColumn的用法示例。


在下文中一共展示了DataColumn.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XYVToMatrix

		/// <summary>
		/// Creates a matrix from three selected columns. This must be a x-column, a y-column, and a value column.
		/// </summary>
		/// <param name="xcol">Column of x-values.</param>
		/// <param name="ycol">Column of y-values.</param>
		/// <param name="vcol">Column of v-values.</param>
		/// <param name="originalTable">The source table. This is only needed to get the names of the columns.</param>
		/// <param name="newtable">On return, contains the newly created table matrix.</param>
		/// <returns>Null if no error occurs, or an error message.</returns>
		public static string XYVToMatrix(DataColumn xcol, DataColumn ycol, DataColumn vcol, DataTable originalTable, out DataTable newtable)
		{
			newtable = null;
			System.Collections.SortedList xx = new System.Collections.SortedList();
			System.Collections.SortedList yy = new System.Collections.SortedList();
			int len = xcol.Count;
			len = Math.Min(len, ycol.Count);
			len = Math.Min(len, vcol.Count);

			// Fill the xx and yy lists
			for (int i = 0; i < len; ++i)
			{
				if (!xx.Contains(xcol[i]))
					xx.Add(xcol[i], null);

				if (!yy.Contains(ycol[i]))
					yy.Add(ycol[i], null);
			}

			DataColumn xnew = (DataColumn)Activator.CreateInstance(xcol.GetType());
			DataColumn ynew = (DataColumn)Activator.CreateInstance(ycol.GetType());
			xnew.Clear();
			ynew.Clear();

			for (int i = xx.Count - 1; i >= 0; --i)
			{
				xnew[i] = (AltaxoVariant)xx.GetKey(i);
				xx[xx.GetKey(i)] = i;
			}

			for (int i = yy.Count - 1; i >= 0; --i)
			{
				ynew[1 + i] = (AltaxoVariant)yy.GetKey(i); // 1 + is because the table will get an additional x-column
				yy[yy.GetKey(i)] = i;
			}

			DataColumn vtemplate = (DataColumn)Activator.CreateInstance(vcol.GetType());

			// make a new table with yy.Count number of columns
			DataColumn[] vcols = new DataColumn[yy.Count];
			for (int i = yy.Count - 1; i >= 0; --i)
			{
				vcols[i] = (DataColumn)vtemplate.Clone();
			}

			// now fill the columns
			for (int i = 0; i < len; ++i)
			{
				int xidx = (int)xx[xcol[i]];
				int yidx = (int)yy[ycol[i]];

				vcols[yidx][xidx] = vcol[i];
			}

			// assemble all columns together in a table
			newtable = new DataTable();

			// add the x-column to the data collection
			string xname = null;
			if (null != originalTable)
				xname = originalTable.DataColumns.GetNameOfChildObject(xcol);
			if (string.IsNullOrEmpty(xname))
				xname = "X";
			newtable.DataColumns.Add(xnew, xname, ColumnKind.X, 0);

			// add the y-column to the property collection
			string yname = null;
			if (null != originalTable)
				yname = originalTable.DataColumns.GetNameOfChildObject(ycol);
			if (string.IsNullOrEmpty(yname))
				yname = "Y";
			newtable.PropertyColumns.Add(ynew, yname, ColumnKind.Y, 0);

			// add the v-columns to the data collection
			string vname = null;
			if (null != originalTable)
				vname = originalTable.DataColumns.GetNameOfChildObject(vcol);
			if (string.IsNullOrEmpty(vname))
				vname = "V";
			for (int i = 0; i < vcols.Length; ++i)
				newtable.DataColumns.Add(vcols[i], vname + i.ToString(), ColumnKind.V, 0);

			return null;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:93,代码来源:EditCommands.cs

示例2: GetFractionalIndex

		/// <summary>
		/// Gets the fractional index for merging of two tables.
		/// </summary>
		/// <param name="masterColumn">X-column of the master table.</param>
		/// <param name="slaveColumn">X-column of the slave table.</param>
		/// <returns>Array of fractional indices. Each item points into the slaveTable to the value that should be included in the master column at the item's index.</returns>
		public static DoubleColumn GetFractionalIndex(DataColumn masterColumn, DataColumn slaveColumn)
		{
			if (masterColumn is DateTimeColumn && slaveColumn is DateTimeColumn)
				return GetFractionalIndex((DateTimeColumn)masterColumn, (DateTimeColumn)slaveColumn);

			if (masterColumn is INumericColumn && slaveColumn is INumericColumn)
				return GetFractionalIndex((INumericColumn)masterColumn, (INumericColumn)slaveColumn);

			throw new ArgumentException(string.Format("Unable to create fractional index from columns of type {0} and {1}", masterColumn.GetType(), slaveColumn.GetType()));
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:16,代码来源:MergeTables.cs

示例3: CopyOrReplaceOrAdd

 /// <summary>
 /// Copies the data of the column (columns have same type, index is inside bounds), or replaces 
 /// the column (columns of different types, index inside bounds), or adds the column (index outside bounds).
 /// </summary>
 /// <param name="index">The column position where to replace or add.</param>
 /// <param name="datac">The column from which the data should be copied or which should replace the existing column or which should be added.</param>
 /// <param name="name">The name under which the column should be stored.</param>
 public void CopyOrReplaceOrAdd(int index, DataColumn datac, string name)
 {
   if(index<ColumnCount)
   {
     if(this[index].GetType().Equals(datac.GetType()))
     {
       this[index].CopyDataFrom(datac);
     }
     else
     {
       // if the column to add has a parent, we can not add the column directly (we are then not the owner), so we clone it
       Replace(index,datac.ParentObject==null ? datac : (DataColumn)datac.Clone());
     }
   }
   else
   {
     // if the column to add has a parent, we can not add the column directly (we are then not the owner), so we clone it
     Add(datac.ParentObject==null ? datac : (DataColumn)datac.Clone(), name);
   }
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:27,代码来源:DataColumnCollection.cs


注:本文中的Altaxo.Data.DataColumn.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。