Created
November 1, 2012 16:14
-
-
Save StacyGay/3994708 to your computer and use it in GitHub Desktop.
Utilities methods for getting data to javascript front end
This file contains 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 characters
namespace Utilities.Data | |
{ | |
public static class Extensions | |
{ | |
public static string ToJson(this Object obj) | |
{ | |
return (new JavaScriptSerializer()).Serialize(obj); | |
} | |
} | |
public class DataHelper | |
{ | |
public static string ObjectToHtmlData<T>(T obj) | |
{ | |
string htmlDataAttributes = ""; | |
foreach(var dataMember in obj.GetType().GetProperties()) | |
htmlDataAttributes += "data-"+dataMember.Name+"=\""+dataMember.GetValue(obj,null)+"\" "; | |
return htmlDataAttributes; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment