# 64 - Learning how to turn an Anonymous object into a Dictionary


11/17/2008
Level: Intermediate
Tags: Dot Net
Comments: (4)
Author:
Derik Whittaker


In this episode we will take a look at how to use Anonymous objects. We will also learn how we can use Anonymous objects as property bags and turn them into a Dictionary for usage.
Click here to Watch this Episode

Download (12.86 MB) (9:29) (1440x900)
Download (8.73 MB) (9:29) (960x600)

Links/Resources:


Comments: (4)

mycall said....
public static void CopyProperties(object fromObject, object toObject) { PropertyInfo[] aProps = fromObject.GetType().GetProperties(); FieldInfo[] aFields = fromObject.GetType().GetFields(); foreach(PropertyInfo oProp in aProps) { object oValue = oProp.GetValue(fromObject, null); try { if (oValue != null && oProp.CanWrite) { PropertyInfo toProp = toObject.GetType().GetProperty(oProp.Name); toProp.SetValue(toObject, oValue, null); } } catch (Exception ex) { string yy = "Error = " + ex.Message; } } foreach(FieldInfo oProp in aFields) { object oValue = oProp.GetValue(fromObject); try { if (oValue != null) { FieldInfo toProp = toObject.GetType().GetField(oProp.Name); toProp.SetValue(toObject, oValue); } } catch{} } }

11/18/2008 4:13:05 PM

celik said....

well it is very interesting.


11/25/2008 1:14:04 PM

flipdoubt said....

Hi Derick. I notice you use both Resharper and what looks like CodeRush in all your demos. Do you find they fight for resources or keyboard shortcuts? Have you tweaked one to be secondary to the other?

I'm asking because I currently use Resharper and love it, but I really appreciate knowing the cyclometric complexity of each method as I write it as CodeRush can display. If I could use that one feature from CodeRush and all of Resharper, that would be golden.

Any ideas? 


12/1/2008 5:08:26 AM

Dimecasts said....

@Flipdoubt,

Yes they do fight.  To get around this i turned off the refactoring features of coderush.  Use it pretty much for the UI candy at this point.


12/1/2008 8:56:34 AM


Name: *
Email (not displayed): *
Url:
Comments: *



So, you Human...?



Submit this story to DotNetKicks