IExtenderProvider and Design Time Attributes

How do I apply design time attributes to my IExtenderProvider class's properties that it's providing? Do I put the attributes on the Get or Set method, or is there another way? I have an IExtenderProvider that provides a property thats a collection. I want to apply the DesignerSerializationVisibility.Content attribute to the property, but there is no property for me to apply it to.

Thanks,
Paul Tyng

[410 byte] By [codefund.com] at [2008-2-20]
# 1
I figured I should actually provide some context for this:

I have a component that implements IExtenderProvider, DataBinder, that provides a "Bindings" property on controls in a form. It initially was designed to only handle one field to property mapping. Of course as soon as I designed it that way it need to handed multiple field to property mappings. A typical collection property built in to the framework renders in the control as and AddRange statement. But since my provided property is not really a property at all but just a get and set method on my DataBinder object I'm not sure exactly how to handle the objects to make the designer function properly for it. Currently it just sets the property to nothing. The collection editor shows up in the designer ui properly and allows me to create my bindings, which also show up in the designer ui properly. The bindings are even written in to the designer code region and their properties set. They are just not added to my collection. I'm not sure exactly how to handle this because every sample, example, howto or post I can find regarding collection properties is only about normal properties, not provided properties.

Paul Tyng

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 2
I haven't tried this, so we may not have a good provision for it, but you should be able to do this:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyCollection GetBindings(Control control)
{
}

Applogies in advance for the horrible name for the attribute.

Assuming we handle this case in the serializer, this should yield the following code in InitializeComponent:

myDataThingy.GetBindings(control1).AddRange(new Binding[] {...});

If it doesn't, let us know and we'll investigate more drastic measures. Worst case, you can replace the serializer for your object. But I like to treat that as a last ditch effort because writing your own serializer is, well, non-trivial.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 3
I haven't tried the IExtenderProvider interface in c# but in vb you do not actually define a property. You add an attributed called provided property, so there is no property for me to put the attribute on. The code looks something like this:

<ProvideProperty("SomeProperty", GetType(Control))> _
Public Class Extender
Inherits Component
Implements IExtenderProvider

Public Function CanExtend(ByVal extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
Return TypeOf extendee Is TextBox
End Function

'this is the property get
Public Function GetSomeProperty(ByVal ctrl as Control) as String
End Function

'this is the property set
Public Sub SetSomeProperty(ByVal ctrl as Control, ByVal value as String)
End Sub

End Class

In the designer generated code you get something to this effect:

Me.Extender1.SetSomeProperty(Me.TextBox1, "TheValue")

So since its a sub that it is calling in the designer generated code it does not have access to the add range method.

Any other ideas? How would I write my own serializer (I would like to know this regardless :) )

Thanks,

Paul Tyng

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 4
Just a note, I currently have it implemented just as a String property with delims that I parse out (its a hack, but I don't have to deal with all this stuff right now at least). Basically props comma delimited and rows semi-colon delimited and I parse it out in to a collection of my type internally.

Paul Tyng

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 5
In my C# code above that's a method, not a property. You can put design time attributes on the Get method of an extended property. So, in VB:

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Fuction GetSomeProperty(c As Control) As SomeDataType
End Function

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 6
Sorry I mean that since its not a property the designer code cannot use AddRange. I did try that extended proeprty though and it does not work, all it passes to my function is nothing. Another thing I realized is that since it is using AddRange for those other properties that means the collection is already instantiated internally in the control so that addrange actually works. I'm not sure how I would get a collection my object creates out to the designer to get the addrange working.

Paul

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 7
I've added good example of an advanced IExtenderProvider to my blog.

See http://www.nootz.net

Garick

Garick at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Designer...