Skip to content

Instantly share code, notes, and snippets.

@NickCraver
Created February 8, 2016 23:00
Show Gist options
  • Save NickCraver/92b8822b7f9cdc0be617 to your computer and use it in GitHub Desktop.
Save NickCraver/92b8822b7f9cdc0be617 to your computer and use it in GitHub Desktop.
Quick performance comparison of the DbColumn options performance-wise
void Main()
{
var c = new DbColumn() { ColumnName = "test" };
var sw = Stopwatch.StartNew();
for (var i = 0; i < 10000000; i++)
{
var test = c["ColumnName"];
}
sw.Stop();
sw.ElapsedMilliseconds.Dump();
}
public class DbColumn
{
public virtual bool AllowDBNull { get; set; }
public virtual string BaseCatalogName { get; set; }
public virtual string BaseColumnName { get; set; }
public virtual string BaseSchemaName { get; set; }
public virtual string BaseServerName { get; set; }
public virtual string BaseTableName { get; set; }
public virtual string ColumnName { get; set; }
public virtual int ColumnOrdinal { get; set; }
public virtual int ColumnSize { get; set; }
public virtual bool IsAliased { get; set; }
public virtual bool IsAutoIncrement { get; set; }
public virtual bool IsExpression { get; set; }
public virtual bool IsHidden { get; set; }
public virtual bool IsIdentity { get; set; }
public virtual bool IsKey { get; set; }
public virtual bool IsLong { get; set; }
public virtual bool IsReadOnly { get; set; }
public virtual bool IsUnique { get; set; }
public virtual int NumericPrecision { get; set; }
public virtual int NumericScale { get; set; }
public virtual string UdtAssemblyQualifiedName { get; set; }
public virtual Type DataType { get; set; }
public virtual string DataTypeName { get; set; }
public virtual object this[string property]
{
get
{
switch (property)
{
case "AllowDBNull":
return AllowDBNull;
case "BaseCatalogName":
return BaseCatalogName;
case "BaseColumnName":
return BaseColumnName;
case "BaseSchemaName":
return BaseSchemaName;
case "BaseServerName":
return BaseServerName;
case "BaseTableName":
return BaseTableName;
case "ColumnName":
return ColumnName;
case "ColumnOrdinal":
return ColumnOrdinal;
case "ColumnSize":
return ColumnSize;
case "IsAliased":
return IsAliased;
case "IsAutoIncrement":
return IsAutoIncrement;
case "IsExpression":
return IsExpression;
case "IsHidden":
return IsHidden;
case "IsIdentity":
return IsIdentity;
case "IsKey":
return IsKey;
case "IsLong":
return IsLong;
case "IsReadOnly":
return IsReadOnly;
case "IsUnique":
return IsUnique;
case "NumericPrecision":
return NumericPrecision;
case "NumericScale":
return NumericScale;
case "UdtAssemblyQualifiedName":
return UdtAssemblyQualifiedName;
case "DataType":
return DataType;
case "DataTypeName":
return DataTypeName;
default:
return null;
}
}
}
// public virtual object this[string propertyName]
// {
// get
// {
// var property = this.GetType().GetProperty(propertyName);
// if (property != null)
// return property.GetValue(this);
// else
// return null;
// }
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment