I have a list with this structure called InputText
:
Which I try to go through with this code:
public void MoveTo <T> ( Page pag , Object obj)
{
var InputText = pag.ChildControls().OfType<T>().ToList();//.AsQueryable().Select("new(ID, SelectedValue)");
var _r = InputText.AsQueryable().OrderBy("ID").Select("new(ID)").GetEnumerator();
var queryable = InputText.AsQueryable();//.AsEnumerable();
try
{
foreach (var list in InputText)
{
try
{
var prop = InputText.First().GetType().GetProperty("ID", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
var reti = queryable.Select(p => prop.GetValue(p).ToString()).Distinct().OrderBy(x => x).ToList();
}
catch (Exception ex) { }
try
{
/* PropertyInfo property = obj.GetType().GetProperty(list.ID.ToString().TrimStart(new char[] { 'v', 'f' }));
Type t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
object safeValue = (value == null) ? null : Convert.ChangeType(value, t);
property.SetValue(obj, safeValue, null);*/
}
catch (Exception ex) { }
}
}
catch (Exception es) { }
}
How can I get each value separately?
Well, so far I've tried with:
- LinQ
- Reflection.
When I try to go through the list, I try to retrieve the value of the property name
.
And I get this error:
I can not use LinQ, because apparently my list is not type IEnumerable
, I tried the cast but I have not achieved it.
This is the code that generates my list, basically I go through a page asp
, to recover all the DropDownList
and it returns them in a list:
public static IEnumerable<Control> MyChildControls(this Control control, Func<Control, bool> selector)
{
var stack = new Stack<IEnumerator<Control>>();
stack.Push(control.Controls.OfType<Control>().Where(c => selector(c)).GetEnumerator());
while (stack.Count > 0)
{
var en = stack.Peek();
if (en.MoveNext())
{
var item = en.Current;
yield return item;
if (item.HasControls())
{
stack.Push(item.Controls.OfType<Control>().Where(c => selector(c)).GetEnumerator());
}
}
else
{
stack.Pop();
}
}
}
The latest version of my code got me close enough. However, I would need to recover a ID
in each interaction of foreach
.