From d9e209b0c3b473932d87d94b174b254a73375890 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 15 Aug 2024 10:37:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20MiniExcelDataR?= =?UTF-8?q?eaderBase=20=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniExcel/MiniExcelDataReaderBase.cs | 251 +++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 src/MiniExcel/MiniExcelDataReaderBase.cs diff --git a/src/MiniExcel/MiniExcelDataReaderBase.cs b/src/MiniExcel/MiniExcelDataReaderBase.cs new file mode 100644 index 00000000..b8895317 --- /dev/null +++ b/src/MiniExcel/MiniExcelDataReaderBase.cs @@ -0,0 +1,251 @@ +namespace MiniExcelLibs +{ + using System; + using System.Data; + + /// + /// IDataReader 实现类基类 + /// + public abstract class MiniExcelDataReaderBase : IDataReader + { + /// + /// + /// + /// + /// + public virtual object this[int i] => null; + + /// + /// + /// + /// + /// + public virtual object this[string name] => null; + + /// + /// + /// + public virtual int Depth { get; } = 0; + + /// + /// + /// + public virtual bool IsClosed { get; } = false; + + /// + /// + /// + public virtual int RecordsAffected { get; } = 0; + + /// + /// + /// + public virtual int FieldCount { get; } + + /// + /// + /// + /// + /// + public virtual bool GetBoolean(int i) => false; + + /// + /// + /// + /// + /// + public virtual byte GetByte(int i) => byte.MinValue; + + /// + /// + /// + /// + /// + /// + /// + /// + /// + public virtual long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferOffset, int length) => 0; + + /// + /// + /// + /// + /// + public virtual char GetChar(int i) => char.MinValue; + + /// + /// + /// + /// + /// + /// + /// + /// + /// + public virtual long GetChars(int i, long fieldOffset, char[] buffer, int bufferOffset, int length) => 0; + + /// + /// + /// + /// + /// + public virtual IDataReader GetData(int i) => null; + + /// + /// + /// + /// + /// + public virtual string GetDataTypeName(int i) => string.Empty; + + /// + /// + /// + /// + /// + public virtual DateTime GetDateTime(int i) => DateTime.MinValue; + + /// + /// + /// + /// + /// + public virtual decimal GetDecimal(int i) => 0; + + /// + /// + /// + /// + /// + public virtual double GetDouble(int i) => 0; + + /// + /// + /// + /// + /// + public virtual Type GetFieldType(int i) => null; + + /// + /// + /// + /// + /// + public virtual float GetFloat(int i) => 0f; + + /// + /// + /// + /// + /// + public virtual Guid GetGuid(int i) => Guid.Empty; + + /// + /// + /// + /// + /// + public virtual short GetInt16(int i) => 0; + + /// + /// + /// + /// + /// + public virtual int GetInt32(int i) => 0; + + /// + /// + /// + /// + /// + public virtual long GetInt64(int i) => 0; + + /// + /// + /// + /// + /// + public virtual int GetOrdinal(string name) => 0; + + /// + /// + /// + /// + public virtual DataTable GetSchemaTable() => null; + + /// + /// + /// + /// + /// + public virtual string GetString(int i) => string.Empty; + + /// + /// + /// + /// + /// + public virtual int GetValues(object[] values) => 0; + + /// + /// + /// + /// + /// + public virtual bool IsDBNull(int i) => false; + + /// + /// + /// + /// + public virtual bool NextResult() => false; + + /// + /// + /// + /// + /// + public abstract string GetName(int i); + + /// + /// + /// + /// + /// + public abstract object GetValue(int i); + + /// + /// + /// + /// + public abstract bool Read(); + + /// + /// + /// + public virtual void Close() + { + + } + + /// + /// + /// + /// + protected virtual void Dispose(bool disposing) + { + + } + + /// + /// + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + } +} From 59b84e08b9513964d6a9ce7c2d7d9c9ee1720170 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 15 Aug 2024 10:37:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=E5=9F=BA?= =?UTF-8?q?=E7=B1=BB=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniExcel/MiniExcelDataReader.cs | 166 ++++++--------------------- 1 file changed, 37 insertions(+), 129 deletions(-) diff --git a/src/MiniExcel/MiniExcelDataReader.cs b/src/MiniExcel/MiniExcelDataReader.cs index 754ed830..93708977 100644 --- a/src/MiniExcel/MiniExcelDataReader.cs +++ b/src/MiniExcel/MiniExcelDataReader.cs @@ -1,12 +1,11 @@ namespace MiniExcelLibs { - using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; - public class MiniExcelDataReader : IDataReader + public class MiniExcelDataReader : MiniExcelDataReaderBase { private readonly IEnumerator> _source; private readonly int _fieldCount; @@ -26,22 +25,29 @@ internal MiniExcelDataReader(Stream stream, bool useHeaderRow = false, string sh } } - public void Dispose() - { - _stream.Dispose(); - } - - public object GetValue(int i) + /// + /// + /// + /// + /// + public override object GetValue(int i) { return _source.Current[_keys[i]]; } - public int FieldCount + /// + /// + /// + public override int FieldCount { get { return _fieldCount; } } - public bool Read() + /// + /// + /// + /// + public override bool Read() { if (_isFirst) { @@ -51,135 +57,37 @@ public bool Read() return _source.MoveNext(); } - public string GetName(int i) + /// + /// + /// + /// + /// + public override string GetName(int i) { return _keys[i]; } - public int GetOrdinal(string name) + /// + /// + /// + /// + /// + public override int GetOrdinal(string name) { var i = _keys.IndexOf(name); return _keys.IndexOf(name); } - public void Close() + /// + /// + /// + /// + protected override void Dispose(bool disposing) { - return; - } - - public int Depth => throw new NotImplementedException(); - - public bool IsClosed => throw new NotImplementedException(); - - public int RecordsAffected => throw new NotImplementedException(); - - public object this[string name] => throw new NotImplementedException(); - - public object this[int i] => throw new NotImplementedException(); - - public DataTable GetSchemaTable() - { - throw new NotImplementedException(); - } - - public bool NextResult() - { - throw new NotImplementedException(); - } - - public bool GetBoolean(int i) - { - throw new NotImplementedException(); - } - - public byte GetByte(int i) - { - throw new NotImplementedException(); - } - - public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) - { - throw new NotImplementedException(); - } - - public char GetChar(int i) - { - throw new NotImplementedException(); - } - - public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) - { - throw new NotImplementedException(); - } - - public IDataReader GetData(int i) - { - throw new NotImplementedException(); - } - - public string GetDataTypeName(int i) - { - throw new NotImplementedException(); - } - - public DateTime GetDateTime(int i) - { - throw new NotImplementedException(); - } - - public decimal GetDecimal(int i) - { - throw new NotImplementedException(); - } - - public double GetDouble(int i) - { - throw new NotImplementedException(); - } - - public Type GetFieldType(int i) - { - throw new NotImplementedException(); - } - - public float GetFloat(int i) - { - throw new NotImplementedException(); - } - - public Guid GetGuid(int i) - { - throw new NotImplementedException(); - } - - public short GetInt16(int i) - { - throw new NotImplementedException(); - } - - public int GetInt32(int i) - { - throw new NotImplementedException(); - } - - public long GetInt64(int i) - { - throw new NotImplementedException(); - } - - public string GetString(int i) - { - throw new NotImplementedException(); - } - - public int GetValues(object[] values) - { - throw new NotImplementedException(); - } - - public bool IsDBNull(int i) - { - throw new NotImplementedException(); + if (disposing) + { + _stream.Dispose(); + } } } } From 636b3a7988c4813c17a10f419e016d02beb850c6 Mon Sep 17 00:00:00 2001 From: Wei Lin Date: Thu, 15 Aug 2024 19:52:22 +0800 Subject: [PATCH 3/3] Update MiniExcelDataReaderBase.cs Signed-off-by: Wei Lin --- src/MiniExcel/MiniExcelDataReaderBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MiniExcel/MiniExcelDataReaderBase.cs b/src/MiniExcel/MiniExcelDataReaderBase.cs index b8895317..3832bf6d 100644 --- a/src/MiniExcel/MiniExcelDataReaderBase.cs +++ b/src/MiniExcel/MiniExcelDataReaderBase.cs @@ -4,7 +4,7 @@ using System.Data; /// - /// IDataReader 实现类基类 + /// IDataReader Base Class /// public abstract class MiniExcelDataReaderBase : IDataReader {