Click here to Skip to main content
12,242,449 members (56,350 online)
Click here to Skip to main content

Stats

176.3K views
7.6K downloads
338 bookmarked
Posted

Building an embedded database engine in C#

, 10 Jun 2009 CPOL
DbfDotNet is a very fast and compact fully managed standalone database/entity framework, for the .Net Framework.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace DbfDotNet
{
    using DbfDotNet.Core;

    public class SortOrder<TRecord>
        where TRecord : new()
    {
        private List<IndexColumn> mColumns;
        private bool mUnique;
        private static Type mRecordType;

        static SortOrder()
        {
            mRecordType = typeof(TRecord);
        }

        public SortOrder(bool unique)
        {
            mUnique = unique;
            mColumns = new List<IndexColumn>();            
        }

        public void AddField(string columnName)
        {
            AddField(columnName,true);
        }

        public void AddField(string columnName, bool ascending)
        {
            AddField(columnName, ascending, 0);
        }

        public void AddField(string columnName, bool ascending, int width)
        {
            var field = mRecordType.GetField(columnName, 
                BindingFlags.Public 
                | BindingFlags.NonPublic 
                | BindingFlags.IgnoreCase 
                | BindingFlags.Instance);
            if (field == null) throw new InvalidColumnException(columnName, "Unknown sort order column");
            mColumns.Add(new IndexColumn() { ColumnName = columnName, Ascending = ascending, Width = width });
        }

        internal List<IndexColumn> Fields
        {
            get
            {
                return mColumns;
            }
        }

        internal bool IsUnique
        {
            get { return mUnique; }
        }

        internal string ToKeyString()
        {
            var sb = new StringBuilder();
            for (int i = 0; i < mColumns.Count; i++)
            {
                if (i > 0) sb.Append(' ');
                sb.Append(mColumns[i].ColumnName);
            }
            return sb.ToString();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pascal Ganaye
Software Developer (Senior)
France France
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 10 Jun 2009
Article Copyright 2009 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid