Hi everyone,
​
I have developed a paclet (to be shared soon), and as a final touch I’m trying to make some custom objects behave in a more “WL native” way.
I have noticed that many objects in WL have associated information that can be accessed by using the Information function.
For example, with neural nets:
In[]:=
net=NetChain[{4,Ramp,2,Ramp,3}]
Out[]=
NetChain
Inputport:
array
Outputport:
vector(size: 3)

In[]:=
info=Information[net]
Out[]=
Net Information
Layers Count
5
Arrays Count
6
Shared Arrays Count
0
Input Port Names
{Input}
Output Port Names
{Output}
Arrays Total Element Count
Indeterminate
Arrays Total Size
Indeterminate
In[]:=
Information[net,"ArraysCount"]
Out[]=
6
Underneath this, there seems to be an an InformationData object associated to NetChain:
In[]:=
FullForm[info]
Out[]//FullForm=
InformationData[Association[Rule["LayersCount",5],Rule["ArraysCount",6],Rule["SharedArraysCount",0],Rule["InputPortNames",List["Input"]],Rule["OutputPortNames",List["Output"]],Rule["ArraysTotalElementCount",Indeterminate],Rule["ArraysTotalSize",Indeterminate],Rule["ObjectType","NetInformation"]]]
My question is: How can I implement my own InformationData object so that I can access information about custom objects in this way?
​
For the purpose of illustration, suppose I have defined MyObject:
ClearAll[MyObject,MyObjectQ];​​​​MyObject[a_Integer] := MyObject[<|"List"->Range[a]|>]​​​​MyObjectQ[asc_?AssociationQ] := KeyExistsQ[asc, "List"]​​​​(* Make it appear in "iconised" form *)​​MyObject/:MakeBoxes[obj:MyObject[asc_?MyObjectQ],form:(StandardForm|TraditionalForm)] := Module[{info},​​ info={{BoxForm`SummaryItem[{"Length: ",Length@asc["List"]}]}};​​ BoxForm`ArrangeSummaryBox[MyObject,obj,None,info,{},form,"Interpretable"->Automatic]​​];
Let’s create an instance of it:
In[]:=
obj=MyObject[3]
Out[]=
MyObject
Length: 3

Suppose I have some function that compute some property of MyObject instances, for example:
In[]:=
getSomeProperty[obj_MyObject]:=MinMax[obj[[1]]["List"]]
In[]:=
getSomeProperty[obj]
Out[]=
{1,3}
What should I do to access such information using
Information[obj]
or
Information[obj,"SomeProperty"]
instead of calling getSomeProperty[obj]?
​