Question

Good day all,

I am struggling to determine what's the issue with an attempt to access a public property on a class.

My need is very basic. I have a public class that's correctly instanced in my routine, and I know, thanks to reflector, that this class has a property that I need to reference.

Problem is, the property is defined as thus:

public Vector3 root {
    [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall] get;
    [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall] set;
}

The problem I'm facing is that all my attempts at getting the property simply fail. I've instanced the Type, and tried with all possible combinations of binding flags

Type vtype = myobj.getType()
PropertyInfo[] vproperties;
vproperties = vtype.GetProperties();//(BindingFlags.Default | BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic);
for (int vpropertycounter =0 ; vpropertycounter < vproperties.Length ; vpropertycounter++) {
    Console.write( varbodyproperties[varpropertycounter].Name); <= 'root' never appears in this list
}

My suspicion and doubt revolves around the fact that the root property might not be 'visibile' because its getter and setter are 'wrapperless' and 'internal'. Sadly I don't know if this can be overcome or not.

I would like to know if this property can by all means be accessed, and possibly how to do it.

All feedback is welcome.

Thanks in advance.

NOTE: addressing the property directly, as in "myobj.root" generates a compiler error for unknown property.

Était-ce utile?

La solution

Methods with MethodImplOptions.InternalCall are usually internal framework methods. You cannot call them directly or via reflection (which is more or less the same thing).

It depends on the library, I found something like this within the Word API where it internally uses VB. To access variant Properties you'll have to call a setter method for example

 Property = "" <- doesn't work
 set_Property("") <- works

Depends on the API you are trying to access I guess, if those successors are implemented

Apart from that, maybe read the Platform Invoke Tutorial

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top