Click here to Skip to main content
15,879,184 members
Articles / Web Development / ASP.NET

PLINQO - Supercharge LINQ to SQL

Rate me:
Please Sign up or sign in to vote.
3.79/5 (6 votes)
17 Aug 2007CPOL6 min read 51.6K   143   17  
PLINQO is a collection of CodeSmith templates that are meant to replace and extend the LINQ to SQL designers.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace CodeSmith.Data.Rules
{
    public abstract class PropertyRuleBase : IRule
    {
        protected PropertyRuleBase(string property)
        {
            TargetProperty = property;
        }

        protected PropertyRuleBase(string property, string message)
        {
            TargetProperty = property;
            ErrorMessage = message;
        }

        public string TargetProperty { get; protected set; }
        public string ErrorMessage { get; protected set; }

        protected PropertyInfo GetPropertyInfo(object target)
        {
            return target.GetType().GetProperty(TargetProperty);
        }

        protected object GetPropertyValue(object target)
        {
            PropertyInfo propertyInfo = GetPropertyInfo(target);
            if (propertyInfo == null) 
                return null;

            return propertyInfo.GetValue(target, null);
        }

        protected T GetPropertyValue<T>(object target)
        {
            object value = GetPropertyValue(target);
            return (value == null) ? default(T) : (T)value;
        }

        public abstract void Run(RuleContext context);
    }
}

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)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions