I need to use reflection to set two custom propertys of custom userControls
CustomUserControl.cs
......
public string _ValidaMsg { get { return _ValidarMsg; } set { _ValidarMsg = value; } }
public bool _Valida { get { return _Validar; } set { _Validar = value;} }
._Valida
determinates if the control needs to be validated before submitting the form and ._ValidaMsg
is the message it shows when the field isn't completed
In my form.cs I have a typed List called listaMetodo (String ControlName,String ControlText,Type Control.Type)
Here's the method where I fill my list
private List<xEntidades.entControlValidacion> GetAllControls(Control container)
{
foreach (Control c in container.Controls)
{
GetAllControls(c);
// these txtDescripcion and others are the diferent types of my customs UserControls
if (c.Name.Equals("txtDescripcion") || c.Name.Equals("Combo") || c.Name.Equals("txtCodigo") || c.Name.Equals("txtFecha"))
{
listaMetodo.Add(new xEntidades.entControlValidacion(c.Parent.Name, c.Text, c.GetType()));
}
}
return listaMetodo;
}
So once I have the list with all controls that are relevant, what I need to do is to compare it with another that I have, wich is filled with all the controls that needs to be validated, let's call it validateList(string NameOfControl,bool Valida , String ValidaMsg)
. In the for loop while im itherating the two list I have the condition
If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida){
//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida
}
So, how can I Modify the propertys of the instanced object using the Type and the ControlName Stored in my listaMetodo It's mandatory to use reflection? Is there another approatch to achieve what I wat to?
Thanks in Advance
Aucun commentaire:
Enregistrer un commentaire