|
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.
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.