title: How to search if an object has a property with a value C#
body: <p>I would like to create a function where I can pass in an arbitrary object and check to see if it has a specific property with a specific value. Im attempting to do this using reflection, but reflection still confuses me a little bit. I was hoping that someone might be able to point me in the right direction.</p>
  
  <p>here is the code that im trying but obviously it doesnt work:</p>
  
  <pre><code>    public static bool PropertyHasValue(object obj, string propertyName, string propertyValue)
  {
      try
      {
          if(obj.GetType().GetProperty(propertyName,BindingFlags.Instance).GetValue(obj, null).ToString() == propertyValue)
          {
              Debug.Log (obj.GetType().FullName + "Has the Value" + propertyValue);
              return true;    
          }
  
          Debug.Log ("No property with this value");
          return false;
      }
      catch
      {
          Debug.Log ("This object doesnt have this property");
          return false;
      }
  
  }
  </code></pre>