471,084 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

Invoking case-sensitive C# methods from VB.NET

Please have a look at the code given below. The class named 'Class1' has two
methods with the same name but with different case. Now how can I invoke
these methods from VB.

using System;

namespace ClassLibrary1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}

public string hello()
{
return "Small h";
}

public string Hello()
{
return "Capital H";
}
}
}
Nov 16 '05 #1
2 1611
Nelson P. Varghese wrote:
Please have a look at the code given below. The class named 'Class1'
has two methods with the same name but with different case. Now how
can I invoke these methods from VB.


This code is not CLS compliant, so the answer is you can't. Marking the
assembly [assembly: CLSCompliant(true)] should produce a warning (error?).

Cheers,
--
Joerg Jooss
www.joergjooss.de
ne**@joergjooss.de
Nov 16 '05 #2
> Please have a look at the code given below. The class named 'Class1' has
two
methods with the same name but with different case. Now how can I invoke
these methods from VB.

You must use reflection to separate the camel cased method from the Pascal
cased method.

Dim myClass As New Class1
Dim camel, pascal As String
camel = myClass .GetType.InvokeMember("hello", _
System.Reflection.BindingFlags.Instance Or _
BindingFlags.Public Or BindingFlags.InvokeMethod, _
Nothing, Class1, Nothing, Nothing, Nothing, Nothing)

pascal = myClass .GetType.InvokeMember("Hello", _
System.Reflection.BindingFlags.Instance Or _
BindingFlags.Public Or BindingFlags.InvokeMethod, _
Nothing, Class1, Nothing, Nothing, Nothing, Nothing)

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by bbxrider | last post: by
5 posts views Thread by Philip | last post: by
4 posts views Thread by Joanna Carter \(TeamB\) | last post: by
2 posts views Thread by =?Utf-8?B?SmltIE93ZW4=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.