Skip to content

Generics

roy roy

Asked Dec 21, 2008, 6:15 PM EST3 answers
Share
LinkedInX

Hello.

Your help is very much appreciated.

I created a class (parametersBusinessObject) with a Generic type. This class basically represents a  parameter.

The memebers :

string paramName,

<T> defaultValue,

bool isRequired

 

Then, I tried to use another class(wctl) which contains a list of the parameters.

List< parametersBusinessObject >.

The problem is that I don’t see how I can populate the list with parametersBusinessObject that have a different type. i.e. how would you populate the list with:

“param1”,string, true

“param1”,int, true   ??

 

C#
public class wctl<T> : WebControl
    {
        public class parametersBusinessObject
        {
            string _paramName;
            bool _isRequired;
            T _defaultValue;

            public parametersBusinessObject(string paramName, bool isRequired,T defaultValue)
            {
                _paramName = paramName;
                _isRequired = isRequired;
                _defaultValue = defaultValue;
            }
            public string ParamName
            {
                get { return _paramName; }
            }
            public bool IsRequired
            {
                get { return _isRequired; }
            }
            public T DefaultValue
            {
                get { return _defaultValue; }
            }
        }

        private List<parametersBusinessObject> _prms;

        public List<parametersBusinessObject> Prms
        {
            get { return _prms; }
            set { _prms = value; }
        }

 

Thank you,

Roy

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    The default type will reset the generic type and you can implement a method within your class to reset the generic type , if I well understand your issue
    0
  • 0

    Thank you Bechir.
    The issue is to populate a list of objects (type of Generics) wherease T is different for each item in the list.
    I realized that it is not possible. So instead of using generics I will just use Type.

    Thanks again.

    Regrdas

    Roy

    0
  • 1 short reply
    • Bechir Bejaoui
      0
      Ok then
      0