Click here to Skip to main content
12,620,840 members (32,826 online)
Click here to Skip to main content

Stats

85K views
1.5K downloads
159 bookmarked
Posted

A Flexible Plugin System

, 3 Sep 2008 LGPL3
A generic plugin system used to load and manage plugins
trunk
dlls
xunit.dll
Examples
Plugins
ExampleApplication.Shared
Properties
ExampleApplication
Properties
ExamplePlugin.Shared
Properties
ExamplePlugin
Properties
Fadd.Globalization.Yaml
fadd.snk
Properties
Tests
fadd
Commands
Net
Tests
fadd.snk
Globalization
Tests
Logging
Plugins
Properties
Tests
Validation
using System;
using System.Collections.Specialized;

namespace Fadd.Validation
{
    /// <summary>
    /// Example on how a generated object helper can look like.
    /// todo How do the object get the validator?
    /// </summary>
    internal class ObjectHelper : IObjectHelper<TestObject>
    {
        private readonly Fadd.Validator _validator;
        private readonly Type _type = typeof (TestObject);

        public ObjectHelper(Fadd.Validator validator)
        {
            _validator = validator;
        }

        public NameValueCollection Validate(TestObject theObject)
        {
            _validator.Max("MySize", 20, theObject.MySize, true);
            return _validator.Errors;
        }

        public void SetProperty(TestObject theObject, string propertyName, object value)
        {
            switch (propertyName)
            {
                case "MySize":
                    theObject.MySize = Convert.ToInt32(value);
                    break;
                default:
                    throw new MissingPropertyException(_type.FullName, propertyName);
            }
        }


        public object GetProperty(TestObject theObject, string propertyName, object value)
        {
            switch (propertyName)
            {
                case "MySize":
                    return theObject.MySize;
                default:
                    throw new MissingPropertyException(_type.FullName, propertyName);
            }
        }
    }
}

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 GNU Lesser General Public License (LGPLv3)

Share

About the Author

jgauffin
Founder Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.

blog | twitter

You may also be interested in...

Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid