gpt4 book ai didi

c# - 条件 "Browsable"属性

转载 作者:可可西里 更新时间:2023-11-01 02:59:21 35 4
gpt4 key购买 nike


有没有一种方法可以使“可浏览”属性成为条件属性,以便应用它的属性有时会出现在属性页面中,有时不会出现?
谢谢:)

最佳答案

我不确定这是否适用于您的情况,但您可以通过调用以下函数在运行时调整“可浏览”装饰。

/// <summary>
/// Set the Browsable property.
/// NOTE: Be sure to decorate the property with [Browsable(true)]
/// </summary>
/// <param name="PropertyName">Name of the variable</param>
/// <param name="bIsBrowsable">Browsable Value</param>
private void setBrowsableProperty(string strPropertyName, bool bIsBrowsable)
{
// Get the Descriptor's Properties
PropertyDescriptor theDescriptor = TypeDescriptor.GetProperties(this.GetType())[strPropertyName];

// Get the Descriptor's "Browsable" Attribute
BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)theDescriptor.Attributes[typeof(BrowsableAttribute)];
FieldInfo isBrowsable = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);

// Set the Descriptor's "Browsable" Attribute
isBrowsable.SetValue(theDescriptorBrowsableAttribute, bIsBrowsable);
}

关于c# - 条件 "Browsable"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4690481/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com