
@Bhupentiwari Sir,
You can use a Dictionary of type
string and Type like
private static Dictionary<string, Type> SetControlTypes()
{
var dicControlTypes = new Dictionary<string, Type>();
dicControlTypes.Add("TextBox", typeof(Panel));
dicControlTypes.Add("DateTimePicker", typeof(Panel));
dicControlTypes.Add("RadioButton", typeof(Panel));
dicControlTypes.Add("Panel", typeof(Panel));
dicControlTypes.Add("GroupBox", typeof(GroupBox));
return dicControlTypes;
}
and search by the
key(which is string) and return the Type . An example follows
using System;
using System.Collections.Generic;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(SearchControlTypes("GroupBox").SomeMethod());
Console.ReadKey();
}
private static dynamic SearchControlTypes(string key)
{
return Activator.CreateInstance(SetControlTypes()[key]) as dynamic;
}
private static Dictionary<String, Type> SetControlTypes()
{
var dicControlTypes = new Dictionary<string, Type>();
dicControlTypes.Add("TextBox", typeof(Panel));
dicControlTypes.Add("DateTimePicker", typeof(Panel));
dicControlTypes.Add("RadioButton", typeof(Panel));
dicControlTypes.Add("Panel", typeof(Panel));
dicControlTypes.Add("GroupBox", typeof(GroupBox));
return dicControlTypes;
}
}
internal class Panel
{
public int SomeMethod()
{
return 10;
}
}
internal class GroupBox
{
public int SomeMethod()
{
return 20;
}
}
}
So your implementation can be changed to
if (schemes != null && schemes.FormFieldslist.Count > 0)
{
GetAllFormControl(vForm, Controllist);
schemes.FormFieldslist.RemoveAll(x => !x.PresentInReport.Contains(vFormReport.ToString()));
foreach (Clipper.CFPS.BusinessEntities.CustomField cf in schemes.FormFieldslist)
{
dynamic T = SearchControlTypes(cf.ControlType);
..............
................
}
}
Hope that will help.
--
Thanks & Regards,
RNA Team
Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator