的PropertyDescriptor [英] PropertyDescriptor

查看:79
本文介绍了的PropertyDescriptor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写了一个自定义的PropertyDescriptor,让我在属性编辑器中编辑我的

自定义数据项,

但我现在希望扩展它以便可以使用

使用属性编辑器附带的集合

编辑器编辑此类数据项的嵌套集合。

[TypeConverter(typeof(ExpandableObjectConverter))]

公共类MyClassDescriptor:PropertyDescriptor,ICustomTypeDescriptor

{

object Object;

getvalue,setvalue,propertycollection等...

}


propertyGrid.SelectedObject = new MyClassDescriptor(obj);


不久前我写了这篇文章,并花了一段时间

来弄清楚它是如何工作的大声笑lol

但我似乎无法取得任何进展

将其扩展到收藏品。

我真的不想转换< myclassto收藏品的收藏品

< MyClassDescriptorwich是我到目前为止唯一想到的方法。


我需要编辑的大多数数据都是结构数据字段的形式或

包含在自定义字段名称,对象字典


非常感谢

Colin = ^。^ =

Hi,
Ive written a custom PropertyDescriptor wich lets me edit my
custom data items in the property editor,
however I now wish to expand it so that it can be used
to edit nested collections of such data items with the collection
editor that comes with the property editor.
[TypeConverter(typeof(ExpandableObjectConverter))]
public class MyClassDescriptor : PropertyDescriptor, ICustomTypeDescriptor
{
object Object;
getvalue,setvalue,propertycollection etc ...
}

propertyGrid.SelectedObject = new MyClassDescriptor (obj);

It was a while ago I wrote this, and taken me a while
to figure out how it worked again lol
but I cant seem to make any progress
on expanding it to collections.
I dont realy want to convert the collections of <myclassto collections of
<MyClassDescriptorwich is the only way ive thought of so far.

most of the data I need to edit is in the form of struct data fields or
contained in a dictionary of custom field names,objects

many thanks
Colin =^.^=

推荐答案

好的,我对设置感到困惑;通常一个类型使用

ICustomTypeDescriptor来提供动态属性支持等(对于

这样的东西,如数据绑定);并且类型或属性标有

[TypeConverter]来自定义转换(字符串序列化等)和

PropertyGrid行为。很难看到PropertyDescriptor

*本身*标有[TypeConverter]。


我希望你仍然可以自动获得收藏支持 -

就像列表编辑器通常如何工作一样。但是,如果你想改变现有类型的元数据,你仍然可以使用

类似TypeDescriptionProvider的东西。但是,这不是一件容易的事,也不容易在短篇文章中总结。


所以;你能详细介绍一下你想做什么吗?


Marc
OK, I''m a little confused with the setup; normally a type uses
ICustomTypeDescriptor to provide dynamic property support etc (for
things like data-binding); and a type or property is marked with
[TypeConverter] to customise conversion (string serialization etc) and
PropertyGrid behavior. It is unusual to see a PropertyDescriptor
*itself* marked with [TypeConverter].

I would expect you to still get collection support automatically -
like how the list editors generally work. However, if you want to
change the metadata of existing types, you can still do it - by using
things like TypeDescriptionProvider. However, this is not trivial nor
easy to summarise in a short post.

So; can you give a bit more detail on what you want this to do?

Marc


" Marc Gravell" < ma ********** @ gmail.comwrote in message

news:22 ******************** ************** @ 34g2000h sh.googlegroups.com ...
"Marc Gravell" <ma**********@gmail.comwrote in message
news:22**********************************@34g2000h sh.googlegroups.com...

好​​的,我有点困惑建立;通常一个类型使用

ICustomTypeDescriptor来提供动态属性支持等(对于

这样的东西,如数据绑定);并且类型或属性标有

[TypeConverter]来自定义转换(字符串序列化等)和

PropertyGrid行为。很难看到PropertyDescriptor

*本身*标有[TypeConverter]。


我希望你仍然可以自动获得收藏支持 -

就像列表编辑器通常如何工作一样。但是,如果你想改变现有类型的元数据,你仍然可以使用

类似TypeDescriptionProvider的东西。但是,这不是一件容易的事,也不容易在短篇文章中总结。


所以;你能详细介绍一下你想要做什么吗?


Marc
OK, I''m a little confused with the setup; normally a type uses
ICustomTypeDescriptor to provide dynamic property support etc (for
things like data-binding); and a type or property is marked with
[TypeConverter] to customise conversion (string serialization etc) and
PropertyGrid behavior. It is unusual to see a PropertyDescriptor
*itself* marked with [TypeConverter].

I would expect you to still get collection support automatically -
like how the list editors generally work. However, if you want to
change the metadata of existing types, you can still do it - by using
things like TypeDescriptionProvider. However, this is not trivial nor
easy to summarise in a short post.

So; can you give a bit more detail on what you want this to do?

Marc



感谢它已经有一段时间了我写了,

我想你回复我的帖子当时询问它,

但是基本上我没有能力修改或添加

a typedescriptor收集的元素。


我使用你描述的外观,它似乎避免了需要

重复的代码

将TypeConverter与PropertyDescriptor结合起来。


我有一个以复杂方式从文件中读取的类,

还有一些自定义字段,它们也在文件中定义,

这些是通过字段字典来处理的。

字段类型也可以是文件中定义的类型。


我的属性描述符很好地处理这些字段,

以及一些简单的数据字段

但是对于集合属性编辑器

显示集合的内容,

但无法进一步扩展它们。


作为示例一个结构可能有自定义field bich

等于一个struct Vector数组(即3个浮点数x,y,z)


我的属性编辑器可以编辑Vector的值但是

只有当它是对象的字段或子字段时才是

如果它在一个集合中则不是。


我可能看看TypeDescriptionProvider,希望它可以做到它可以做所有工作的所有工作即使它有点复杂。


不幸的是很多财产袋我看过的课程看起来很好

复杂和

我需要修改很多才能添加我的自定义字段。

很难看到它的哪一部分参与了收藏

编辑。


非常感谢

Colin = ^。^ =

thanks it was a while since I wrote it,
I think you replied to my posts askign about it at the time,
however basically I dont have the ability to modify or add
a typedescriptor to the elements of the collections.

Im using what you described as a facade, and it seemed to avoid the need for
duplicate code
by combining the TypeConverter with the PropertyDescriptor.

I have a class wich is read from a file in a complicated fashion,
with some custom fields wich are also defined in the file,
these are handled by having a field dictionary.
the field types may also be types defined in the file.

my property descriptor nicely handles these fields,
and also some simple data fields
but for the collections the property editor
displays the contents of the collection,
but is unable to further expand them.

as an example one struct might have a custom field wich
equates to an array of struct Vector (ie 3 floats x,y,z)

my property editor can edit the values of the Vector but
only if it is a field or sub field of the object but
not if its in a collection.

I might look at TypeDescriptionProvider, hope it may be that it can do
all the work even if it is a bit more complicated.

unfortunatly a lot of the propertybag classes ive looked at seem quite
complicated and
I need to modify quite a lot to add my custom field stuff.
its hard to see what part of it is involved in the collection
editing.

many thanks
Colin =^.^=




我已经设法将集合编辑器设置为工作

,以便从提供给TypeDescriptor.AddProvider的

DescriptorProvidor中获取我的CustomTypeDescriptor。


我也设法解决了我之前的问题

有嵌套的struct字段而不必复制,

使用TypedReference和FeildInfo.SetValueDirect。


所以当弹出窗口时,列表会正确更新

集合编辑器,但是当列表显示为

时,我的TypeCOnverter就像expandableObjectConverter,

它似乎没有使用与弹出集合相同的代码

编辑器,因为数组没有更新。


我好像不能够找到我可以找到的地方

数组中的索引将数据复制回来。

我希望直接更新值而不是更新

a复制然后将副本复制回来。


谢谢

Colin = ^。^ =



&quo t; Marc Gravell < ma ********** @ gmail.comwrote in message

news:22 ******************** ************** @ 34g2000h sh.googlegroups.com ...
Hi,
wel ive managed to get the collection editor to work
so that it picks up my CustomTypeDescriptor from the
DescriptorProvidor supplied to TypeDescriptor.AddProvider.

Ive also managed to solve my problem I had before
with nested struct fields without having to do copy back,
using TypedReference, and FeildInfo.SetValueDirect.

so the list gets updated correctly whith the pop up
collection editor fine, but when the list is displayed with
my TypeCOnverter wich is like the expandableObjectConverter,
it doesnt seem to use the same code as the pop up collection
editor as the array does not get updated.

I dont seem to be able to find where I can pick up
the index into the array to copy the data back to.
I wish to update the values directly rather than updating
a copy then copying the copy back.

thanks
Colin =^.^=


"Marc Gravell" <ma**********@gmail.comwrote in message
news:22**********************************@34g2000h sh.googlegroups.com...

好​​的,我有点困惑建立;通常一个类型使用

ICustomTypeDescriptor来提供动态属性支持等(对于

这样的东西,如数据绑定);并且类型或属性标有

[TypeConverter]来自定义转换(字符串序列化等)和

PropertyGrid行为。很难看到PropertyDescriptor

*本身*标有[TypeConverter]。


我希望你仍然可以自动获得收藏支持 -

就像列表编辑器通常如何工作一样。但是,如果你想改变现有类型的元数据,你仍然可以使用

类似TypeDescriptionProvider的东西。但是,这不是一件容易的事,也不容易在短篇文章中总结。


所以;你能详细介绍一下你想做什么吗?


Marc
OK, I''m a little confused with the setup; normally a type uses
ICustomTypeDescriptor to provide dynamic property support etc (for
things like data-binding); and a type or property is marked with
[TypeConverter] to customise conversion (string serialization etc) and
PropertyGrid behavior. It is unusual to see a PropertyDescriptor
*itself* marked with [TypeConverter].

I would expect you to still get collection support automatically -
like how the list editors generally work. However, if you want to
change the metadata of existing types, you can still do it - by using
things like TypeDescriptionProvider. However, this is not trivial nor
easy to summarise in a short post.

So; can you give a bit more detail on what you want this to do?

Marc



这篇关于的PropertyDescriptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆