Setting enumerator using reflection

  • Thread starter Thread starter Paul
  • Start date Start date
P

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
 
Don't worry.

I have solved my own problem.

Simple is best :)

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