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 7016111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:44:31+00:00 2026-05-27T22:44:31+00:00

I have a simple class. And I have to add some conditions to some

  • 0

I have a simple class. And I have to add some conditions to some methods and properties. For example:

public class Example
{
  public Boolean Condition {get; set;}
  public Double ConditionValue {get; set;}

  [Verify("!Condition && ConditionValue>5")]
  public void DoSomthing()
  { ... }
}

I want to check the condition (for example, “!Condition && ConditionValue>5”) in an aspect attribute. I can not give an action/func into an attribute so I give a simple string. And I need to translate this string into a condition:

[Serializable]
public class MyAspectAttribute : OnMethodBoundaryAspect
{
    public override void OnExit(MethodExecutionArgs args)
    {
        if (!this.Condition && this.ConditionValue>5) // If-statment from string, this is the problem...
        { ... }
    }
}  

How I can extract real if-statment from string? I see some solutions, but I’m not sure they fine:

  1. Use a runtime compiler, e.g. CSharpCodeProvider.
  2. Use a library such as http://flee.codeplex.com/
  3. Somthing else…?

How I can do it gracefully? Thanks!

Upd: I have edited the question on the advices…
Upd2: I don’t try to verification my code, I can do this:

public class Example2
    {
      public Boolean Condition {get; set;}

      [LoggingIf("Condition")]
      public void DoSomthing1()
      { ... }

      [PrintReportIf("!Condition")]
      public void DoSomthing2()
      { ... }
    }
  • 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-27T22:44:32+00:00Added an answer on May 27, 2026 at 10:44 pm

    Considered using lambda expressions parser? You should be able to do something along the lines:

    [Verify("(Example e) => !e.Condition && e.Condition > 5")]
    public void DoSomthing() 
    { ... }
    

    And compile that later using:

    [Serializable]
    public class MyAspectAttribute : OnMethodBoundaryAspect
    {
        public override void OnExit(MethodExecutionArgs args)
        {
             ExprParser parser = new ExprParser();
             LambdaExpression lambda = parser.Parse(/* Verify string comes here */);
             bool isConditionMet = (bool) parser.Run(lambda, this);
    
             if (isConditionMet)
             { ... }
        }
    }
    

    Edit:

    For custom user types, you need to provide namespace (and assembly if type resides in different assembly than the one you call parser from):

    ExprParser.Using.Add("PersonTypeNamespace");
    ExprParser parser = new ExprParser();
    LambdaExpression lambda = parser.Parse("(Person p) => p.Name");
    var output = parser.Run(lambda, new Person { Name = "DragonFire" });
    

    In download section there’s User guide file – it provides some extra information on library usage.

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

Sidebar

Related Questions

I have an simple class that I get from a webservice. public class person
Suppose you have a viewModel: public class CreatePersonViewModel { [Required] public bool HasDeliveryAddress {get;set;}
I have a simple domain class with two properties. For example: class Person {
I have a simple class Student under namespace School. namespace XmlTestApp { public class
I have a simple Class Hierarchy that I am trying to get to work
I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
I have a simple class that contains some general information about the current web
I have a simple class inheriting from WebControl as follow: public class Instrument :
Say we have this hyper simple class hierchy: public class SomeMath { public int
I have a simple RAII class to ensure some handle is properly disposed of.

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.