Tag: typedescriptor

是否有可能在.Net的编译时有条件地隐藏属性?

根据预处理程序指令,我想将类中的所有属性设置为EditorBrowsableAttribute.Never。 我考虑过创建一个从EditorBrowsableAttribute派生的自定义属性,但遗憾的是该类是密封的。 我已经看过ICustomTypeDescriptor,但在GetProperties方法中,我可以获取每个属性描述符,但属性集合是readonly。 有任何想法吗?

TypeDescriptor.GetConverter()不会返回我的转换器

我有一个简单的类型与自定义类型转换器,在运行时编译和加载。 但是,TypeDescriptor.GetConverter()找不到合适的转换器。 这是一个独立的例子 using System; using System.ComponentModel; using System.Collections.Generic; using System.CodeDom.Compiler; using Microsoft.CSharp; public class Program { private static string src = @” using System; using System.ComponentModel; namespace LoadMe { [TypeConverter(typeof(FooConverter))] public class Foo { } public class FooConverter : TypeConverter { // stuff } } “; public static void Main() { var codeProvider = […]

TypeDescriptor不会从inheritance的接口返回成员

我的问题是TypeDescriptor不会从inheritance的接口返回成员,这是它应该如何工作? 还是一个bug? [TestFixture] public class DescriptorTests { [Test] public void Test() { // count = 1 Assert.AreEqual(2, TypeDescriptor.GetProperties(typeof(IFoo)).Count); // it is going to fail, the Id is not going to be returned } public interface IEntity { int Id { get; set; } } public interface IFoo : IEntity { string Name { get; set; […]

在Silverlight中从字符串转换为数据?

基本上我正在尝试这样做: Path path = new Path( ); string sData = “M 250,40 L200,20 L200,60 Z”; var converter = TypeDescriptor.GetConverter( typeof( Geometry ) ); path.Data = ( Geometry )converter.ConvertFrom( sData ); 但它不会编译,Silverlight似乎没有TypeDescriptor类…

以编程方式将属性添加到方法或参数

我可以使用TypeDescriptor.AddAttributes在运行时向属性添加属性。 如何为方法和参数执行相同操作? (也许是2个单独的问题……)

TypeDescriptor.GetProperties()vs Type.GetProperties()

请考虑以下代码。 Object obj; PropertyDescriptorCollection A = TypeDescriptor.GetProperties(obj); PropertyInfo[] B = obj.GetType().GetProperties(); // EDIT* 我试图理解A和B之间的区别。据我所知, TypeDescriptor.GetProperties()将返回自定义的TypeDescriptor属性,其中Type.GetProperties()只返回对象的内在“真实”属性。 这是正确的吗? 如果obj没有任何自定义的TypeDescriptor属性,那么它只是默认返回对象的文字内在属性。 * EDIT之前的第二行代码(返回值错误): PropertyDescriptorCollection B = obj.GetType()。GetProperties();

如何在运行时将属性级属性添加到TypeDescriptor?

我想为对象的属性添加一些自定义的以PropertyGrid为中心的属性,以提供更丰富的编辑,隐藏一些值并将它们分类,因为我正在使用的那个类不提供这样的function而且我什么也做不了关于它。 实际上,它是MS的应用程序设置生成代码,因此您无法以任何方式扩展它的属性。 请参阅我的另一个问题: 运行时AppSettings.settings编辑器对话框