public static T LateBoundProperty <T>(object source, string property) { PropertyInfo pi = source.GetType().GetProperty(property); if (pi == null) { return(default(T)); } try { object value = pi.GetValue(source, null); if (pi.PropertyType == typeof(T)) { return((T)value); } else { return(default(T)); } } catch (Exception ex) { if (Failure.IsCriticalException(ex)) { throw; } return(default(T)); } }
public static void Dispose(object instance) { var d = instance as IDisposable; if (d == null) { return; } try { d.Dispose(); } catch (Exception ex) { if (Failure.IsCriticalException(ex)) { throw; } } }