Link to home
Start Free TrialLog in
Avatar of saktiranjan
saktiranjan

asked on

Using TypeConverter for Parameterized Constructor Class

Hi,
Can somebody help to know how to use a class having parameterized constructor inherted from typeconverter in the property grid. That means how can I pass parameters to constructor while defining property. Below is the code for your reference.

I have a custom pipeline component and I am adding three custom properties to input columns. Different properties will have different static values. So I have developed a class inherting from Type Converter.

public class BooleanList : TypeConverter
{
    //public BooleanList(string displayValues)
    //{
    //    if (displayValues.ToLower() == "boolean")
    //    {
    //        m_list.Add("Y");
    //        m_list.Add("N");
    //    }
    //   else if (displayValues.ToLower() == "datatypes")
    //    {
    //        m_list.Add("String");
    //        m_list.Add("Numeric");
    //        m_list.Add("DateTime");
    //    }
    //}

    public BooleanList()
    {
        m_list.Add("Y");
        m_list.Add("N");
    }
    public List<string> m_list = new List<string>();

    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
        return true;
    }
    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    {
        return true;
    }
    public StandardValuesCollection GetValues()
    {
        return new StandardValuesCollection(m_list);
    }
    protected void SetList(List<string> list)
    {
        m_list = list;
    }
    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
        return GetValues();
    }
}

The defined property will use the above class and the property will have static values (Y & N) as coded below.
propCheckNull.TypeConverter = typeof(BooleanList);
Now look at the commented part in above class. I want to use this parameterized constructor and want to send parameters while assigning to property values so that I will get static values as per the parameter. Instead of typeof(BooleanList), want to write something else where I can pass parameters.

Let me know if something is unclear.

Thanks
Sakti
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Huh?  I don't understand your requirement.

Bob
Avatar of saktiranjan
saktiranjan

ASKER

OK... let me explain little more. The full code which I have posted, is a class which creates a list of values. And if you use this class in a custom property like below, you will get property values in the property grid as dropdown list.
[TypeConverter(typeof(DefineProperty))]
        public string SourceConnection
        {
            get { return this.strConnection; }
            set { strConnection = value; }
        }

In my case I am using this [TypeConverter(typeof(DefineProperty))] in a input column of data flow pipeline component in ssis as
propCheckNull.TypeConverter = typeof(BooleanList); where propCheckNull is a custom property.
Now, Can I use the same class for loading different static values in the property? If I can pass parameter to the constructor, different values can be loaded as per the parameter. But how to write that, I dont know.

Let me know if you need something specific.

Sakti
Does that mean that you want to use a single TypeConverter to return different values depending on how it is used?  What value would this have versus having 2 different TypeConverter classes?

Bob
I am expecting more than 10 values to be returned on 10 different situation. For each thing, its not good idea to write those many TypeConverter classes.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I struggled a lot but did not find any other solution except this, though I am not totally convinced.