public static PropertyInfo GetSettablePropertyInfo(Type type, string propertyName) { PropertyInfo propertyInfo = TypeSystem.GetPropertyInfo(type, propertyName); if (propertyInfo == null) { return(null); } else { if (propertyInfo.CanWrite) { return(propertyInfo); } else { return(null); } } }
public static object GetPropertyValue(object instance, string propertyName, bool throwIfMissing = true) { object value; Type type = instance.GetType(); PropertyInfo propertyInfo = TypeSystem.GetPropertyInfo(type, propertyName); if (propertyInfo == null) { object fieldValue = TypeSystem.GetFieldValue(instance, propertyName); if (fieldValue != null) { return(fieldValue); } } if (!throwIfMissing) { if (propertyInfo == null) { return(null); } } else { if (propertyInfo == null) { object[] assemblyQualifiedName = new object[2]; assemblyQualifiedName[0] = propertyName; assemblyQualifiedName[1] = type.AssemblyQualifiedName; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.PropertyNotFoundInDotNetType, assemblyQualifiedName), "propertyName"); } } try { value = propertyInfo.GetValue(instance, null); } catch (Exception exception1) { Exception exception = exception1; TraceHelper.Current.DebugMessage(exception.ToTraceMessage(string.Concat("GetPropertyValue failed to parse property: ", propertyName))); if (!exception.IsIgnorablePropertyException()) { if (!exception.IsSevereException()) { object[] message = new object[2]; message[0] = propertyName; message[1] = exception.Message; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.PropertyRetrievalFailed, message), exception); } else { throw; } } else { if (!throwIfMissing) { value = null; } else { object[] objArray = new object[2]; objArray[0] = propertyName; objArray[1] = type.AssemblyQualifiedName; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.PropertyNotFoundInDotNetType, objArray), "propertyName"); } } } return(value); }