Reflection Ignore Unsupported Properties

I am using reflection in an editor script. The script looks up all of the components on a GameObject and returns their properties with GetProperties();

Some properties are obsolete and return an error when used in conjunction with GetValue such as:

minVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead.
System.Reflection.MonoProperty:GetValue(Object, Object[])

How can we check for these obsolete properties or simply avoid having to see these error messages?

try{ 
  propertyValue = propertyInfo.GetValue(myComponent,null); 
} catch {
  // is not catching the error
}

Edit: The problematic properties I’ve found were “rolloffFactor”,“minVolume”, and “maxVolume” which are all from AudioSource. My current workaround is to check for these property names and skip them.

You need to use:

if(!propertyInfo.IsDefined(typeof(ObsoleteAttribute), true))
    propertyValue = propertyInfo.GetValue(myComponent,null);

I accidently just posted some code first, but the idea is to look for an Obsolete attribute on your property.

Here’s some more info:

And a code snippet:

object[] attr = propertyInfo.GetCustomAttributes (typeof(ObsoleteAttribute), true);

if(attr.Length > 0)
   continue;