title: Execute the code stored as a String in VB.NET
body: <p>I wonder about how I can store a part of code in a string field of an object and convert it at run-time in executable code.</p>
  
  <p>Let's say I have my class:</p>
  
  <pre><code>Public Class Car
  
  Public m_IDCar As String
  Public m_Brand As String
  Public m_Description As String
  Public m_Condition As String ' =&gt; here I need to store an If, or an If condition as a String, that will be executed at run-time.
  
  End Class
  </code></pre>
  
  <p>Then the code that happens when <code>CommandButton1.Click()</code>:</p>
  
  <pre><code>Dim  carList As List(Of Car)
  Dim parameter as String
  
  ' here I create carList with data from a database, so for each car In the database I create its relative object, with its .m_IDCar, .m_Brand, .m_Description and .m_Condition, and add it to carList
  
  parameter = TextBox1.Text ' =&gt; given in input by the user
  
  For each car As Car in carList
      If (car.m_Condition = True) then  ' =&gt; here there must be something to do cause, as things are now, in car.m_Condition is stored a String, but I need to parse it in code that returns a boolean value and, if this value would be True, the code will enter in the If statement.
          'do something
       End If
  Next
  </code></pre>
  
  <p>Example of <code>car.m_Condition</code> could be:</p>
  
  <pre><code>car.m_Condition = "(car.m_Name=""BMW"" AND car.m_Description.Contains(parameter)) OR car.m_Brand=""AUDI"""
  </code></pre>
  
  <p>I need some tips on how to implement this approach, if someone would help me.</p>
  
  <p>TY!</p>
  
  <p>EDIT:
  Thanks David, I have seen that question and seems a lot similar. I've seen that the user asked how store the entire If in a string:</p>
  
  <pre><code>Dim code As String = "IIf(1 = 2, True, False)"
  </code></pre>
  
  <p>(the users that asked that question used IIf)</p>
  
  <p>The best way for me would be to store the condition to evaluate in a string and, maybe, the value to with compare the result in another one. So, for example:</p>
  
  <pre><code>Dim condition As String = "(car.m_Name=""BMW"" AND car.m_Description.Contains(parameter)) OR car.m_Brand=""AUDI"""
  Dim valueToCompareWith as String = "True"
  </code></pre>
  
  <p>and the following If</p>
  
  <pre><code>If (car.m_Name=""BMW"" AND car.m_Description.Contains(parameter)) OR car.m_Brand=""AUDI"" = True) Then
  'do something
  End If
  </code></pre>
  
  <p>will become:</p>
  
  <pre><code>If (condition = valueToCompareWith) Then '(conceptually, because in this form it's simply a String comparison that returns always False)
  'do something
  End If
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>Thanks Plutonix, I've read about your hint on Getters and Setters, I've not specified it, but the context I'm working on is a lot more complex then this. I've made a very simple example just for focus the problem, but I'm working with a good amount of objects, with various fields to compare and for every comparison there are different conditions in the If, with different logics and different types of data to compare.</p>