-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide Default behaviour of "Nullable" types in plain objects when value is NULL #5
Comments
Additionally, Null properties of Parser options doesn't works for me in String Properties of my plain .cs object. Non Working Code 👎var options = new ParserOptions(sourceTemplate)
{
ValueResolver = new NullableValuesResolver(),
Null = "null" //doesn't works :(
}; I've fixed this problem using always my NullableValuesResolver, as this: Working Code 👍public class NullableValuesResolver : IValueResolver {
public bool CanResolve(Type type, object value, string path, ContextObject context) {
return true;
}
public object Resolve(Type type, object value, string path, ContextObject context) {
var result = type.GetProperty(path).GetValue(value);
if (result == null)
{
return "null";
}
return result;
}
} |
@garzy Thank you for this pretty good written bug i appreciate that. I was able to reproduce the bug and fixed it. A Nuget Release is on its way and should be available soon. https://www.nuget.org/packages/Morestachio/2.3.7 You should be able to use the "Null" property of the Options object again. |
Thanks for the very fast bugfix, I've tested the new version this morning and its works like a charm with only this code: var options = new ParserOptions(sourceTemplate)
{
Null = "null"
}; I don't need my NullableValuesResolver anymore :) Thanks! |
You are welcome. That are the perks of an HomeOffice ;-) |
Hello!, I'm currently generating javascript files with a template, injecting the values with morestachio.
The Problem
Part of my template file (javascript.tpl):
Part of my plain object (JavascriptParams.cs):
Wanted output if property is NULL:
Current output:
The Solution
[...]
The text was updated successfully, but these errors were encountered: