I'm trying to use Dot Liquid which is one of the coolest templating engines for c#. Dot Liquid uses a way in order to make using templates safe. Here is the explanation page.
Here is the Explanation from it's wiki:
DotLiquid, by default, only accepts a limited number of types as parameters to the Render method - including the .NET primitive types(int, float, string, etc.), and some collection types including IDictionary, IList and IIndexable (a custom DotLiquid interface).
If it supported arbitrary types, then it could result in properties or methods being unintentionally exposed to template authors. To prevent this, DotLiquid uses Drop objects. Drops use an opt-in approach to exposing object data.
The Drop class is just one implementation of ILiquidizable, and the simplest way to expose your objects to DotLiquid templates is to implement ILiquidizable directly
Wiki Sample Code:
public class User
{
public string Name { get; set; }
public string Email { get; set; }
}
public class UserDrop : Drop
{
private readonly User _user;
public string Name
{
get { return _user.Name; }
}
public UserDrop(User user)
{
_user = user;
}
}
Template template = Template.Parse("Name: {{ user.name }}; Email: {{ user.email }};");
string result = template.Render(Hash.FromAnonymousObject(new
{
user = new UserDrop(new User
{
Name = "Tim",
Email = "[email protected]"
})
}));
So when I pass DataRow to liquid, liquid wont let me show it's content and tells me that:
'System.Data.DataRow' is invalid because it is neither a built-in type nor implements ILiquidizable
Is there any solutions to pass DataRow object that implements ILiquidizable too? Thanks
DataRow
to a class instance of your own, which implementsILiquidizable
. I don't see how you could make an existing class likeDataRow
suddenly support a new interface.... – marc_s