[ComVisible(false)] public class MyDll { Dictionary<string, List<Contact>> lists = new Dictionary<string, List<Contact>>(); [ComVisible(true)] public void AddClientsToList(string xml, string listName) { List<Contact> c = Helper.RetrieveList<Contact>(xml); if (!lists.Keys.Contains(listName)) lists.Add(listName, c); else lists[listName] = c; } [ComVisible(true)] public string GetClientsList(string listName) { return Helper.ConvertToXML(lists[listName]); } }>FWIW, I tend to use generic serializers for this (a la SerializationUtils.SerializeObject(inst, instType) and SerializationUtils.DeserializeObject(inst,instType) which works across all serializable types.
public static class Helper >> { >> public static List<T> RetrieveList<T>(string s) >> { >> XmlSerializer xs = new XmlSerializer(typeof(List<T>)); >> System.Xml.XmlReader v = System.Xml.XmlReader.Create(new StringReader(s)); >> return (List<T>)xs.Deserialize(v); >> } >> >> public static string ConvertToXML<T>(List<T> list) >> { >> XmlSerializer xs = new XmlSerializer(typeof(List<T>)); >> StringWriter sw = new StringWriter(); >> xs.Serialize(sw, list); >> return sw.ToString(); >> } >> }Example use:
List<Contact> list = new List<Contact>(); >> list.Add(new Contact { Name = "Fred", Age = 33 }); >> list.Add(new Contact { Name = "Joe", Age = 66 }); >> >> string xmlString = Helper.ConvertToXML<Contact>(list); >> //(Examine this string to determine what VFP should create) >> >> List<Contact> retrievedList = Helper.RetrieveList<Contact>(xmlString);>>>Thanks for the tip. In the meantime, I've decided to switch to sending XML and convert that to a DataTable that I can iterate through. That seems to do the trick for now.
>>>>>public void AddClientsToList(Contact[] contacts, string listName) >>>>>>>>>>
public class MyDll >>>> { >>>> Dictionary<string, List<Contact>> lists = new Dictionary<string, List<Contact>>(); >>>> public Contact GetNewContact() { return new Contact();} >>>> >>>> public void AddClientToList(Contact contact,string listName) >>>> { >>>> if (!lists.Keys.Contains(listName)) >>>> lists.Add(listName, new List<Contact>()); >>>> lists[listName].Add(contact); >>>> } >>>> }