I have a variable in fsharp interactive
val toto : obj = [["NKY INDEX"]]
(I got that value from a call to a regular dotnet library, whose prototype tells me it returns an obj )
I would like to access the value inside of it, but I don't know exactly the type. So I try to reflect on it :
>toto.GetType();;
val it : Type =
System.Object[,]
{Assembly = mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;
AssemblyQualifiedName = "System.Object[,], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
Attributes = AutoLayout, AnsiClass, Class, Public, Sealed, Serializable;
BaseType = System.Array;
ContainsGenericParameters = false;
CustomAttributes = seq [[System.SerializableAttribute()]];
DeclaredConstructors = [|Void .ctor(Int32, Int32);
Void .ctor(Int32, Int32, Int32, Int32)|];
DeclaredEvents = [||];
DeclaredFields = [||];
DeclaredMembers = [|Void Set(Int32, Int32, System.Object);
System.Object& Address(Int32, Int32);
System.Object Get(Int32, Int32);
Void .ctor(Int32, Int32);
Void .ctor(Int32, Int32, Int32, Int32)|];
DeclaredMethods = [|Void Set(Int32, Int32, System.Object);
System.Object& Address(Int32, Int32);
System.Object Get(Int32, Int32)|];
DeclaredNestedTypes = seq [];
DeclaredProperties = [||];
It has a Get method, however, when I try to retrieve the element, I get an error.
>toto.Get(0,0);;
toto.Get(0,0);;
-----^^^
error FS0039: The field, constructor or member 'Get' is not defined
What is the correct way to retrieve the inside element ?
PS : casting it beforehand yields the same
>(toto :?> System.Object[,]).Get(0,0);;
(toto :?> System.Object[,]).Get(0,0);;
----------------------------^^^
error FS0039: The field, constructor or member 'Get' is not defined
same for .[0, 0]
> toto.[0, 0];;
toto.[0, 0];;
^^^^^^^^^^^
error FS0039: The field, constructor or member 'Item' is not defined
toto : obj = [[""]]shouldn`t even compile. - JaredPar