Created
October 26, 2012 08:43
-
-
Save jacobmendoza/3957681 to your computer and use it in GitHub Desktop.
El motor de plantillas más simple del mundo
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
private string ObjectToTextTemplate(string text, object objectToSerialize) | |
{ | |
const string enclosingSymbol = "#"; | |
const string entityProxyModule = "EntityProxyModule"; | |
var type = objectToSerialize.GetType(); | |
var isEntityFrameworkProxyObject = type.Module.ScopeName.Contains(entityProxyModule); | |
foreach (var propertyInfo in type.GetProperties()) | |
{ | |
if ((!propertyInfo.CanRead) || (!propertyInfo.CanWrite)) continue; | |
if (type.BaseType != null) | |
{ | |
var typeName = (isEntityFrameworkProxyObject) ? type.BaseType.Name : type.Name; | |
var tokenToLookup = string.Format("{0}{1}.{2}{0}", enclosingSymbol, typeName, propertyInfo.Name); | |
text = text.Replace(tokenToLookup, propertyInfo.GetValue(objectToSerialize, null).ToString()); | |
} | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment