• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1185
  • Last Modified:

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
0
saktiranjan
Asked:
saktiranjan
  • 3
  • 3
1 Solution
 
Bob LearnedCommented:
Huh?  I don't understand your requirement.

Bob
0
 
saktiranjanAuthor Commented:
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
0
 
Bob LearnedCommented:
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
saktiranjanAuthor Commented:
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.
0
 
Bob LearnedCommented:
Why not?  I don't see any problem with a base class for each TypeConverter, for the common things, and then a deriving class for the return values.

Bob
0
 
saktiranjanAuthor Commented:
I struggled a lot but did not find any other solution except this, though I am not totally convinced.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now