Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » ADO.NET » Downloads
 
Add your own
alternative version

Light ORM Library for .NET

, 8 Oct 2010
This article is about the Light Object-Relational Mapping library.
using System;
using System.Data;
using System.Reflection;

namespace Light.Model
{
	/// <summary>
	/// Represents a column based on a field.
	/// </summary>
	internal class FieldColumn : AbstractColumn
	{
		private FieldInfo field;
		
		/// <summary>
		/// Creates a new field column.
		/// </summary>
		/// <param name="field">underlying class field</param>
		/// <param name="name">column name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="primaryKey">whether this column is a primary key column</param>
		/// <param name="autoIncr">whether this column is an auto-incremented column</param>
		internal FieldColumn(FieldInfo field, string name, DbType dbtype,
		                     bool primaryKey, bool autoIncr)
			: this(field, name, dbtype, 0, primaryKey, autoIncr)
		{
		}
		
		/// <summary>
		/// Creates a new field column.
		/// </summary>
		/// <param name="field">underlying class field</param>
		/// <param name="name">column name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">size of the database data type</param>
		/// <param name="primaryKey">whether this column is a primary key column</param>
		/// <param name="autoIncr">whether this column is an auto-incremented column</param>
		internal FieldColumn(FieldInfo field, string name, DbType dbtype,
		                     int size, bool primaryKey, bool autoIncr)
			: this(field, name, dbtype, size, 0, 0, primaryKey, autoIncr)
		{
		}
		
		/// <summary>
		/// Creates a new field column.
		/// </summary>
		/// <param name="field">underlying class field</param>
		/// <param name="name">column name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">size of the database data type</param>
		/// <param name="precision">precision of the database data type</param>
		/// <param name="scale">scale of the database data type</param>
		/// <param name="primaryKey">whether this column is a primary key column</param>
		/// <param name="autoIncr">whether this column is an auto-incremented column</param>
		internal FieldColumn(FieldInfo field, string name, DbType dbtype, int size,
		                     byte precision, byte scale, bool primaryKey, bool autoIncr)
			: base(name, dbtype, size, precision, scale, primaryKey, autoIncr)
		{
			this.field = field;
		}
		
		/// <summary>
		/// True if this column can be written to. That is,
		/// whether calling the Write method can actually
		/// attempt to write a value into a target object.
		/// </summary>
		public override bool Writeable
		{
			get { return true; }
		}
		
		/// <summary>
		/// True if this column can be read from. That is,
		/// whether calling the Read method will return a valid value.
		/// </summary>
		public override bool Readable
		{
			get { return true; }
		}
		
		/// <summary>
		/// Attempts to write a given value info a given target object.
		/// </summary>
		/// <param name="target">target object</param>
		/// <param name="value">value to write</param>
		public override void Write(object target, object value)
		{
			field.SetValue(target, value);
		}
		
		/// <summary>
		/// Attempts to read a value from a given source object.
		/// </summary>
		/// <param name="source">source object</param>
		/// <returns>value of this column from the source object</returns>
		public override object Read(object source)
		{
			return field.GetValue(source);
		}
	}
}

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

Sergey Busel
Software Developer (Senior)
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 8 Oct 2010
Article Copyright 2007 by Sergey Busel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid