public static bool SetValue()

in src/DeloitteDigital.Atlas/Extensions/TypeExtensions.cs [17:34]


        public static bool SetValue( this object theObject, string propertyName, object val )
        {
            try
            {
                var property = theObject.GetType( ).GetProperty( propertyName );
                if ( property == null )
                    return false;
                // convert the value to the expected type
                val = Convert.ChangeType( val, property.PropertyType );
                // attempt the assignment
                property.SetValue( theObject, val, null );
                return true;
            }
            catch
            {
                return false;
            }
        }