Last active
August 29, 2015 14:12
-
-
Save demircimurat/0f4cbc23b7a168f16c84 to your computer and use it in GitHub Desktop.
Revisions
-
Murat Demircioglu revised this gist
Jan 4, 2015 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ /* * based on Jorge Fioranelli's code.. * http://blog.jorgef.net/2011/06/converting-any-object-to-dynamic.html */ public static class Extensions { public static dynamic ToDynamic(this object value) -
Murat Demircioglu revised this gist
Jan 4, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,8 +28,7 @@ public static bool IsListOrArray(this object value) return true; } if (value.GetType().IsArray) { return true; } -
Murat Demircioglu created this gist
Jan 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ public static class Extensions { public static dynamic ToDynamic(this object value) { if (value.IsListOrArray ()) { var list = new List<ExpandoObject> (); IEnumerable enumerable = value as IEnumerable; foreach (object o in enumerable) { list.Add (o.ToDynamic ()); } return (dynamic) list; } IDictionary<string, object> expando = new ExpandoObject (); foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType())) { expando.Add (property.Name, property.GetValue (value)); } return (dynamic) expando; } public static bool IsListOrArray(this object value) { if(value is IList && value.GetType().IsGenericType) { return true; } var valueType = value.GetType (); if (valueType.IsArray) { return true; } return false; } }