VMware {code} Community
bsteer
Contributor
Contributor

Simple property finder in C#?

Is there a simple way to find a property, using C#? Following some sample code, I've created a TraversalSpec, an array of PropertySpecs and a PropertyFilterSpec. The traversalSpec and the aray of propertySpecs are referenced in the PropertyFilterSpec, which is then used in the call to RetrieveProperties. This seems to be fairly complicated, just to retrieve the value of one property. Is there a simpler way to do it? Can anybody supply sample C# code?

Reply
0 Kudos
1 Reply
jrackliffe
Hot Shot
Hot Shot

Linked thread http://communities.vmware.com/message/778886

Regrettably the property acquisiton is bound to the overall complex arangement you list below. And until the Helper lib for .NET comes out you will need to manage your retrieveprops queries.

If you have a working ts, ps and pfs and the RetrieveProp call returns back the goods in the ObjectContent array result you can easily loop through the objs and get their props using a pattern like this. Note brackets get eaten by the forum so replace the parens to make it compile. There is also a sample in the SDK stuff that demonstrates this.

if (ocs != null)

{

foreach (ObjectContent oc in ocs)

{

DynamicProperty() dps = oc.propSet;

if (dps != null)

{

foreach (DynamicProperty dp in dps)

{

if (dp.name == propertyName)

return dp.val;

}

}

}

}

Reply
0 Kudos