While deserializing how do I check whether a name is available in the deserialized info?
This is usually an issue when a newer version introduces newer names, then the older version will not serialize property due to the absence of certain names. For example, this code will fail, sometimes: protected MyClassConstructor(SerializationInfo info, StreamingContext context) { ... // This might fail if MyProp was added in a newer version and you are serializing an older version. this.MyProp = info.GetBoolean('MyProp'); } To avoid such conflicts, you could insert version nos. into the serialized info. and during deserialization check for a name only when a particular version is being deserialized. Or you could instead parse through the available info in the SerializationInfo list as follows: [C#] protected MyClassConstructor(SerializationInfo info, StreamingContext context) { foreach(SerializationEntry entry in info) { switch(entry.Name) { case 'MyProp': // This will make sure that older versions without the MyProp name will also deserialize without any problems this.MyProp = (bool)entry.Value; break; ... } } } [VB.Net] Protected MyClassConstructor(ByVal info As SerializationInfo, ByVal context As StreamingContext) As Protected Dim entry As SerializationEntry For Each entry In info Select Case entry.Name Case 'MyProp' ’ This will make sure that older versions without the MyProp name will also deserialize without any problems Me.MyProp = (Boolean)entry.Value Exit For End Select Next End Function
How can I instruct the compiler to use the Main method in Class2 instead of Class1?
In the project’s General Properties, specify Class2 as the ‘Startup Object’. The dropdown contains all classes with a Main method specified.
How can I paint a representation of enum values using a UITypeEditor?
The following HatchStyleEditor class draws a graphical representation for values in the HatchStyle enumeration. HatchStyleEditor is derived from UITypeEditor and overrides the GetPaintValueSupported method and returns true. GetPaintValueSupported indicates that this editor supports the painting of a representation of an object’s value. PaintValue paints the representative value to the canvas. public class HatchStyleEditor : UITypeEditor { public override bool GetPaintValueSupported(ITypeDescriptorContext context) { return true; } public override void PaintValue(PaintValueEventArgs e) { if (e.Value is HatchStyle) { HatchStyle hatch = (HatchStyle) e.Value; Brush br = new HatchBrush(hatch, SystemColors.WindowText, SystemColors.Window); e.Graphics.FillRectangle(br, e.Bounds); br.Dispose(); } } }
At designtime, how can I hide a base class property in my derived control from the user
Set the Browsable attribute on the new property that hides the existing one. Here is a code snippet that hides the WordWrap property in the derived TextBox. [C#] public class MyTextBox : TextBox { [Browsable(false)] public new bool WordWrap { get{ return false;} //always false set{} } } [VB.NET] Public Class MyTextBox Inherits TextBox <Browsable(False)> _ Public Shadows Property WordWrap() As Boolean Get Return False ’always false End Get Set ’empty End Set End Property End Class ’MyTextBox
How do I implement a custom designer
Here are a couple of articles that discuss custom designers. Shawn Burke, in his article Wrinting Custom Designers for .NET Components at msdn. Brian Pepin, in his article .NET Shape Library: A Sample Designer at gotnetdot.com.