Click here to Skip to main content
15,915,019 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: ORM Quick Survey Pin
Mike Hankey12-Apr-18 7:47
mveMike Hankey12-Apr-18 7:47 
GeneralRe: ORM Quick Survey Pin
Kevin Marois12-Apr-18 8:24
professionalKevin Marois12-Apr-18 8:24 
GeneralRe: ORM Quick Survey Pin
Jörgen Andersson12-Apr-18 8:33
professionalJörgen Andersson12-Apr-18 8:33 
GeneralRe: ORM Quick Survey Pin
RickZeeland12-Apr-18 8:42
mveRickZeeland12-Apr-18 8:42 
GeneralRe: ORM Quick Survey Pin
Foothill12-Apr-18 8:49
professionalFoothill12-Apr-18 8:49 
GeneralRe: ORM Quick Survey Pin
RickZeeland12-Apr-18 8:56
mveRickZeeland12-Apr-18 8:56 
GeneralRe: ORM Quick Survey Pin
Foothill12-Apr-18 9:37
professionalFoothill12-Apr-18 9:37 
GeneralRe: ORM Quick Survey Pin
Jon McKee12-Apr-18 12:04
professionalJon McKee12-Apr-18 12:04 
C#
dObj["AnIntegerProperty"].SetValue(42);

Not suggesting premature optimization, but if this SetValue ends up causing any bottlenecks you can do the following which works for properties but not fields because of how the values are set internally:
C#
class PropertyInfoWrapper
{
  private Action<object, object> _setValueDelegate;

  public PropertyInfoWrapper(PropertyInfo property)
  {
    MethodInfo delegateHelper = typeof(PropertyInfoWrapper).GetTypeInfo()
      .GetMethod(nameof(this.CreateDelegate), BindingFlags.Instance | BindingFlags.NonPublic)
      .MakeGenericMethod(property.DeclaringType, property.PropertyType);
    _setValueDelegate = (Action<object, object>)delegateHelper.Invoke(
      this, 
      new object[] { property.SetMethod });
  }

  private Action<object, object> CreateDelegate<TObject, TProp>(MethodInfo method)
  {
    var del = (Action<TObject, TProp>)method.CreateDelegate(typeof(Action<TObject, TProp>));
    return (object obj, object val) => { del((TObject)obj, (TProp)val); };
  }

  public void SetValue(object container, object value) =>
    _setValueDelegate(container, value);
}

I've been debating on whether to do an article about my RegexContainer[^] project for a similar reason (where this example is from). There's a lot of dislike for reflection even when it's useful.
GeneralRe: ORM Quick Survey Pin
Foothill13-Apr-18 3:11
professionalFoothill13-Apr-18 3:11 
GeneralRe: ORM Quick Survey Pin
User 1106097912-Apr-18 9:19
User 1106097912-Apr-18 9:19 
GeneralRe: ORM Quick Survey Pin
Foothill12-Apr-18 9:43
professionalFoothill12-Apr-18 9:43 
GeneralRe: ORM Quick Survey Pin
Nish Nishant12-Apr-18 10:23
sitebuilderNish Nishant12-Apr-18 10:23 
GeneralRe: ORM Quick Survey Pin
kmoorevs12-Apr-18 11:06
kmoorevs12-Apr-18 11:06 
GeneralRe: ORM Quick Survey Pin
MadMyche13-Apr-18 3:58
professionalMadMyche13-Apr-18 3:58 
GeneralRe: ORM Quick Survey Pin
Mycroft Holmes12-Apr-18 13:39
professionalMycroft Holmes12-Apr-18 13:39 
GeneralRe: ORM Quick Survey Pin
Jacquers12-Apr-18 20:37
Jacquers12-Apr-18 20:37 
GeneralRe: ORM Quick Survey Pin
twaindev12-Apr-18 20:40
twaindev12-Apr-18 20:40 
GeneralRe: ORM Quick Survey Pin
Pachangas12-Apr-18 21:25
Pachangas12-Apr-18 21:25 
GeneralRe: ORM Quick Survey Pin
Ste.S12-Apr-18 22:41
Ste.S12-Apr-18 22:41 
GeneralRe: ORM Quick Survey Pin
andegre13-Apr-18 2:59
andegre13-Apr-18 2:59 
GeneralRe: ORM Quick Survey Pin
DerekT-P12-Apr-18 23:08
professionalDerekT-P12-Apr-18 23:08 
GeneralRe: ORM Quick Survey Pin
Roman Ivantsov13-Apr-18 2:41
professionalRoman Ivantsov13-Apr-18 2:41 
GeneralRe: ORM Quick Survey Pin
andegre13-Apr-18 2:52
andegre13-Apr-18 2:52 
GeneralRe: ORM Quick Survey Pin
Adam O'Neil (Travelers Rest, SC)13-Apr-18 4:15
Adam O'Neil (Travelers Rest, SC)13-Apr-18 4:15 
GeneralRe: ORM Quick Survey Pin
Thornik13-Apr-18 4:37
Thornik13-Apr-18 4:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.