Click here to Skip to main content
12,814,249 members (38,165 online)
Click here to Skip to main content

Stats

198.8K views
8.2K downloads
339 bookmarked
Posted 1 Jun 2009

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...

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