.NET使用FastDBF讀寫DBF

来源:https://www.cnblogs.com/wofeiliangren/archive/2020/01/19/12212460.html
-Advertisement-
Play Games

FastDBF源代碼地址:https://github.com/SocialExplorer/FastDBF 第一步在解決方案中新建一個類庫的項目:取名為SocialExplorer.FastDBF 第二步:引入FASTDBF的源文件 源代碼可以通過github地址下載引入 源文件:DbfColum ...


FastDBF源代碼地址:https://github.com/SocialExplorer/FastDBF

第一步在解決方案中新建一個類庫的項目:取名為SocialExplorer.FastDBF

 

 

 

第二步:引入FASTDBF的源文件  源代碼可以通過github地址下載引入

 

源文件:DbfColumn.cs

///
/// Author: Ahmed Lacevic
/// Date: 12/1/2007
/// 
/// Revision History:
/// -----------------------------------
///   Author:
///   Date:
///   Desc:

using System;
using System.Collections.Generic;
using System.Text;


namespace SocialExplorer.IO.FastDBF
{ 
  
  /// <summary>
  /// This class represents a DBF Column.
  /// </summary>
  /// 
  /// <remarks>
  /// Note that certain properties can not be modified after creation of the object. 
  /// This is because we are locking the header object after creation of a data row,
  /// and columns are part of the header so either we have to have a lock field for each column,
  /// or make it so that certain properties such as length can only be set during creation of a column.
  /// Otherwise a user of this object could modify a column that belongs to a locked header and thus corrupt the DBF file.
  /// </remarks>
  public class DbfColumn : ICloneable
  { 
    
    /*
     (FoxPro/FoxBase) Double integer *NOT* a memo field
     G     General     (dBASE V: like Memo) OLE Objects in MS Windows versions 
     P     Picture     (FoxPro) Like Memo fields, but not for text processing. 
     Y     Currency     (FoxPro)
     T     DateTime     (FoxPro)
     I     Integer     Length: 4 byte little endian integer     (FoxPro)
    */
    
    /// <summary>
    ///  Great information on DBF located here: 
    ///  http://www.clicketyclick.dk/databases/xbase/format/data_types.html
    ///  http://www.clicketyclick.dk/databases/xbase/format/dbf.html
    /// </summary>
    public enum DbfColumnType
    { 
      
      /// <summary>
      /// Character  less than 254 length
      /// ASCII text less than 254 characters long in dBASE. 
      /// 
      /// Character fields can be up to 32 KB long (in Clipper and FoxPro) using decimal 
      /// count as high byte in field length. It's possible to use up to 64KB long fields 
      /// by reading length as unsigned.
      /// 
      /// </summary>
      Character = 0,
      
      /// <summary>
      /// Number     Length: less than 18 
      ///   ASCII text up till 18 characters long (include sign and decimal point). 
      /// 
      /// Valid characters: 
      ///    "0" - "9" and "-". Number fields can be up to 20 characters long in FoxPro and Clipper. 
      /// </summary>
      /// <remarks>
      /// We are not enforcing this 18 char limit.
      /// </remarks>
      Number = 1,
      
      /// <summary>
      ///  L  Logical  Length: 1    Boolean/byte (8 bit) 
      ///  
      ///  Legal values: 
      ///   ?     Not initialised (default)
      ///   Y,y     Yes
      ///   N,n     No
      ///   F,f     False
      ///   T,t     True
      ///   Logical fields are always displayed using T/F/?. Some sources claims 
      ///   that space (ASCII 20h) is valid for not initialised. Space may occur, but is not defined.      
      /// </summary>
      Boolean = 2,
      
      /// <summary>
      /// D     Date     Length: 8  Date in format YYYYMMDD. A date like 0000-00- 00 is *NOT* valid. 
      /// </summary>
      Date = 3,
      
      /// <summary>
      /// M     Memo     Length: 10     Pointer to ASCII text field in memo file 10 digits representing a pointer to a DBT block (default is blanks). 
      /// </summary>
      Memo = 4,
      
      /// <summary>
      /// B     Binary          (dBASE V) Like Memo fields, but not for text processing.
      /// </summary>
      Binary = 5,
      
      /// <summary>
      /// I     Integer     Length: 4 byte little endian integer     (FoxPro)
      /// </summary>
      Integer = 6, 
      
    }
    
    
    /// <summary>
    /// Column (field) name
    /// </summary>
    private string mName;
    
    
    /// <summary>
    /// Field Type (Char, number, boolean, date, memo, binary)
    /// </summary>
    private DbfColumnType mType;
    
    
    /// <summary>
    /// Offset from the start of the record
    /// </summary>
    internal int mDataAddress;
    
    
    /// <summary>
    /// Length of the data in bytes; some rules apply which are in the spec (read more above).
    /// </summary>
    private int mLength;
    
    
    /// <summary>
    /// Decimal precision count, or number of digits afer decimal point. This applies to Number types only.
    /// </summary>
    private int mDecimalCount;
    
    
    
    /// <summary>
    /// Full spec constructor sets all relevant fields.
    /// </summary>
    /// <param name="sName"></param>
    /// <param name="type"></param>
    /// <param name="nLength"></param>
    /// <param name="nDecimals"></param>
    public DbfColumn(string sName, DbfColumnType type, int nLength, int nDecimals)
    { 
      
      Name = sName;
      mType = type;
      mLength = nLength;
      
      if(type == DbfColumnType.Number)
        mDecimalCount = nDecimals;
      else
        mDecimalCount = 0;
      
      
      
      //perform some simple integrity checks...
      //-------------------------------------------
      
      //decimal precision:
      //we could also fix the length property with a statement like this: mLength = mDecimalCount + 2;
      //lyq修改源碼取消判斷
      //if (mDecimalCount > 0 && mLength - mDecimalCount <= 1)
      //  throw new Exception("Decimal precision can not be larger than the length of the field.");
      
      if(mType == DbfColumnType.Integer)
        mLength = 4;
      
      if(mType == DbfColumnType.Binary)
        mLength = 1;
      
      if(mType == DbfColumnType.Date)
        mLength = 8;  //Dates are exactly yyyyMMdd
      
      if(mType == DbfColumnType.Memo)
        mLength = 10;  //Length: 10 Pointer to ASCII text field in memo file. pointer to a DBT block.
      
      if(mType == DbfColumnType.Boolean)
        mLength = 1;
      
      //field length:
      if (mLength <= 0)
        throw new Exception("Invalid field length specified. Field length can not be zero or less than zero.");
      else if (type != DbfColumnType.Character && type != DbfColumnType.Binary && mLength > 255)
        throw new Exception("Invalid field length specified. For numbers it should be within 20 digits, but we allow up to 255. For Char and binary types, length up to 65,535 is allowed. For maximum compatibility use up to 255.");
      else if((type == DbfColumnType.Character || type == DbfColumnType.Binary) && mLength > 65535)
        throw new Exception("Invalid field length specified. For Char and binary types, length up to 65535 is supported. For maximum compatibility use up to 255.");
      
      
    }
    
    
    /// <summary>
    /// Create a new column fully specifying all properties.
    /// </summary>
    /// <param name="sName">column name</param>
    /// <param name="type">type of field</param>
    /// <param name="nLength">field length including decimal places and decimal point if any</param>
    /// <param name="nDecimals">decimal places</param>
    /// <param name="nDataAddress">offset from start of record</param>
    internal DbfColumn(string sName, DbfColumnType type, int nLength, int nDecimals, int nDataAddress): this(sName, type, nLength, nDecimals)
    { 
      
      mDataAddress = nDataAddress;
      
    }
    
    
    public DbfColumn(string sName, DbfColumnType type): this(sName, type, 0, 0)
    { 
      if(type == DbfColumnType.Number || type == DbfColumnType.Character )
        throw new Exception("For number and character field types you must specify Length and Decimal Precision.");
      
    }
    
    
    /// <summary>
    /// Field Name.
    /// </summary>
    public string Name
    { 
      get
      { 
        return mName;
      }
      
      set
      { 
        //name:
        if (string.IsNullOrEmpty(value))
          throw new Exception("Field names must be at least one char long and can not be null.");
        
        if (value.Length > 11)
          throw new Exception("Field names can not be longer than 11 chars.");
        
        mName = value;
        
      }
      
    }
    
    
    /// <summary>
    /// Field Type (C N L D or M).
    /// </summary>
    public DbfColumnType ColumnType
    { 
      get
      { 
        return mType;
      }
    }
    
    
    /// <summary>
    /// Returns column type as a char, (as written in the DBF column header)
    /// N=number, C=char, B=binary, L=boolean, D=date, I=integer, M=memo
    /// </summary>
    public char ColumnTypeChar
    { 
      get
      { 
        switch(mType)
        {
          case DbfColumnType.Number:
            return 'N';
          
          case DbfColumnType.Character:
            return 'C';
          
          case DbfColumnType.Binary:
            return 'B';
            
          case DbfColumnType.Boolean:
            return 'L';
          
          case DbfColumnType.Date:
            return 'D';
          
          case DbfColumnType.Integer:
            return 'I';

          case DbfColumnType.Memo:
            return 'M';
          
        }
        
        throw new Exception("Unrecognized field type!");
        
      }
    }
    
    
    /// <summary>
    /// Field Data Address offset from the start of the record.
    /// </summary>
    public int DataAddress
    { 
      get
      { 
        return mDataAddress;
      }
    }

    /// <summary>
    /// Length of the data in bytes.
    /// </summary>
    public int Length
    { 
      get
      { 
        return mLength;
      }
    }

    /// <summary>
    /// Field decimal count in Binary, indicating where the decimal is.
    /// </summary>
    public int DecimalCount
    { 
      get
      { 
        return mDecimalCount;
      }
      
    }
    
    
    
    
    
    /// <summary>
    /// Returns corresponding dbf field type given a .net Type.
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static DbfColumnType GetDbaseType(Type type)
    { 
      
      if (type == typeof(string))
        return DbfColumnType.Character;
      else if (type == typeof(double) || type == typeof(float))
        return DbfColumnType.Number;
      else if (type == typeof(bool))
        return DbfColumnType.Boolean;
      else if (type == typeof(DateTime))
        return DbfColumnType.Date;
      
      throw new NotSupportedException(String.Format("{0} does not have a corresponding dbase type.", type.Name));
      
    }
    
    public static DbfColumnType GetDbaseType(char c)
    { 
      switch(c.ToString().ToUpper())
      { 
        case "C": return DbfColumnType.Character;
        case "N": return DbfColumnType.Number;
        case "B": return DbfColumnType.Binary;
        case "L": return DbfColumnType.Boolean;
        case "D": return DbfColumnType.Date;
        case "I": return DbfColumnType.Integer;
        case "M": return DbfColumnType.Memo;
      }
      
      throw new NotSupportedException(String.Format("{0} does not have a corresponding dbase type.", c));
      
    }
    
    /// <summary>
    /// Returns shp file Shape Field.
    /// </summary>
    /// <returns></returns>
    public static DbfColumn ShapeField()
    { 
      return new DbfColumn("Geometry", DbfColumnType.Binary);
      
    }
    
    
    /// <summary>
    /// Returns Shp file ID field.
    /// </summary>
    /// <returns></returns>
    public static DbfColumn IdField()
    { 
      return new DbfColumn("Row", DbfColumnType.Integer);
      
    }



    public object Clone()
    {
        return this.MemberwiseClone();
    }
  }
}
View Code

源文件:DbfDataTruncateException.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;


namespace SocialExplorer.IO.FastDBF
{ 
  
  public class DbfDataTruncateException: Exception
  { 
    
    public DbfDataTruncateException(string smessage): base(smessage)
    { 
    }

    public DbfDataTruncateException(string smessage, Exception innerException)
      : base(smessage, innerException)
    { 
    }

    public DbfDataTruncateException(SerializationInfo info, StreamingContext context)
      : base(info, context)
    {
    }
    
  }
}
View Code

源文件:DbfFile.cs

///
/// Author: Ahmed Lacevic
/// Date: 12/1/2007
/// Desc: This class represents a DBF file. You can create, open, update and save DBF files using this class and supporting classes.
/// Also, this class supports reading/writing from/to an internet forward only type of stream!
/// 
/// Revision History:
/// -----------------------------------
///   Author:
///   Date:
///   Desc:


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace SocialExplorer.IO.FastDBF
{

    /// <summary>
    /// This class represents a DBF file. You can create new, open, update and save DBF files using this class and supporting classes.
    /// Also, this class supports reading/writing from/to an internet forward only type of stream!
    /// </summary>
    /// <remarks>
    /// TODO: add end of file byte '0x1A' !!!
    /// We don't relly on that byte at all, and everything works with or without that byte, but it should be there by spec.
    /// </remarks>
    public class DbfFile
    {

        /// <summary>
        /// Helps read/write dbf file header information.
        /// </summary>
        protected DbfHeader mHeader;


        /// <summary>
        /// flag that indicates whether the header was written or not...
        /// </summary>
        protected bool mHeaderWritten = false;


        /// <summary>
        /// Streams to read and write to the DBF file.
        /// </summary>
        protected Stream mDbfFile = null;
        protected BinaryReader mDbfFileReader = null;
        protected BinaryWriter mDbfFileWriter = null;

        private Encoding encoding = Encoding.ASCII;

        /// <summary>
        /// File that was opened, if one was opened at all.
        /// </summary>
        protected string mFileName = "";


        /// <summary>
        /// Number of records read using ReadNext() methods only. This applies only when we are using a forward-only stream.
        /// mRecordsReadCount is used to keep track of record index. With a seek enabled stream, 
        /// we can always calculate index using stream position.
        /// </summary>
        protected int mRecordsReadCount = 0;


        /// <summary>
        /// keep these values handy so we don't call functions on every read.
        /// </summary>
        protected bool mIsForwardOnly = false;
        protected bool mIsReadOnly = false;

        [Obsolete]
        public DbfFile()
            : this(Encoding.ASCII)
        {
        }

        public DbfFile(Encoding encoding)
        {
            this.encoding = encoding;
            mHeader = new DbfHeader(encoding);
        }

        /// <summary>
        /// Open a DBF from a FileStream. This can be a file or an internet connection stream. Make sure that it is positioned at start of DBF file.
        /// Reading a DBF over the internet we can not determine size of the file, so we support HasMore(), ReadNext() interface. 
        /// RecordCount information in header can not be trusted always, since some packages store 0 there.
        /// </summary>
        /// <param name="ofs"></param>
        public void Open(Stream ofs)
        {
            if (mDbfFile != null)
                Close();

            mDbfFile = ofs;
            mDbfFileReader = null;
            mDbfFileWriter = null;

            if (mDbfFile.CanRead)
                mDbfFileReader = new BinaryReader(mDbfFile, encoding);

            if (mDbfFile.CanWrite)
                mDbfFileWriter = new BinaryWriter(mDbfFile, encoding);

            //reset position
            mRecordsReadCount = 0;

            //assume header is not written
            mHeaderWritten = false;

            //read the header
            if (ofs.CanRead)
            {
                //try to read the header...
                try
                {
                    mHeader.Read(mDbfFileReader);
                    mHeaderWritten = true;

                }
                catch (EndOfStreamException)
                {
                    //could not read header, file is empty
                    mHeader = new DbfHeader(encoding);
                    mHeaderWritten = false;
                }


            }

            if (mDbfFile != null)
            {
                mIsReadOnly = !mDbfFile.CanWrite;
                mIsForwardOnly = !mDbfFile.CanSeek;
            }


        }



        /// <summary>
        /// Open a DBF file or create a new one.
        /// </summary>
        /// <param name="sPath">Full path to the file.</param>
        /// <param name="mode"></param>
        public void Open(string sPath, FileMode mode, FileAccess access, FileShare share)
        {
            mFileName = sPath;
            Open(File.Open(sPath, mode, access, share));
        }

        /// <summary>
        /// Open a DBF file or create a new one.
        /// </summary>
        /// <param name="sPath">Full path to the file.</param>
        /// <param name="mode"></param>
        public void Open(string sPath, FileMode mode, FileAccess access)
        {
            mFileName = sPath;
            Open(File.Open(sPath, mode, access));
        }

        /// <summary>
        /// Open a DBF file or create a new one.
        /// </summary>
        /// <param name="sPath">Full path to the file.</param>
        /// <param name="mode"></param>
        public void Open(string sPath, FileMode mode)
        {
            mFileName = sPath;
            Open(File.Open(sPath, mode));
        }


        /// <summary>
        /// Creates a new DBF 4 file. Overwrites if file exists! Use Open() function for more options.
        /// </summary>
        /// <param name="sPath"></param>
        public void Create(string sPath)
        {
            Open(sPath, FileMode.Create, FileAccess.ReadWrite);
            mHeaderWritten = false;

        }



        /// <summary>
        /// Update header info, flush buffers and close streams. You should always call this method when you are done with a DBF file.
        /// </summary>
        public void Close()
        {

            //try to update the header if it has changed
            //------------------------------------------
            if (mHeader.IsDirty)
                WriteHeader();



            //Empty header...
            //--------------------------------
            mHeader = new DbfHeader(encoding);
            mHeaderWritten = false;


            //reset current record index
            //--------------------------------
            mRecordsReadCount = 0;


            //Close streams...
            //--------------------------------
            if (mDbfFileWriter != null)
            {
                mDbfFileWriter.Flush();
                mDbfFileWriter.Close();
            }

            if (mDbfFileReader != null)
                mDbfFileReader.Close();

            if (mDbfFile != null)
                mDbfFile.Close();


            //set streams to null
            //--------------------------------
            mDbfFileReader = null;
            mDbfFileWriter = null;
            mDbfFile = null;

            mFileName = "";

        }



        /// <summary>
        /// Returns true if we can not write to the DBF file stream.
        /// </summary>
        public bool IsReadOnly
        {
            get
            {
                return mIsReadOnly;
                /*
                if (mDbfFile != null)
                  return !mDbfFile.CanWrite; 
                return true;
                */

            }

        }


        /// <summary>
        /// Returns true if we can not seek to different locations within the file, such as internet connections.
        /// </summary>
        public bool IsForwardOnly
        {
            get
            {
                return mIsForwardOnly;
                /*
                if(mDbfFile!=null)
                  return !mDbfFile.CanSeek;
        
                return false;
                */
            }
        }


        /// <summary>
        /// Returns the name of the filestream.
        /// </summary>
        public string FileName
        {
            get
            {
                return mFileName;
            }
        }



        /// <summary>
        /// Read next record and fill data into parameter oFillRecord. Returns true if a record was read, otherwise false.
        /// </summary>
        /// <param name="oFillRecord"></param>
        /// <returns></returns>
        public bool ReadNext(DbfRecord oFillRecord)
        {

            //check if we can fill this record with data. it must match record size specified by header and number of columns.
            //we are not checking whether it comes from another DBF file or not, we just need the same structure. Allow flexibility but be safe.
            if (oFillRecord.Header != mHeader && (oFillRecord.Header.ColumnCount != mHeader.ColumnCount || oFillRecord.Header.RecordLength != mHeader.RecordLength))
                throw new Exception("Record parameter does not have the same size and number of columns as the " +
                                    "header specifies, so we are unable to read a record into oFillRecord. " +
                                    "This is a programming error, have you mixed up DBF file objects?");

            //DBF file reader can be null if stream is not readable...
            if (mDbfFileReader == null)
                throw new Exception("Read stream is null, either you have opened a stream that can not be " +
                                    "read from (a write-only stream) or you have not opened a stream at all.");

            //read next record...
            bool bRead = oFillRecord.Read(mDbfFile);

            if (bRead)
            {
      

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 解構賦值 數組解構 上面的寫法等價於: 利用解構賦值交換變數: 函數參數解構: 解構剩餘參數: 也可以忽略其它參數: 或者跳過解構: 對象解構 示例一: 就像數組解構,你可以用沒有聲明的賦值: 你可以在對象里使用 語法創建剩餘變數: 屬性解構重命名 你也可以給屬性以不同的名字: 註意,這裡的冒號 不 ...
  • Hello World 新建 並寫入以下內容: 安裝編譯器: 編譯: 修改 文件中的代碼,為 greeter 函數的參數 person 加上類型聲明 : 重新編譯執行。 讓我們繼續修改: 重新編譯,你將看到如下錯誤: 介面(Interface) 類(Class) 變數聲明 作用域 重覆聲明 塊級作用 ...
  • TypeScript 介紹 TypeScript 是什麼 TypeScript 是 JavaScript 的強類型版本。然後在編譯期去掉類型和特有語法,生成純粹的 JavaScript 代碼。由於最終在瀏覽器中運行的仍然是 JavaScript,所以 TypeScript 並不依賴於瀏覽器的支持,也 ...
  • 隨著你的 Python 項目越來越多,你會發現不同的項目會需要 不同的版本的 Python 庫。同一個 Python 庫的不同版本可能不相容。虛擬環境可以為每一個項目安裝獨立的 Python 庫,這樣就可以隔離不同項目之間的 Python 庫,也可以隔離項目與操作系統之間的 Python 庫。 1. ...
  • http請求在我們實際工作中天天見,為了不重覆造輪子,現在分享一下最近的一次封裝整理,供大家參考,交流,學習! ...
  • static void AggregateExceptionsDemo() { var task1 = Task.Factory.StartNew(() => { var child1 = Task.Factory.StartNew(() => { throw new CustomException ...
  • 本筆記摘抄自:https://www.cnblogs.com/PatrickLiu/p/7699301.html,記錄一下學習過程以備後續查用。 一、引言 今天我們要講結構型設計模式的第二個模式--橋接模式,也有叫橋模式的。橋在我們現實生活中經常是連接著A地和B地,再往後來發展,橋引申為一種紐 帶, ...
  • 目 錄 1. 概述... 2 2. 演示信息... 2 3. 安裝Docker容器... 2 4. 安裝dotnet鏡像... 3 5. 複製iNeuKernel到容器中... 4 6. 進入指定容器... 4 7. 安裝dotnet框架... 4 8. 在Docker容器中運行iNeuKernel ...
一周排行
    -Advertisement-
    Play Games
  • 概述:在C#中,++i和i++都是自增運算符,其中++i先增加值再返回,而i++先返回值再增加。應用場景根據需求選擇,首碼適合先增後用,尾碼適合先用後增。詳細示例提供清晰的代碼演示這兩者的操作時機和實際應用。 在C#中,++i 和 i++ 都是自增運算符,但它們在操作上有細微的差異,主要體現在操作的 ...
  • 上次發佈了:Taurus.MVC 性能壓力測試(ap 壓測 和 linux 下wrk 壓測):.NET Core 版本,今天計劃準備壓測一下 .NET 版本,來測試並記錄一下 Taurus.MVC 框架在 .NET 版本的性能,以便後續持續優化改進。 為了方便對比,本文章的電腦環境和測試思路,儘量和... ...
  • .NET WebAPI作為一種構建RESTful服務的強大工具,為開發者提供了便捷的方式來定義、處理HTTP請求並返迴響應。在設計API介面時,正確地接收和解析客戶端發送的數據至關重要。.NET WebAPI提供了一系列特性,如[FromRoute]、[FromQuery]和[FromBody],用 ...
  • 原因:我之所以想做這個項目,是因為在之前查找關於C#/WPF相關資料時,我發現講解圖像濾鏡的資源非常稀缺。此外,我註意到許多現有的開源庫主要基於CPU進行圖像渲染。這種方式在處理大量圖像時,會導致CPU的渲染負擔過重。因此,我將在下文中介紹如何通過GPU渲染來有效實現圖像的各種濾鏡效果。 生成的效果 ...
  • 引言 上一章我們介紹了在xUnit單元測試中用xUnit.DependencyInject來使用依賴註入,上一章我們的Sample.Repository倉儲層有一個批量註入的介面沒有做單元測試,今天用這個示例來演示一下如何用Bogus創建模擬數據 ,和 EFCore 的種子數據生成 Bogus 的優 ...
  • 一、前言 在自己的項目中,涉及到實時心率曲線的繪製,項目上的曲線繪製,一般很難找到能直接用的第三方庫,而且有些還是定製化的功能,所以還是自己繪製比較方便。很多人一聽到自己畫就害怕,感覺很難,今天就分享一個完整的實時心率數據繪製心率曲線圖的例子;之前的博客也分享給DrawingVisual繪製曲線的方 ...
  • 如果你在自定義的 Main 方法中直接使用 App 類並啟動應用程式,但發現 App.xaml 中定義的資源沒有被正確載入,那麼問題可能在於如何正確配置 App.xaml 與你的 App 類的交互。 確保 App.xaml 文件中的 x:Class 屬性正確指向你的 App 類。這樣,當你創建 Ap ...
  • 一:背景 1. 講故事 上個月有個朋友在微信上找到我,說他們的軟體在客戶那邊隔幾天就要崩潰一次,一直都沒有找到原因,讓我幫忙看下怎麼回事,確實工控類的軟體環境複雜難搞,朋友手上有一個崩潰的dump,剛好丟給我來分析一下。 二:WinDbg分析 1. 程式為什麼會崩潰 windbg 有一個厲害之處在於 ...
  • 前言 .NET生態中有許多依賴註入容器。在大多數情況下,微軟提供的內置容器在易用性和性能方面都非常優秀。外加ASP.NET Core預設使用內置容器,使用很方便。 但是筆者在使用中一直有一個頭疼的問題:服務工廠無法提供請求的服務類型相關的信息。這在一般情況下並沒有影響,但是內置容器支持註冊開放泛型服 ...
  • 一、前言 在項目開發過程中,DataGrid是經常使用到的一個數據展示控制項,而通常表格的最後一列是作為操作列存在,比如會有編輯、刪除等功能按鈕。但WPF的原始DataGrid中,預設只支持固定左側列,這跟大家習慣性操作列放最後不符,今天就來介紹一種簡單的方式實現固定右側列。(這裡的實現方式參考的大佬 ...