kellyelton/Eltons.ReflectionKit

System.Object& instead of object, when ByRef

Opened this issue · 2 comments

Heya,

I looked at your stackoverflow answer and ended up here :)
Thanks for the ReflectionKit.

I am getting this instead of object:

MethodInfo.ToString():

Int32 SelectComponentFromTable(System.Object ByRef, System.Object ByRef)

GetSignature(false):

public int SelectComponentFromTable(ref System.Object& ComponentName, ref System.Object& ComponentVersion)

I realized that it is not only with object but also string and int.
This happens when the ref keyword is there.

Using Resharper to produce the source, I get the following (It is a different method, but mainly because in this one, there is a string and an int:

[DispId(1610809345)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern int GetProjectInformation(
    [MarshalAs(UnmanagedType.Struct), In, Out] ref object filename,
    [MarshalAs(UnmanagedType.Struct), In, Out] ref object type,
    [MarshalAs(UnmanagedType.Struct), In, Out] ref object is_dbe);

The helpfile documentation for this assembly mentions the following:

GetProjectInformation( filename, type, is_dbe ) 
Syntax 
Integer GetProjectInformation( [in]String filename, [out]Integer type, [out]Integer is_dbe ) 

Digging in the debugger, I get the following:

-		parameters	{System.Reflection.ParameterInfo[3]}	System.Reflection.ParameterInfo[]
-		[0]	{System.Object& filename}	System.Reflection.ParameterInfo {System.Reflection.RuntimeParameterInfo}
		Attributes	In | Out | HasFieldMarshal	System.Reflection.ParameterAttributes
		AttrsImpl	In | Out | HasFieldMarshal	System.Reflection.ParameterAttributes
+		ClassImpl	{Name = "Object&" FullName = "System.Object&"}	System.Type {System.RuntimeType}
-		CustomAttributes	Count = 3	System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeData>}
+		[0]	{[System.Runtime.InteropServices.InAttribute()]}	System.Reflection.CustomAttributeData
+		[1]	{[System.Runtime.InteropServices.OutAttribute()]}	System.Reflection.CustomAttributeData
-		[2]	{[System.Runtime.InteropServices.MarshalAsAttribute((System.Runtime.InteropServices.UnmanagedType)27, ArraySubType = 0, SizeParamIndex = 0, SizeConst = 0, IidParameterIndex = 0, SafeArraySubType = 0)]}	System.Reflection.CustomAttributeData
+		AttributeType	{Name = "MarshalAsAttribute" FullName = "System.Runtime.InteropServices.MarshalAsAttribute"}	System.Type {System.RuntimeType}
+		Constructor	{Void .ctor(System.Runtime.InteropServices.UnmanagedType)}	System.Reflection.ConstructorInfo {System.Reflection.RuntimeConstructorInfo}
-		ConstructorArguments	Count = 1	System.Collections.Generic.IList<System.Reflection.CustomAttributeTypedArgument> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeTypedArgument>}
-		[0]	{(System.Runtime.InteropServices.UnmanagedType)27}	System.Reflection.CustomAttributeTypedArgument
+		ArgumentType	{Name = "UnmanagedType" FullName = "System.Runtime.InteropServices.UnmanagedType"}	System.Type {System.RuntimeType}
		Value	27	object {int}
+		Non-Public members		
+		Raw View		
-		NamedArguments	Count = 5	System.Collections.Generic.IList<System.Reflection.CustomAttributeNamedArgument> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeNamedArgument>}
+		[0]	{ArraySubType = 0}	System.Reflection.CustomAttributeNamedArgument
+		[1]	{SizeParamIndex = 0}	System.Reflection.CustomAttributeNamedArgument
+		[2]	{SizeConst = 0}	System.Reflection.CustomAttributeNamedArgument
+		[3]	{IidParameterIndex = 0}	System.Reflection.CustomAttributeNamedArgument
+		[4]	{SafeArraySubType = 0}	System.Reflection.CustomAttributeNamedArgument
+		Raw View		
+		Non-Public members		
+		Raw View		
+		DefaultValue	{}	object {System.DBNull}
		DefaultValueImpl	null	object
		HasDefaultValue	false	bool
		IsIn	true	bool
		IsLcid	false	bool
		IsOptional	false	bool
		IsOut	true	bool
		IsRetval	false	bool
+		Member	{Int32 GetProjectInformation(System.Object ByRef, System.Object ByRef, System.Object ByRef)}	System.Reflection.MemberInfo {System.Reflection.RuntimeMethodInfo}
+		MemberImpl	{Int32 GetProjectInformation(System.Object ByRef, System.Object ByRef, System.Object ByRef)}	System.Reflection.MemberInfo {System.Reflection.RuntimeMethodInfo}
		MetadataToken	134222821	int
		Name	"filename"	string
		NameImpl	"filename"	string
+		ParameterType	{Name = "Object&" FullName = "System.Object&"}	System.Type {System.RuntimeType}
		Position	0	int
		PositionImpl	0	int
+		RawDefaultValue	{}	object {System.DBNull}
+		Static members		
+		Non-Public members		
+		[1]	{System.Object& type}	System.Reflection.ParameterInfo {System.Reflection.RuntimeParameterInfo}
+		[2]	{System.Object& is_dbe}	System.Reflection.ParameterInfo {System.Reflection.RuntimeParameterInfo}

This is the same for all 3 arguments:

-		ConstructorArguments	Count = 1	System.Collections.Generic.IList<System.Reflection.CustomAttributeTypedArgument> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeTypedArgument>}
-		[0]	{(System.Runtime.InteropServices.UnmanagedType)27}	System.Reflection.CustomAttributeTypedArgument
+		ArgumentType	{Name = "UnmanagedType" FullName = "System.Runtime.InteropServices.UnmanagedType"}	System.Type {System.RuntimeType}
		Value	27	object {int}

And by using the library itself, I get a object parameter type for the 3, so apparently the library documentation is wrong.