c# - How to Use Reflection to Access Non-Public List and Its Non-Public Elements -
i need access list elements within array "message" strings, so:
string msg0 = sender.synchelper.uploadsyncprogresslist[0].results.exception.message; string msg1 = sender.synchelper.uploadsyncprogresslist[1].results.exception.message; ...
i given "sender" object (which of type "object"). rest (synchelper, uploadsyncprogresslist, results, exception , message) non-public. these, class types of non-public types (except "exception").
this image shows visual representation of problem.
i have managed use reflection list variable "uploadsyncprogresslist" following code, stuck on how loop through list elements "messages" string:
propertyinfo synchelperinfo = sender.gettype().getproperty("synchelper", system.reflection.bindingflags.public | system.reflection.bindingflags.nonpublic | system.reflection.bindingflags.instance); object synchelper = synchelperinfo.getvalue(sender, null); propertyinfo uploadprogresssynclistinfo = synchelper.gettype().getproperty("uploadsyncprogresslist", system.reflection.bindingflags.public | system.reflection.bindingflags.nonpublic | system.reflection.bindingflags.instance); object uploadprogresssynclist = uploadprogresssynclistinfo.getvalue(synchelper, null);
how loop through "uploadprogresssynclist" elements "message" strings?
i doing because need access low-level network error messages hidden in 3rd party library.
thanks in advance!
you have few options here.
as uploadsyncprogresslist type of list<esri...eventargs>
implements following collection interfaces
generic
ilist<t>
ienumerable<t>
icollection<t>
ireadonlylist<t>
ireadonlycollection<t>
non generic
ienumerable
icollection
ilist
so if eventargs in context public can cast result uploadprogresssynclist
of generic interface
eg
ilist<esri...eventargs> synclist = (ilist<esri...eventargs>)uploadprogresssynclist;
you can use of generic interface above suits needs
if event arg type not public non generic choice
ilist synclist = (ilist)uploadprogresssynclist;
using ilist
ilist<t>
, ireadonlylist<t>
interface retrieve via indexes
eg
var arg1 = synclist[0];
for of above can iterate using foreach
eg
foreach(var arg in synclist) { //your logic arg }
Comments
Post a Comment