well that does indeed set the title nicely,
however I doscovered you cant put template parameter inside attributes,
so this didnt work :-
public class UListWrap<T>
{
[Editor(typeof(U CollectionEdito r<T>), typeof(UITypeEd itor))]
// ^-- error CS0416:
// 'type parameter': an attribute argument cannot use type parameters
public class UDescWrap : CustomTypeDescr iptor
{
UColection<Tdat a;
... GetProperties() etc ...
}
}
I cant avoid the generic becuase i cant see any other way of getting
the type name at the time CreateCollectio nForm is called.
also the type of the object still apears as the typename of the wrapped
object
wich would be something like "UWrap'1"
oh and I also have to generate the generic type in reflection
(wich ive manged to do ok)
so i have no clue what T might be at run time.
I dont need to use any of this for simple types like int anyway,
but some of the items in some lists need to be able to get
the list of properties from the class that contains the list.
im thinking instead of using my own wrapper that I could use
typedescriptorp rovider for each object in the list
isntead of aplying it to a type, wich aplies to al objects of that type.
interestingly i was looking at the arraycolectione ditor in reflector
and it uses a fairly simple wrapper like mine.
its just the type name that apears obscure thats driving me mad
and thats only in the pop up colection editor,
the rest works ok, am I just being too pedantic ?
many thanks again
Colin =^.^=
ps if i ever get this sorted il post the complete solution
somewhere like code project ...
"Marc Gravell" <ma**********@g mail.comwrote in message
news:ez******** ******@TK2MSFTN GP04.phx.gbl...
Well, the following shows a way to customise the title (there may be
simpler ways, but I can't see them). Obviously you'd need to put some
different code in around ".Text = " to put in some code (presumably using
reflection and GetGenericTypeD efinition() etc) to put in a more useful
name...
using System;
using System.Collecti ons.ObjectModel ;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Drawing. Design;
using System.Windows. Forms;
class CollectionEdito r<T: CollectionEdito r
{
protected override CollectionForm CreateCollectio nForm()
{
CollectionForm form = base.CreateColl ectionForm();
form.Text = "Here be thee " + typeof(T).Name + "s";
return form;
}
public CollectionEdito r() : base(typeof(T)) {}
}
class Foo
{
[Editor(typeof(C ollectionEditor <Bar>), typeof(UITypeEd itor))]
public Collection<BarB ars { get; private set; }
public Foo() {Bars = new Collection<Bar> ();}
}
class Bar
{
public string Name { get; set; }
public int Age { get; set; }
}
static class Program
{
[STAThread]
static void Main()
{
Application.Ena bleVisualStyles ();
Application.Run (new Form
{
Controls = {
new PropertyGrid {
Dock = DockStyle.Fill,
SelectedObject = new Foo()
}
}
});
}
}