[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 '&' 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 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>
<P>using System;<BR>using System.Reflection;<BR> <BR>class parminfo<BR>{<BR> public static void mymethod(int int1m, out string str2m, <BR> ref string str3m, out string str4m)<BR> {<BR> str2m = "in mymethod";<BR> str4m = "also in mymethod";<BR> }<BR> <BR> public static int Main(string[] args)<BR> {<BR> Console.WriteLine("Reflection.Parameterinfo");<BR> <BR> Type Mytype = Type.GetType("parminfo");<BR> MethodBase Mymethodbase = Mytype.GetMethod("mymethod");<BR> Console.WriteLine("Mymethodbase = " + Mymethodbase);<BR> <BR> foreach (ParameterInfo Myparam in Mymethodbase.GetParameters())<BR> {<BR> Console.WriteLine(" param #{0} {1}", Myparam.Position, <BR> My
param.Name);<BR> Console.WriteLine(" type: {0} ({1})",<BR> Myparam.ParameterType.Name,<BR> Myparam.ParameterType.FullName);<BR> Console.WriteLine(" IsIn: {0}", Myparam.IsIn);<BR> Console.WriteLine(" IsOut: {0}", Myparam.IsOut);<BR> Console.WriteLine(" IsRetval: {0}", Myparam.IsRetval);<BR> }<BR> <BR> return 0;<BR> }<BR>}
<P> <B><I>Paolo Molaro <lupus@ximian.com></I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">On 03/03/03 Erik LeBel wrote:<BR>> While using reflection I've found that ParameterInfo's IsIn, IsOut<BR>> and IsRetval always return false. I have not found any logged bugs at<BR>> Ximian's bugzilla. Is this a know problem? If this is not a problem,<BR>> then I'll assume that something in my code is not correct, but it seems<BR>> 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--