/// <summary> /// it is used to convert variableModel to list of entityDef dynamic object . /// </summary> /// <typeparam name="T">is entityDef class generated by engine.</typeparam> public static List <T> ConvertToList <T>(VariableModel variableModel) { if (variableModel == null) { return(default(List <T>)); } List <T> list = new List <T>(); foreach (var varModel in variableModel.Items) { foreach (var item in varModel.ToList()) { var instance = Activator.CreateInstance(typeof(T)); if (instance.GetType().GetProperty(item.Key) != null) { instance.GetType().GetProperty(item.Key).SetValue(instance, item.Value); } list.Add((T)instance); } } return(list); }
/// <summary> /// it is used to convert variableModel to entityDef dynamic object . /// </summary> /// <typeparam name="T">is entityDef class generated by engine.</typeparam> public static T ConvertTo <T>(VariableModel variableModel) { var instance = Activator.CreateInstance(typeof(T)); if (variableModel == null) { return(default(T)); } //set the name of variable instance.GetType().GetProperty("VariableName").SetValue(instance, variableModel.Name); //set the values of variables if (variableModel.Items?.Any() == true) { foreach (var item in variableModel.Items.FirstOrDefault().ToList()) { if (instance.GetType().GetProperty(item.Key) != null) { instance.GetType().GetProperty(item.Key).SetValue(instance, item.Value); } } } return((T)instance); }