ExapndableObjectConvert.CreateInstance method is ignored


A

Andrew2

I'.m trying to use an ExapndableObjectConvert, but despite I'm able to
show the correct string into the property grid, and convert to and
from my specific class, the whole process doesn't work unitl I don't
create a private new instance of my return type class in the
WebControl object and use that as set/get variable property like the
small part of code reported below.


private EmployeeInfoClass empInfo = new EmployeeInfoClass();

public EmployeeInfoClass EmployeeInfo
{
get { return empInfo; }
set { empInfo = value; }
}

[TypeConverter(typeof(EmployeeConverter))]
public class EmployeeInfoClass
{
....
}


I noticed that the ExpandableObjectConvert offer an
GetCreateInstanceSupported and a CreateInstance methods that should
act in place of the private instantiation, but while the
GetCreateInstanceSupported is called, the CreateInstance method is
completely ignored.


public class EmployeeConverter : ExpandableObjectConverter //
TypeConverter
{
public override bool
GetCreateInstanceSupported(ITypeDescriptorContext context)
{
// Always force a new instance
return true;
}

public override object CreateInstance(ITypeDescriptorContext
context, IDictionary propertyValues)
{
// Use the dictionary to create a new instance
return new
EmployeeInfoClass((int)propertyValues["EmployeeID"],
(string)propertyValues["FirstName"],
(string)propertyValues["LastName"]);
}


Where am I doing mistakes?

Thanks
Andrea
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top