我希望我能用RPGLe做一些反思.通过反思,我的意思是:'在运行时确定对象功能的过程或机制.'
想象一下,你有这个数据结构:
D DS_Format DS Qualified Based(pDS_Format)
D Type 20I 0 Inz(1)
D Label 50A Inz('myLabel')
D Description 5000A Inz('myDescription')
Run Code Online (Sandbox Code Playgroud)
使用反射api,我可以这样做:
Reflection_ListSubfields(DS_Format);
Run Code Online (Sandbox Code Playgroud)
=>返回此数组:{'Type','Label','Description'}
然后,我可以这样做:
Reflection_GetSubfield(DS_Format : 'Label'); => return 'myLabel'
Run Code Online (Sandbox Code Playgroud)
我希望我也可以这样做:
Reflection_GetSubfieldType(DS_Format : 'Label'); => return 'A'
Reflection_GetSubfieldLength(DS_Format : 'Label'); => return 50
Reflection_GetSubfieldPrecision(DS_Format : 'Type'); => return 0
Run Code Online (Sandbox Code Playgroud)
有了这个,我希望我可以做这样的事情(有一些小工作):
SerializeXml(DS_Format); //I build xml with one line of code !
Run Code Online (Sandbox Code Playgroud)
得到:
<DS_Format>
<Type>1</Type>
<Label>myLabel</Label>
<Description>myDescription</Description>
</DS_Format>
Run Code Online (Sandbox Code Playgroud)
与DeserializeXml(myXml)相反;
反思会帮助我建立真正酷的apis.有什么办法吗?