Home All Groups Group Topic Archive Search About

Setting enumerator using reflection

Author
12 Sep 2006 8:27 AM
Paul
Hi Guys.

I am loading an enumerator in a list box using reflection.
Using

        if (!this.IsPostBack)
        {
            ddlSource.Items.Clear();

            Type _enum = typeof(adTargetDataSource);

            FieldInfo[] _prop = _enum.GetFields();

            // We start at 1 here as we do not want the value__ field.
            for (int iLoop = 1; iLoop < _prop.Length; iLoop++)
            {
                ddlSource.Items.Add(_prop[iLoop].Name);
            }
        }

This is all fine.
However to make this workwhile I need to be able to pass back the
enumerator dynamically as well.

How do I do this. I have tried

            FieldInfo _fI =
typeof(adTargetDataSource).GetField(ddlSource.SelectedValue);

            adTargetDataSource _source = adTargetDataSource.database;

            _fI.SetValue(_source, _fI.Name);

It does not like this :)

Paul

Author
12 Sep 2006 8:45 AM
Paul
Don't worry.

I have solved my own problem.

Simple is best :)

            adTargetDataSource _source =
(adTargetDataSource)Enum.Parse(typeof(adTargetDataSource),
ddlSource.SelectedValue);

AddThis Social Bookmark Button