gpt4 book ai didi

c# - 如何获取当前属性的 PropertyDescriptor?

转载 作者:可可西里 更新时间:2023-11-01 08:33:44 25 4
gpt4 key购买 nike

如何获取当前属性的 PropertyDescriptor?例如:

[MyAttribute("SomeText")]
public string MyProperty
{
get{....}
set
{
// here I want to get PropertyDescriptor for this property.
}
}

最佳答案

你可以试试这个:


public string Test
{
get
{
//Get properties for this
System.ComponentModel.PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties( this );

//Get property descriptor for current property
System.ComponentModel.PropertyDescriptor pd = pdc[ System.Reflection.MethodBase.GetCurrentMethod().Name ];
}
}

关于c# - 如何获取当前属性的 PropertyDescriptor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4722876/

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