You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement a sort of LazyValue implementation.
I've implemented changed both in public class MyScriptObject : ScriptObject
and public class MyTemplateContext : TemplateContext
... works, but as I advance in tests, there are edge cases coming, forcing me to revisit the source code to check what's going on.
For now, I'm stuck when an object is nested. Example, when the LazyValue is a property of a random object:
varmodel={person=new{
values =new{
lazyValue1 =newLazyValue<object>(()=>1234),//LazyValue is a custom lazy handler, works similar to Lazy}}}//template: {{ person.values.lazyValue1 }}
In the case above, the ScriptObject, which give us the necessary control, can't manage this because the case is out of it's scope.
That is managed by the TemplateContext AND TypedObjectAcessor.
The ScriptObject has a handly method (TryGetValue) which allows us to make the magic work. But this only work in first level of imported objects.
But the TemplateContext has no such trick. As I investigated, you have to implement your own TypedObjectAcessor and handle your own TryGetValue().
Well, I could copy the entire code of TypedObjectAcessor, but what if you introduce important changes? I would lose these changes.
So, I'd like to ask you if you cold change one or both of the following:
ensure the TypeObjectAcessor is public, where we can override the TryGetValue() by just making it virtual
or
a handly TryGetValue() in the TemplateContext, as exists in the ScriptObject
Is it possible?
The text was updated successfully, but these errors were encountered:
I would think that it would be easier to use a custom parameter less function like this to wrap a lazy value (I could add this to library if necessary)
[Test]publicvoidTestLazy(){varinput=@"{{ value }}";vartemplate= Template.Parse(input);varresult= template.Render(new{ value =newScriptLazy<int>(()=>1)});
Assert.AreEqual("1", result);}
Hello,
I'm trying to implement a sort of LazyValue implementation.
I've implemented changed both in
public class MyScriptObject : ScriptObject
and
public class MyTemplateContext : TemplateContext
... works, but as I advance in tests, there are edge cases coming, forcing me to revisit the source code to check what's going on.
For now, I'm stuck when an object is nested. Example, when the LazyValue is a property of a random object:
In the case above, the ScriptObject, which give us the necessary control, can't manage this because the case is out of it's scope.
That is managed by the TemplateContext AND TypedObjectAcessor.
The ScriptObject has a handly method (TryGetValue) which allows us to make the magic work. But this only work in first level of imported objects.
But the TemplateContext has no such trick. As I investigated, you have to implement your own TypedObjectAcessor and handle your own TryGetValue().
Well, I could copy the entire code of TypedObjectAcessor, but what if you introduce important changes? I would lose these changes.
So, I'd like to ask you if you cold change one or both of the following:
or
Is it possible?
The text was updated successfully, but these errors were encountered: