none
Is it safe to use reflection to access some non-public members in .net framework? RRS feed

  • Question

  • Hi all,

    This is my first question in MSDN community.  Now I have a problem as below:

    I have a DataGridView filled with 11 million rows.(since the special requirement, we don't split them into multiple pages).

    It works in virtual mode, however, with 11 million rows, it takes quite a long time to do something on this DataGridView, such as:

    loop the SelectedRows, set the CurrentCell..etc... 

    so I went through the source code of the DataGridView, and figured out a way to do the operations more quickly by accessing some private/internal members of DataGridView, it works well. 

    My concern is, my code works well in .net framework 4.7, but does it still work well if the .net framework upgrade? will the non-public methods/properties be changed in the .net framework in the future? 

    Could anyone give me some suggestion or share your experiences on this case?

    Thanks

     

    Tuesday, November 14, 2017 5:16 AM

Answers

  • Any non-public member of classes in project not owned by yourself is subject to change without notice.

    Especially since with .NET Standard, Microsoft aims to produce platform independent code so the component behavior will be the same across platforms. So I'd say the chance Microsoft may change the internal code layout is not zero.

    So don't rely on internal structures of component. If anything, just keep another copy of the data, or make use of DataView to control presentation of data instead so you can access the DataView directly.

    Tuesday, November 14, 2017 6:11 AM
    Answerer

All replies

  • Any non-public member of classes in project not owned by yourself is subject to change without notice.

    Especially since with .NET Standard, Microsoft aims to produce platform independent code so the component behavior will be the same across platforms. So I'd say the chance Microsoft may change the internal code layout is not zero.

    So don't rely on internal structures of component. If anything, just keep another copy of the data, or make use of DataView to control presentation of data instead so you can access the DataView directly.

    Tuesday, November 14, 2017 6:11 AM
    Answerer
  • Hi, sorry for the late reply, thank you so much. I will look back to my code changes again to figure out another approach.  ; )

    Thursday, March 1, 2018 1:24 AM