Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4572018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:35:11+00:00 2026-05-21T19:35:11+00:00

public interface IRule { bool Check(string input); } I have an interface that defines

  • 0
public interface IRule
{
    bool Check(string input);
}

I have an interface that defines a rule. A rule is just a generic business rule or constraint that a user can create. So I have two sample rules:

public class ContainsRule : IRule
{
    public string MustContain { get; set; }

    public bool Check(string input)
    {
        return input.Contains(this.MustContain);
    }
}

public class LengthRule : IRule
{
    public int MaxLength { get; set; }

    public bool Check(string input)
    {
        return input.Length <= this.MaxLength;
    }
}

Rules may have more than one property that can be set, but in this example, each of these rules only have one property.

A user can create their own set of rules that should be saved. For example, a user have these three rules:

IRule[] rules = new IRule[]
{
    new ContainsRule { MustContain = "foo" },
    new ContainsRule { MustContain = "bar" },
    new LengthRule { MaxLength = 5}
};

I need to persist this information to a database or some data store for each user. Since each user can have their own set of rules, I’m not sure what the database tables should look like.

User  |  ClassName               |  Parameters
-----------------------------------------------
1     |  Namespace.ContainsRule  |  MustContain:foo
1     |  Namespace.ContainsRule  |  MustContain:bar
1     |  Namespace.LengthRule    |  MaxLength:5

My initial guess would be to create a table that looks something like the above, where parameters should a string. This means I would need to parse out the information and use reflection or something to set the properties. I would need to use the activator to create the class using the ClassName column. Another suggestion was instead of creating a delimited string for all the properties, there would be another table. Each of the properties would be its own row that has a foreign key relationship back to a row in the table above.

However, both examples don’t seem to be the best way of saving these rules. Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:35:12+00:00Added an answer on May 21, 2026 at 7:35 pm

    Why not use XML serialisation. The database table would contain the User # and the XML serialisation of the indvidual rule.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule
I have an interface @PersistenceCapable public interface MyInterface { public abstract String getName(); public
I have a marker interface defined as public interface IExtender<T> { } I have
Consider the following interface in Java: public interface I { public final String KEY
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
Let's say we have public interface ITimestampProvider { DateTime GetTimestamp(); } and a class
I have the concept of a Rule that I want to be able to
I'm programmatically registering a group of services that all implement the same interface, IRule.
Example, I have the following interface and classes: public interface IRole { DateTime Since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.