Import Object not work
See original GitHub issueI have a class as ScriptObject, but when I added it to a ScriptArray,it doesn’t work. The template:
<h1>{{ Paginations }}</h1>
<div>
{{~ for page in Paginations.Posters ~}}
<p>{{ page }}</p>
<p>{{ page.Title }}</p>
<p>{{ page.CreateTime }}</p>
<hr>
{{~ end ~}}
</div>
If I add my own object by array.add(obj)
,it likes:
ScriptArray array = new();
foreach(var item in my_own_objects)
{
array.Add(item);
}
ScriptObject global = new();
global.Add("Paginations",array);
TemplateContext context = new()
{
MemberRenamer = member => member.Name
};
context.PushGlobal(global);
Console.WriteLine(Template.Parse("template...").Render(context));
It output:
<h1>{PostersIndexStart: 0, IsFirstPage: true, PosterCount: 4, CurrentPageNumber: 1, Posters: [EightLeggedEssay.Poster, EightLeggedEssay.Poster, EightLeggedEssay.Poster, EightLeggedEssay.Poster, EightLeggedEssay.Poster], IsLastPage: false}</h1>
<div>
<p>EightLeggedEssay.Poster</p>
<p></p>
<p></p>
<hr>
<p>EightLeggedEssay.Poster</p>
<p></p>
<p></p>
<hr>
<p>EightLeggedEssay.Poster</p>
<p></p>
<p></p>
<hr>
<p>EightLeggedEssay.Poster</p>
<p></p>
<p></p>
<hr>
<p>EightLeggedEssay.Poster</p>
<p></p>
<p></p>
<hr>
</div>
In other way,if I added it by ScriptObject.Import()
,it will output different:
ScriptArray array = new();
foreach(var item in my_own_objects)
{
// code change here ↓
ScriptObject obj = new();
obj.Import(item)
array.Add(obj);
// code below here has not changed
}
ScriptObject global = new();
global.Add("Paginations",array);
TemplateContext context = new()
{
MemberRenamer = member => member.Name
};
context.PushGlobal(global);
Console.WriteLine(Template.Parse("template...").Render(context));
It outputs:
<h1>{CurrentPageNumber: 1, PosterCount: 4, Posters: [{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}, {base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}, {base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}, {base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}, {base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}], IsFirstPage: true, IsLastPage: false, PostersIndexStart: 0}</h1>
<div>
<p>{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}</p>
<p></p>
<p></p>
<hr>
<p>{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}</p>
<p></p>
<p></p>
<hr>
<p>{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}</p>
<p></p>
<p></p>
<hr>
<p>{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}</p>
<p></p>
<p></p>
<hr>
<p>{base_object: EightLeggedEssay.Poster, members: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}, string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], properties: [string Title {get;set;}, datetime CreateTime {get;set;}, System.Nullable[bool] Strict {get;set;}, System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] Attributes {get;set;}, string SourcePath {get;set;}, string CompiledPath {get;set;}, string Text {get;}], methods: [string get_Title(), void set_Title(string value), datetime get_CreateTime(), void set_CreateTime(datetime value), System.Nullable[bool] get_Strict(), void set_Strict(System.Nullable[bool] value), System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] get_Attributes(), void set_Attributes(System.Collections.Generic.Dictionary[string,System.Text.Json.Nodes.JsonNode] value), string get_SourcePath(), void set_SourcePath(string value), string get_CompiledPath(), void set_CompiledPath(string value), string get_Text(), type GetType(), string ToString(), bool Equals(System.Object obj), int GetHashCode()], immediate_base_object: EightLeggedEssay.Poster, type_names: ["EightLeggedEssay.Poster", "System.Object"]}</p>
<p></p>
<p></p>
<hr>
</div>
My class is just a plain class,not any interface:
public class Poster{
public string Title { get; set; } = string.Empty;
...other fields...
}
There’s no error. The Title
and CreateTime
disappeared,any help? thanks
This seems to call ToString directly. And not access field or property.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Unable to use function with imported object [duplicate]
As the documentation states: The static import statement is used to import read only live bindings which are exported by another module.
Read more >Unable to see anything after importing .obj file
I noticed that sometimes when you import an object it does not do that loading animation and immediately shows an empty mesh in...
Read more >Why import in js not working?
To import it with an import statement, the syntax without the {} automatically searches for the object property with the key default ,...
Read more >import() - JavaScript - MDN Web Docs - Mozilla
The import() call is a syntax that closely resembles a function call, but import itself is a keyword, not a function. You cannot...
Read more >Export and Import
Export before declarations ... We can label any declaration as exported by placing export before it, be it a variable, function or a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When you access to a .NET object from your running script and this object hasn’t been imported, that’s the
TemplateContext
that defines the way .NET objects are exposed.Yes, because you need to setup the renamer also on the TemplateContext. This is explained here