Following on an expired more than two months, on a positive chance encounter on a business trip. I can not find the original demo program come back, so this series will put aside.
However, still have to make a case, let it complete whom little about:
Still remember that like Found: after row of the array Copy, and then array.GetEnumerator (); can be OK.
After practice, I found not feasible, so this is not possible do not write the way to avoid wasting energy and everyone looked.
The following talk about practical way:
Find SqlDataReader class by Reflector, because it also can be bound to a data source one, although often resulting in Czochralski binding link is not closed events.
By studying:
Find it inherited from DbDataReader, then, click-through DbDataReader:
Here, as long as our MDataTable inherited from the middle of the IDataReader, IEnumerable two can, you can achieve the binding of the road.
After inheriting, of course, it is to achieve the other interfaces:
public void Close()
{
_Mdr.Clear();
}
public int Depth
{
get
{
if (_Mdr != null )
{
return _Mdr.Count;
}
return 0 ;
}
}
public DataTable GetSchemaTable()
{
return null ;
}
public bool IsClosed
{
get
{
return true ;
}
}
public bool NextResult()
{
if (_Ptr < _Mdr.Count - 1 )
{
return true ;
}
else
{
return false ;
}
}
public bool Read()
{
if (_Ptr < _Mdr.Count)
{
_Ptr ++ ;
return true ;
}
else
{
return false ;
}
}
public int RecordsAffected
{
get
{
return - 1 ;
}
}
#endregion
#region IDataRecord 成员
private int _Ptr = 0 ;
public int FieldCount
{
get
{
if ( this .Columns != null )
{
return this .Columns.Count;
}
return 0 ;
}
}
public bool GetBoolean( int i)
{
return ( bool )_Mdr[_Ptr][i].Value;
}
public byte GetByte( int i)
{
return ( byte )_Mdr[_Ptr][i].Value;
}
public long GetBytes( int i, long fieldOffset, byte [] buffer, int bufferoffset, int length)
{
throw new Exception( " The method or operation is not implemented. " );
}
public char GetChar( int i)
{
return ( char )_Mdr[_Ptr][i].Value;
}
public long GetChars( int i, long fieldoffset, char [] buffer, int bufferoffset, int length)
{
throw new Exception( " The method or operation is not implemented. " );
}
public IDataReader GetData( int i)
{
return this ;
}
public string GetDataTypeName( int i)
{
return DataType.GetDbTypeFromSqlDbType(_Mdr[_Ptr].Columns[i].SqlType.ToString()).ToString();
}
public DateTime GetDateTime( int i)
{
return (DateTime)_Mdr[_Ptr][i].Value;
}
public decimal GetDecimal( int i)
{
return ( decimal )_Mdr[_Ptr][i].Value;
}
public double GetDouble( int i)
{
return ( double )_Mdr[_Ptr][i].Value;
}
public Type GetFieldType( int i)
{
return Type.GetType( " System. " + GetDataTypeName(i));
}
public float GetFloat( int i)
{
return ( float )_Mdr[_Ptr][i].Value;
}
public Guid GetGuid( int i)
{
return (Guid)_Mdr[_Ptr][i].Value;
}
public short GetInt16( int i)
{
return ( short )_Mdr[_Ptr][i].Value;
}
public int GetInt32( int i)
{
return ( int )_Mdr[_Ptr][i].Value;
}
public long GetInt64( int i)
{
return ( long )_Mdr[_Ptr][i].Value;
}
public string GetName( int i)
{
return _Mdr[_Ptr][i].ColumnName;
}
public int GetOrdinal( string name)
{
throw new Exception( " The method or operation is not implemented. " );
}
public string GetString( int i)
{
return _Mdr[_Ptr][i].ColumnName.ToString();
}
public object GetValue( int i)
{
return null ;
// return _Mdr[_Ptr][i-1].Value;
}
public int GetValues( object [] values)
{
for ( int i = 0 ; i < values.Length; i ++ )
{
values[i] = _Mdr[_Ptr - 1 ][i].Value;
}
return values.Length;
}
public bool IsDBNull( int i)
{
return _Mdr[_Ptr][i].IsNull;
}
public object this [ string name]
{
get
{
return null ;
}
}
public object this [ int i]
{
get
{
return _Mdr[i];
}
}
#endregion
#region IEnumerable 成员
public IEnumerator GetEnumerator()
{
return new System.Data.Common.DbEnumerator( this );
}
#endregion
So far, MDataTable have a DataTable can replace commonly used.
Also it has a common row, column, data structures, bound controls and other functions.
Reproduced in: https: //my.oschina.net/secyaher/blog/274366