-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Sitaraman
Message 3 in Discussion
Hi As Shamir said it is better to use guidelines specified by MS if u want proper
language interoperability. But wat if the C# code was written by someone and u dont
have access to the C# source code? How do u solve this problem then? Check this out!!!
C# Class public class Class1
{ public Class1()
{
//
// TODO: Add constructor logic here
//
} //Two functions below, the only difference between the two is their
Case(lower case and upper case) public String function1(String p_strData)//Note
that function1 is lower case here
{
return("Lower Case Function - function1() Called with Parameter : " +
p_strData);
}
public String FUNCTION1(String p_strData)//Note that FUNCTION1 is upper case here
{
return("Upper Case Function - FUNCTION1() Called with Parameter : " +
p_strData);
}
} VB.Net Client Imports System.Reflection
Module Module1 Sub Main()
Dim l_obj1 As New CSharpClassLib.Class1() ' The Statement below, if
uncommented, will give will give the following error
' Overload resolution failed because no accessible 'function1' is most
specific for these arguments:
' Public Overloads Function FUNCTION1() As String': Not most specific.
' Public Overloads Function function1() As String': Not most specific.
'l_obj1.FUNCTION1() 'How to avoid this?? Use the mechanism given
below Dim l_objParameters(0) As Object
Dim l_objReturnValue As Object l_objParameters(0) = "111"
Console.WriteLine("Calling Lower case function - function1()")
l_objReturnValue = l_obj1.GetType.InvokeMember("function1",
System.Reflection.BindingFlags.Instance Or _
BindingFlags.Public Or
BindingFlags.InvokeMethod, Nothing, l_obj1 _
, l_objParameters, Nothing,
Nothing, Nothing)
Console.WriteLine(l_objReturnValue) Console.WriteLine()
l_objParameters(0) = "222"
Console.WriteLine("Calling Upper case function - FUNCTION1()")
l_objReturnValue = l_obj1.GetType.InvokeMember("FUNCTION1",
System.Reflection.BindingFlags.Instance Or _
BindingFlags.Public Or
BindingFlags.InvokeMethod, Nothing, l_obj1 _
, l_objParameters, Nothing,
Nothing, Nothing)
Console.WriteLine(l_objReturnValue) 'Note : The InvokeMember can be
used to invoke any member(property method etc...). Here im passing the method name as
the first parameter and by passing the BindingFlags.InvokeMethod as the
second parameter im specifying that im invoking a method. Note that , by default, the
InvokeMember function will treat its first parameter(function name ) as case
sensitive. Im using that to our advantage here. In case u do not want this
case sensitivity for some other purpose then u can achieve tht by adding
System.Reflection.BindingFlags.ignorecase in the second parameter.
Console.ReadLine() End Sub End Module
Note tht using reflection has a performance overhead and the above mentioned
mechanism should be used only if u cannot modify the C# Code to comply to the
guidelines. hth regards, sr
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]