title: Dynamic Binding Flag Algorithm which uses RegExp
body: <p>I've been at this for at least 3 hours now - 1.5 - 2 of which has been spent just learning regex in order to do this. I am still nowhere near comprehending it, but that's not quite the priority: I'd rather get this algorithm flushed out first. </p>
  
  <p>SO..</p>
  
  <p>Here, I have a nice little method which accepts a string which is basically supposed to contain a phrase that determines what kind of bindingflag to return. The string is evaluated by the regexpression. If this expression comes out to true, it goes onward to move through an array which lists the proper BindingFlags settings to set. I have most of this figured out - the main problem is A) simplicity, and B) the last two bits: ensuring that a BindingFlag will be returned (Which I believe I have done, but I still get a logic error from that, so obviously I haven't), and comparing the string with the actual BindingFlag array to determine which flag to select and return. </p>
  
  <p>Kind of complicated for my level. Here's the code:</p>
  
  <pre><code>private static BindingFlags CheckPropBinding(string bindFlagSpec) 
          {
              BindingFlags binderFlag; //--will be returned.
  
              string bindLower = bindFlagSpec.ToLower(); //--lowers string parameter.
  
              Match matchBinder; //--our matcher :).
  
              string regex = "regex dummy"; /*--this is a dummy which will be replaced when I've found the appropriate regex to use. */
  
              matchBinder = Regex.Match(bindLower, regex); 
  
              if (matchBinder.Success) //--if success, will go on...
              {
                  for(int bindIndex = 0; bindIndex &lt; bindings.Length; bindIndex++) /*--compares string with bindingFlag array */
                  {
                      if (bindLower.Contains(bindings[bindIndex].ToString()))
                      {
                          binderFlag = bindings[bindIndex];
  
                          break;
                      }
                      else 
                      {
                          if (bindIndex == bindings.Length &amp;&amp; !bindLower.Contains(bindings[bindings.Length].ToString())) 
                          {
                               binderFlag = BindingFlags.NonPublic; /*--this is just a
  </code></pre>
  
  <p>last resort check, assigning a default flag if for some reason one can't be selected.*/
                                   break;
                              }</p>
  
  <pre><code>                        continue;
                      }
  
                   }
              }
  
  
              return binderFlag; //--returned :).
         }
  </code></pre>
  
  <p>I should probably also mention the binding flags array field:`</p>
  
  <pre><code>public class PropertyManagener
      {
          private static BindingFlags[] bindings = {BindingFlags.NonPublic, BindingFlags.Public, 
                                                       BindingFlags.Static, BindingFlags.Instance};
  </code></pre>