[Mono-list] Reflection error

Erik LeBel eriklebel@yahoo.ca
Wed, 5 Mar 2003 16:02:01 -0500 (EST)


--0-981146507-1046898121=:93793
Content-Type: text/plain; charset=us-ascii


The following code snippet indicates that:
IsOut is set only for out parameters. (as it should)
Ref parameters are characterised by the ParameterType.FullName having a '&' appended to if, and the parameter is not an IsOut. (this seems like a hack, there must be a better way to determine this)
IsIn is not set for any of these parameters. A parameter is out if it fails to qualify for the previous conditions. (not terribly useful)
MSDN states that the IsIn and IsOut values MAY be set by the compiler, but don't need to. I presume Mono uses a more deterministic system to decide on the direction of its arguments.
the code sample itself may be buggy. I'm sure there is another case where IsOut is not set even though the parameter is an out, but the code is rather lengthy, I'm still trying to refine it.
 
using System;
using System.Reflection;
 
class parminfo
{
    public static void mymethod(int int1m, out string str2m, 
     ref string str3m, out string str4m)
    {
       str2m = "in mymethod";
       str4m = "also in mymethod";
    }
  
    public static int Main(string[] args)
    {
 Console.WriteLine("Reflection.Parameterinfo");
       
 Type Mytype = Type.GetType("parminfo");
 MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
 Console.WriteLine("Mymethodbase = " + Mymethodbase);
  
 foreach (ParameterInfo Myparam in Mymethodbase.GetParameters())
 {
     Console.WriteLine(" param #{0}  {1}", Myparam.Position, 
      Myparam.Name);
     Console.WriteLine("   type: {0} ({1})",
      Myparam.ParameterType.Name,
      Myparam.ParameterType.FullName);
     Console.WriteLine("   IsIn: {0}", Myparam.IsIn);
     Console.WriteLine("   IsOut: {0}", Myparam.IsOut);
     Console.WriteLine("   IsRetval: {0}", Myparam.IsRetval);
 }
 
 return 0;
    }
}
 Paolo Molaro <lupus@ximian.com> wrote:On 03/03/03 Erik LeBel wrote:
> While using reflection I've found that ParameterInfo's IsIn, IsOut
> and IsRetval always return false. I have not found any logged bugs at
> Ximian's bugzilla. Is this a know problem? If this is not a problem,
> then I'll assume that something in my code is not correct, but it seems
> odd to have all the metadata except method attribute info.

It's supposed to work (mcs uses them, for example).
If you have a test case where it doesn't work, submit it so that
people can check if it's a bug in your code or in mono.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


---------------------------------
Post your free ad now! Yahoo! Canada Personals

--0-981146507-1046898121=:93793
Content-Type: text/html; charset=us-ascii

<P>The following code snippet indicates that:
<P>IsOut is set only for out parameters. (as it should)
<P>Ref parameters are characterised by the ParameterType.FullName having a '&amp;' appended to if, and the parameter is not an IsOut. (this seems like a hack, there must be a better way to determine this)
<P>IsIn is not set for any of these parameters. A parameter is out if it fails to qualify for the&nbsp;previous conditions. (not terribly useful)
<P>MSDN states that the IsIn and IsOut values MAY be set by the compiler, but don't need to. I presume Mono uses a more deterministic system to decide on the direction of its arguments.
<P>the code sample itself may be buggy. I'm sure there is another case where IsOut is not set even though the parameter is an out, but the code is rather lengthy, I'm still trying to refine it.
<P>&nbsp;
<P>using System;<BR>using System.Reflection;<BR>&nbsp;<BR>class parminfo<BR>{<BR>&nbsp;&nbsp;&nbsp; public static void mymethod(int int1m, out string str2m, <BR>&nbsp;&nbsp;&nbsp;&nbsp; ref string str3m, out string str4m)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str2m = "in mymethod";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str4m = "also in mymethod";<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; public static int Main(string[] args)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;Console.WriteLine("Reflection.Parameterinfo");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;Type Mytype = Type.GetType("parminfo");<BR>&nbsp;MethodBase Mymethodbase = Mytype.GetMethod("mymethod");<BR>&nbsp;Console.WriteLine("Mymethodbase = " + Mymethodbase);<BR>&nbsp; <BR>&nbsp;foreach (ParameterInfo Myparam in Mymethodbase.GetParameters())<BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(" param #{0}&nbsp; {1}", Myparam.Position, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My
 param.Name);<BR>&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("&nbsp;&nbsp; type: {0} ({1})",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Myparam.ParameterType.Name,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Myparam.ParameterType.FullName);<BR>&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("&nbsp;&nbsp; IsIn: {0}", Myparam.IsIn);<BR>&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("&nbsp;&nbsp; IsOut: {0}", Myparam.IsOut);<BR>&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("&nbsp;&nbsp; IsRetval: {0}", Myparam.IsRetval);<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;return 0;<BR>&nbsp;&nbsp;&nbsp; }<BR>}
<P>&nbsp;<B><I>Paolo Molaro &lt;lupus@ximian.com&gt;</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">On 03/03/03 Erik LeBel wrote:<BR>&gt; While using reflection I've found that ParameterInfo's IsIn, IsOut<BR>&gt; and IsRetval always return false. I have not found any logged bugs at<BR>&gt; Ximian's bugzilla. Is this a know problem? If this is not a problem,<BR>&gt; then I'll assume that something in my code is not correct, but it seems<BR>&gt; odd to have all the metadata except method attribute info.<BR><BR>It's supposed to work (mcs uses them, for example).<BR>If you have a test case where it doesn't work, submit it so that<BR>people can check if it's a bug in your code or in mono.<BR><BR>lupus<BR><BR>-- <BR>-----------------------------------------------------------------<BR>lupus@debian.org debian/rules<BR>lupus@ximian.com Monkeys do it better<BR>_______________________________________________<BR>Mono-list maillist - Mono-list@lists.ximian.com<BR>http://lists.ximian.com/mailman/listi
 nfo/mono-list</BLOCKQUOTE><p><br><hr size=1>Post your free ad now! <a href="http://ca.personals.yahoo.com/"><b>Yahoo! Canada Personals</b></a><br>
--0-981146507-1046898121=:93793--