lundi 8 février 2016

How to Set a property using a func<>

Say I have a function How do i set the property on the record

public void SetProperty<TRecord, TEnum>(TRecord item,  
                                        Func<TRecord, TEnum> property, string enumValue )
   where TEnum : struct
   where TRecord : class
{
     TEnum enumType;
     if (Enum.TryParse(enumValue, true, out enumType))
     {
         //How Do I set this?
         property.Invoke(item) = enumType;
     }
}

I'd prefer not to switch this to an expression. Does anybody know how to set the property?





Aucun commentaire:

Enregistrer un commentaire