do wwDotNetBridge LOCAL loBridge as wwDotNetBridge loBridge = CreateObject("wwDotNetBridge") *** Load your .NET assembly loBridge.LoadAssembly(FULLPATH("ContactManager.dll")) *** Create the top level .NET object loContactManager = loBridge.CreateInstance("MyApp.ContactManager") *** Create an empty array of MyApp.Contact items loContacts = loBridge.CreateComArray("MyApp.Contact") *** Create a Contact instance * loContact = loBridge.CreateInstance("MyApp.Contact") *** Easier way to create a contact object from the array *** since it knows what our base type is loContact = loContacts.CreateItem() loContact.Name = "Rick" loContact.Entered = DATETIME() *** Add first contact loContacts.Add(loContact) loContact = loContacts.CreateItem() && get a Contact object of type MyApp.Contact loContact.Name = "Jim" loContact.Entered = DATETIME() *** Add Second contact loContacts.Add(loContact) *** Call AddContacts(Contacts[] contacts,DateTime enteredOn) *** InvokeMethod is required to properly pass the loContact array as a .NET array loBridge.InvokeMethod(loContactManager,"AddContacts",loContacts,DATETIME()) *** You can still call most methods direct just like with plain COM Interop loContactManager.Close()(note this is off the cuff so there might be minor errors here but it gives you the idea)
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); >>>> } >>>> }