Skip to content

TypedObjectAccessor: can you make the TryGetValue() virtual? Or create a TryGetValue on TemplateContext #479

@avataron

Description

@avataron

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:

var model = {
   person = new {
      values = new {
          lazyValue1 = new LazyValue<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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions