?Hi,
I'm working on C# bindings. The goal is to obtain a more C# API for the API users.
So I have create object for libvirt familly function (an object Connect, Domain, Storage
and so on).
All is almost done, but I need and advice about the way to handle object properties. For
example, for the Connect object, I expose a "RunningDomains" property that can
be used in this manner :
Connect myConn = new Connect("qemu+tcp://192.168.220.198/system");
List<Domain> runningDomains = myConn.RunningsDomains;
In the Connect object, the property "RunningDomains" is coded in this :
/// <summary>
/// Get the list of running domains
/// </summary>
public List<Domain> RunningDomains
{
get
{
if (_conn == IntPtr.Zero) return null;
int nbRunningDomain = NumOfDomains(_conn);
int[] runningDomainIds = new int[nbRunningDomain];
ListDomains(_conn, runningDomainIds, nbRunningDomain);
return runningDomainIds.Select(id => new Domain(Domain.LookupByID(_conn, id),
this)).ToList();
}
}
So the property call "virConnectNumOfDomains" and
"virConnectListDomains" each time the property is called. And I don't know
if it is a good thing. The other way, is to keep the list in the Connect object and handle
domain adding or removing in this via callbacks. This avoid multiple call to the librar.
Any advice ?
Regards,
Arnaud
Show replies by date