InstanceDescriptor problem rendering Nullable<double> constructor parameters

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have a class like so:

public class MyClass
{
public MyClass(double? x, double? y)
{
}
}

I have created a type converter for this class that converts MyClass to an
InstanceDescriptor which renders a line of code like the following on a form
when x and y are null:

this.myComponent1.MyClassInstance = new MyClass(null, null);

The designer deserialization mechanism in Visual Studio is able to correctly
determine which constructor must be called on the MyClass class when
entering design mode.

However, if x and y are not null, and happen to have no decimal, the
following line of code is rendered:

this.myComponent1.MyClassInstance = new MyClass(2, 1);

This causes an exception when the form is designed with an error about a
constructor with Int32, Int32 signature not being found. It appears as
though there is no implicit conversion (for some reason) from Int32 to
Nullable<Double>.

So far I have not been able to find a way to cause the InstanceDescriptor to
render an explicit cast statement (double?) to ensure the constructor is
called successfully.

Has anyone experienced this problem before, and if so, how did you solve it?

Thanks.

-- Nathan


.



Relevant Pages

  • InstanceDescriptor problem rendering Nullable constructor parameters
    ... public class MyClass ... I have created a type converter for this class that converts MyClass to an ... constructor with Int32, ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: Backward compatibility issue of Serialization
    ... Don't change MyClass at all, instead derive a new type from MyClass and use ... > I'm planning to use serialization to persist an object in my application. ... > public class MyClass ... > private int oldField1; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: make a class sortable
    ... public MyClass(string className, string classType) ... public static int CompareByClassNameAsc(MyClass a, ... public class MyClass: IComparable ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: make a class sortable
    ... public MyClass(string className, string classType) ... public static int CompareByClassNameAsc(MyClass a, ... public class MyClass: IComparable ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is it possible to have parameters in a property?
    ... possible to expose its elements with "array-like" syntax through a ... public class MyClass ... MyClass myClass = new MyClass; ... to pass the index and value as parameters rather than using array-like ...
    (microsoft.public.dotnet.languages.csharp)