简体   繁体   English

是否有任何黑客方法可以访问声明为内部的父属性?

[英]Are there any hack methods for accessing a parent property declared as internal?

The problem is I have AspxGridView with Bands and Columns.问题是我有带和列的 AspxGridView。 I need to add Bands (class GridViewBands ) with ColRowSpan = 2 , but this property exists only in parent class - GridViewColumn .我需要使用ColRowSpan = 2添加 Bands(类GridViewBands ),但此属性仅存在于父类 - GridViewColumn中。 GridViewColumn has property ColRowSpan , but it is declared as "protected internal". GridViewColumn具有属性ColRowSpan ,但它被声明为“受保护的内部”。 Also, I tried to access it during debug - it works!此外,我尝试在调试期间访问它 - 它有效! But in the code I got exception.但是在代码中我遇到了异常。

Please, let me know does any method exist to access and change this property?请让我知道是否有任何方法可以访问和更改此属性?

在此处输入图像描述

I found the solution.我找到了解决方案。 It needs to use Reflection in this case.在这种情况下,它需要使用反射。 The code will be like this:<b代码将是这样的:<b

var gridViewColumnType = typeof(GridViewColumn);
var cellRowSpanProperty = gridViewColumnType.GetProperty("CellRowSpan", BindingFlags.Instance | BindingFlags.NonPublic);
cellRowSpanProperty.SetValue(bandcolumn, 2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM