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

  • SEARCH
  • Home
  • 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 6650099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:51:10+00:00 2026-05-26T00:51:10+00:00

I made a system that creates a simple string with Function/Response format, example: Check(‘Value’):ShowImage(@)|Check(‘Value’):OtherFunction(@)….and

  • 0

I made a system that creates a simple string with Function/Response format, example:

Check('Value'):ShowImage(@)|Check('Value'):OtherFunction(@)....and so on

Where Check is the name of a function, Value is the parameter, ShowImage is the name of a Response function, @ is the entry paremeter (result of the previous function). The pipe splits another Function/Response pair that fires if the first Check('Value') function once “checked” were not satisfied (say, if the parameter was not accomplished the Check condition the function is invalid and hence the Response part in the first Function/Response pair is not executed, so system keep trying Functions awaiting to find the one that executes the right Response).

The way the application should work is to evaluate each rule (similar to a JavaScript eval function) and take appropriate action based on function results.

At first glance, it looks complicated, because first of all I need to cast the string to the right real C# function that will actually process the condition. Therefore, depending on the function result, decide where to point to execute my Response function.

Furthermore: This is just the kind example, because there are functions as * that represent something like: “any condition is true” what in almost all cases this function is the last in the chain (the default function).

That’s my problem, I can’t realize what is the easiest way to cope with this problem.
Maybe a chain of delegates? Lambdas? Anonymous stored into a structure…

Could you give me your measure/advise? Where to start?

  • 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-26T00:51:11+00:00Added an answer on May 26, 2026 at 12:51 am

    Depending on the level of extensibility you want to have, I would say the most extensible way would be to use reflection to get method references, after you have parsed the input string.

    You can start by splitting your problem into smaller subproblems.

    Let’s say you are aiming for something like this:

    static void Main(string[] args)
    {
        string rules = 
            "Check(Morning):Say(Good morning)|" +
            "Check(Afternoon):Say(Good afternoon)|" +
            "Check(Evening):Say(Good night)";
    
        // next, you need some **object instances** which will 
        // provide a context for your "test" and "action" methods.
        // you don't want to use static methods if you
        // went through the pain of defining such an architecture!
    
        // let's say that a "Tester" object has a "Check" method,
        // and an "Executor" object has a "Say" method:
    
        var tester = new Tester("Afternoon");
        var executor = new Executor();
    
        // since I suck at regular expressions,
        // I am using plain string methods to split
        // the expression into tokens. You might want
        // to add some validation
    
        foreach (var rule in rules.Split('|'))
        {
            var result = Parse(rule, tester, executor);
            if (result.TestPassed)
            {
                result.Execute();
                break;
            }
        }
    }
    

    A “result” as it’s used above would then have an interface like this:

    public interface IResult
    {
        // returns true if a test is fulfilled
        bool TestPassed { get; }
    
        // executes the related action
        void Execute();
    }
    

    And, if you want to delegate actual actions to some unknown methods, a reasonable way to implement it would be something like this:

    public class Result : IResult
    {
        #region IResult Members
    
        private readonly Func<bool> _testMethod;
        public bool TestPassed
        {
            get { return _testMethod(); }
        }
    
        private readonly Action _actionMethod;
        public void Execute()
        {
            _actionMethod();
        }
    
        #endregion
    
        public Result(Func<bool> testMethod, Action actionMethod)
        {
            _testMethod = testMethod;
            _actionMethod = actionMethod;
        }
    }
    

    What’s left is to use some reflection to get the actual methods out of your strings:

    private static IResult Parse(string rule, object tester, object executor)
    {
        // split into test/action
        var tokens = rule.Split(':');
    
        // extract the method/parameter part for each expression
        var test = GetMethodAndParams(tokens[0]);
        var action = GetMethodAndParams(tokens[1]);
    
        // use reflection to find actual methods
        var testMethod = tester.GetType().GetMethod(test.Method);
        var actionMethod = executor.GetType().GetMethod(action.Method);
    
        // return delegates which will simply invoke these methods
        return new Result
        (
            () => (bool)testMethod.Invoke(tester, new object[] { test.Param }),
            () => actionMethod.Invoke(executor, new object[] { action.Param })
        );
    }
    

    That is, more or less, your program’s skeleton. You should be able to fill in the missing parts yourself, as an exercise. If you have problems, I can update the answer later.

    A GetMethodAndParams method should split the input string into a Tuple (or your custom class) which contains the method name and its params as plain strings. Tester and Executor classes can also be implemented trivially.

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

Sidebar

Related Questions

How do you manage development and deployment of a n-tier system that's made up
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
So I'm going to be working on a home made blog system in PHP
I've made many different seperate parts of a GUI system for the Nintendo DS,
I have a vertical menu in my system which is basically made of HTML
I've made an simple installation class: [RunInstaller(true)] public class MyCustumAction : Installer { public
UPDATE: I made major changes to this post - check the revision history for
I have a non-MFC, non-ATL C++ app that routinely creates notification balloons on a
I've created a simple Java application that each second for for 10 seconds consecutive
I'm trying to write a simple HTTP remember me authentication system for users. My

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.