|
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Zadesoft.Library.Script.ExternalValueProviders
{
public class DataRowExternalValueProvider
: IExternalValueProvider
{
private DataRow _row = null;
public DataRowExternalValueProvider()
{
}
public DataRowExternalValueProvider(DataRow row)
{
ResetDataRow(row);
}
public void ResetDataRow(DataRow row)
{
if (row == null)
{
throw new ArgumentNullException("source data row is null");
}
if (row.Table == null)
{
throw new ArgumentException("source data row has got no table");
}
_row = row;
}
#region IAvailableValueProvider Members
public string Name
{
get { return "DataRow"; }
}
public bool Contains(string name)
{
if (_row == null)
{
return false;
}
lock (_row)
{
return _row.Table.Columns.Contains(name);
}
}
public object GetAvailable(string name)
{
if (_row == null || string.IsNullOrEmpty(name))
{
throw new ArgumentException("available name is invalid");
}
lock (_row)
{
if (!_row.Table.Columns.Contains(name))
{
throw new AvailableNotFoundInProviderException(this, name);
}
return _row[name];
}
}
public void SetAvailable(string name, object value)
{
if (_row == null || string.IsNullOrEmpty(name))
{
throw new ArgumentException("available name is invalid");
}
lock (_row)
{
if (!_row.Table.Columns.Contains(name))
{
throw new AvailableNotFoundInProviderException(this, name);
}
_row[name] = value;
}
}
#endregion
}
}
|
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.
Just develop simple softwares. C# is my favorite prgramming languare, though I hope to create a new one...