West Wind .NET Tools and Demos
wwDotnetBridge: Access
Gravatar is a globally recognized avatar based on your email address. wwDotnetBridge: Access
  Manni Borg
  All
  May 25, 2022 @ 06:56am

Hi Rick,

using wwDotnetBridge I'm trying to access a method from an assembly created in C# and have trouble accessing an object inside an object (if that makes sense).

How can I access the List UserEntries in the following example:

VFP-Code:

loBridge.LoadAssembly("Com.dll")
com = loBridge.CreateInstance("Com.Operations")

oUserList = loBridge.CreateInstance("Com.UserList")
oUserList = com.COM_GetUserList(myform.HwNd)

It works, as far as I can access the property UserListComplete, so

? oUserList.UserListComplete && yields .T.

but the List UserEntries cannot be accessed:

? oUserList.UserEntries  && cannot be accessed

Here's the C# code:

public UserList COM_GetUserList(int windowHandle)
{
    UserList list;

...

    return list;
}
public class UserList
{
    // Methods
    public UserList();
    internal UserList(List<UserEntry> entries, bool listComplete, IReadOnlyList<SOAPErrorTrace> errorTraces);

    // Properties
    public IReadOnlyList<UserEntry> UserEntries { get; private set; }
    public IReadOnlyList<SOAPErrorTrace> ErrorEntries { get; private set; }
    public bool UserListComplete { get; private set; }
}
public class UserEntry
{
    // Methods
    public UserEntry(GetUserListResponseUserEntry entry);

    // Properties
    public string NR { get; private set; }
    public string ID { get; private set; }
    public DateTime ValidTo { get; private set; }
}

How can I access the IReadOnlyList UserEntry? So for example for the first entry in the list, I would like to get the NR, IR and DateTime.

Thanks, Manni

Gravatar is a globally recognized avatar based on your email address. re: wwDotnetBridge: Access
  Manni Borg
  Manni Borg
  May 25, 2022 @ 10:45am

Update:

Fortunately, I was able to solve the problem using GetProperty() to get to the nested properties:

oUserList = loBridge.InvokeMethod(com,"COM_GetUserList", myform.HWND)
cUserListComplete = loBridge.GetProperty(oUserList, "UserListComplete")
oUserEntries = loBridge.GetProperty(oUserList, "UserEntries[0]")
cUserEntryNR = oUserEntries.NR
cUserEntryID = oUserEntries.ID
dtUserEntryValidTo = oUserEntries.ValidTo

"UserEntries[0]" instead of just "UserEntries" was the solution.

Thanks, Manni

Gravatar is a globally recognized avatar based on your email address. re: wwDotnetBridge: Access
  Rick Strahl
  Manni Borg
  May 25, 2022 @ 02:25pm

Direct access doesn't work because generic types (ie Class<TType>) can't be accessed via COM directly as they are virtual types created at runtime. This is what GetProperty() and GetProperty() are there for, to allow retrieving these values and them making them available to FoxPro in a way that can be accessed through the COM interface.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwDotnetBridge: Access
  Manni Borg
  Rick Strahl
  May 25, 2022 @ 02:50pm

Thank you for the explanation, Rick!

© 1996-2022