Skip to main content
added 275 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191

   public void CloneProperties(T source, T target)
   {
        SetProperties(target, GetProperties(source, CloneableProperties));
   }

    public void SetToDefault(ref T instance)
    {
        instance = _applyDefaultValues(instance);
    }

There's no need for these methods. You can always call

accessor.SetValue("prop", default(int));

or write an extension for either one.


   public void CloneProperties(T source, T target)
   {
        SetProperties(target, GetProperties(source, CloneableProperties));
   }

    public void SetToDefault(ref T instance)
    {
        instance = _applyDefaultValues(instance);
    }

There's no need for these methods. You can always call

accessor.SetValue("prop", default(int));

or write an extension for either one.

added 1282 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191

These methods are implemented in a very inconsitant way. Only one checks if the property exists in the dictionary, the other ones will crash. There's also a lot of repetition. The entire logic should be in only one getter/setter and the other overloads should call the main method. Lastly I think their names should be changed to GetValue/SetValue because this is what they do.

These methods are implemented in a very inconsitant way. Only one checks if the property exists in the dictionary, the other ones will crash. There's also a lot of repetition. The entire logic should be in only one getter/setter and the other overloads should call the main method.

These methods are implemented in a very inconsitant way. Only one checks if the property exists in the dictionary, the other ones will crash. There's also a lot of repetition. The entire logic should be in only one getter/setter and the other overloads should call the main method. Lastly I think their names should be changed to GetValue/SetValue because this is what they do.

added 1282 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191

Getting and setting properties

private object GetProperty(T instance, string propertyName)
    => GetterCache[propertyName].Invoke(instance);

public TValue GetProperty<TValue>(T instance, Expression<Func<T, TValue>> property)
    => (TValue) GetterCache[GetMemberInfo(property).Name](instance);

private void SetProperty(T instance, string propertyName, object value)
{
    Action<T, object> setter;

    if (SetterCache.TryGetValue(propertyName, out setter))
    {
        setter(instance, value);
    }
    else
    {
        throw new KeyNotFoundException(
            $"a property setter with the name does not {propertyName} exist on {typeof(T).FullName}");
    }
}

public void SetProperty<TValue>(T instance, Expression<Func<T, TValue>> property, TValue value)
    => SetterCache[GetMemberInfo(property).Name](instance, value);

These methods are implemented in a very inconsitant way. Only one checks if the property exists in the dictionary, the other ones will crash. There's also a lot of repetition. The entire logic should be in only one getter/setter and the other overloads should call the main method.


Getting and setting properties

private object GetProperty(T instance, string propertyName)
    => GetterCache[propertyName].Invoke(instance);

public TValue GetProperty<TValue>(T instance, Expression<Func<T, TValue>> property)
    => (TValue) GetterCache[GetMemberInfo(property).Name](instance);

private void SetProperty(T instance, string propertyName, object value)
{
    Action<T, object> setter;

    if (SetterCache.TryGetValue(propertyName, out setter))
    {
        setter(instance, value);
    }
    else
    {
        throw new KeyNotFoundException(
            $"a property setter with the name does not {propertyName} exist on {typeof(T).FullName}");
    }
}

public void SetProperty<TValue>(T instance, Expression<Func<T, TValue>> property, TValue value)
    => SetterCache[GetMemberInfo(property).Name](instance, value);

These methods are implemented in a very inconsitant way. Only one checks if the property exists in the dictionary, the other ones will crash. There's also a lot of repetition. The entire logic should be in only one getter/setter and the other overloads should call the main method.

added 1439 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 754 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 2 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 1543 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 3 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 846 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 200 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 921 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
Post Undeleted by t3chb0t
added 640 characters in body
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
Post Deleted by t3chb0t
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading