473,480 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using C# written Class in VB.NET project - Case Problem

Hi,

I've a component written in C#, and I use it in VB.NET project.
The class comes with these members:

MyClass.onClick ==> This is a property of type string
MyClass.OnClick ==> This is an event

In C# I can use this as expected.

Now I have a VB.NET project and Intellisense cannot recognize the
OnClick event because it sees the onClick property instead with
2 overloads.

I want to do:

AddHandler MyClass.OnClick, AddressOf MyHandler
^^^^^^^

This fails, because VB.NET reads a property instead of the event
and the editor makes the OnClick (upper case O) into onClick
(lower case o).

Has anybody any solution in VB.NET?

Thank you for any idea...

Jorge
Nov 20 '05 #1
8 1284
G'Day,

The best way is to change the property name or the event name. It is not a
good practice anyway IMHO.
Nov 20 '05 #2
If you have the C# code, rename the Property and Event to something a bit
more descriptive. AFAIK, Identifiers Beginning with "On" are used to
identify protected methods used to raise the event of the same name minus
the "On" (e.g. Protected "OnClick" method raises the "Click" event).

If you are stuck with the names, maybe you could inherit from the class and
provide a new event with a different name that is raised when the base class
raises the OnClick event. Just remember that this way is a Fudge IMHO.

Hth,

Trev.

"Joerg Krause" <jo***@krause.net> wrote in message
news:75**************************@posting.google.c om...
Hi,

I've a component written in C#, and I use it in VB.NET project.
The class comes with these members:

MyClass.onClick ==> This is a property of type string
MyClass.OnClick ==> This is an event

In C# I can use this as expected.

Now I have a VB.NET project and Intellisense cannot recognize the
OnClick event because it sees the onClick property instead with
2 overloads.

I want to do:

AddHandler MyClass.OnClick, AddressOf MyHandler
^^^^^^^

This fails, because VB.NET reads a property instead of the event
and the editor makes the OnClick (upper case O) into onClick
(lower case o).

Has anybody any solution in VB.NET?

Thank you for any idea...

Jorge

Nov 20 '05 #3
Think VB.NET is case insensitive so it can't distinguish onClick from
OnClick or indeed ONCLICK or onclick.
You probably have to change the name of the property to something else?
There might be a workaround I don't know of.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 20 '05 #4
* jo***@krause.net (Joerg Krause) scripsit:
I've a component written in C#, and I use it in VB.NET project.
The class comes with these members:

MyClass.onClick ==> This is a property of type string
MyClass.OnClick ==> This is an event


That's very bad design in the C# class. If you have the source code,
change it. If you don't have it, ask the author of the component to
change it.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
"Joerg Krause" <jo***@krause.net> schrieb
Hi,

I've a component written in C#, and I use it in VB.NET project.
The class comes with these members:

MyClass.onClick ==> This is a property of type string
MyClass.OnClick ==> This is an event

In C# I can use this as expected.


Don't use C#. It is case sensitive.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
Just to add: if you've written the c# component and plan on using it from
other languages, you should try adding the attribute
[assembly:CLSCompliant(true)]

If this is added, the compiler will verify CLS Compliance - it would yell at
you for having multiple public exports from a type with names that differ
only by case. You may find other issues this way as well.

Note that not all assemblies can use this, as it is quite restrictive - but
it does help for multiple-language projects.

-Philip Rieck
"Joerg Krause" <jo***@krause.net> wrote in message
news:75**************************@posting.google.c om...
Hi,

I've a component written in C#, and I use it in VB.NET project.
The class comes with these members:

MyClass.onClick ==> This is a property of type string
MyClass.OnClick ==> This is an event

In C# I can use this as expected.

Now I have a VB.NET project and Intellisense cannot recognize the
OnClick event because it sees the onClick property instead with
2 overloads.

I want to do:

AddHandler MyClass.OnClick, AddressOf MyHandler
^^^^^^^

This fails, because VB.NET reads a property instead of the event
and the editor makes the OnClick (upper case O) into onClick
(lower case o).

Has anybody any solution in VB.NET?

Thank you for any idea...

Jorge

Nov 20 '05 #7
Thank you for the answers.

ClsCompliant is not possible, the project contains a lot of COM Interop
stuff which is in fact not CLS compliant.

Changing the sources is obviously the best way. My questions was "what
can I do if I have the object form only?".

-Joerg
www.joergkrause.de
ASP.NET/.NET-WinForm Softwaredevelopment

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8
* Joerg Krause <joerg_at_krause_dot_net> scripsit:
Changing the sources is obviously the best way. My questions was "what
can I do if I have the object form only?".


You can use reflection to call the method/..., but that's not very
comfortable.

\\\
Imports System.Reflection

Public Class Main
Public Shared Sub Main()
Dim sc As New SampleClass()
Dim obj As Object = sc ' ;-)))
Dim mi As MethodInfo = obj.GetType.GetMethod("SampleMethod")
mi.Invoke(obj, Nothing)
End Sub

Public Class SampleClass
Public Sub SampleMethod()
MsgBox("Hello World!")
End Sub
End Class
End Class
///

Keywords: invoke, call, method, reflection.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1977
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
121
9890
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
11
6546
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
6674
by: Terry | last post by:
I'm building some dll assemblies that have in them the implementation of an abstract class defined in a different assembly. I'm trying to create objects of the type defined in the dlls with...
4
1394
by: Joerg Krause | last post by:
Hi, I've a component written in C#, and I use it in VB.NET project. The class comes with these members: MyClass.onClick ==> This is a property of type string MyClass.OnClick ==> This is an...
12
2031
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
0
3903
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
3
1984
by: flat_ross | last post by:
For anyone who is just getting into VB.NET and/or is starting to work with inheritance I would like to point out a potential pitfall. We found this confusion recently when code-reviewing an...
8
2387
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
6903
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.