Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C#

Script Engine Implemented by C# and Regular Expression

Rate me:
Please Sign up or sign in to vote.
4.60/5 (4 votes)
21 Nov 2009CPOL2 min read 24.8K   853   24  
Script engine to execute script codes, which is built by C# and regular expression
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Totaldata Web Data Mining(extractweb.com)
China China
Just develop simple softwares. C# is my favorite prgramming languare, though I hope to create a new one...

Comments and Discussions