473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Interface Question

Hello all
I'm currently converting me and our code from VB.NET to C# for the
company I work for.

I have an VB.NET interface that has an excerpt like this:

Public Interface ISensorCameraSettings
..
..
..
Property Exposure(ByVal ChannelName As String) As Single
Property Gain(ByVal ChannelName As String) As Integer
Property BitRange(ByVal ChannelName As String) As Integer
..
..
..
End Interface

I can't figure the syntax to convert this to C#. . .
I've tried many iterations, I'm sure I just havent found the correct
thread on google or msdn?

something like:
public interface ICameraSettings
{
/// <summary>
/// Set the exposure for this sensor.
/// </summary>
void set_Exposure(string DataBufferName,float value);
float get_Exposure(string DataBuffername);
}
???

Please help.

Sincerely,

Kevin Christopher

Nov 16 '05 #1
8 2590
I have never used VB.Net but you seem to want is to declare an
interface in C# and expose get/set properties. Its something like this:

public interface ICameraSettings
{
float Exposure
{ get; set;
}
}

------
Ajay Kalra
aj*******@yahoo.com

Nov 16 '05 #2
Thank you for the response. You left out the arguments, and adding
them in like this

float Exposure(string DataBufferName){get;set;}

Results in an "Interface members cannot have a definition" error.

-Kevin

Nov 16 '05 #3
>I can't figure the syntax to convert this to C#. . .

C# doesn't support non-default (i.e. non-indexer) parameterized
properties. So you can't write that in C#.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
Thanks for pointing it out. I was kind of lost when I saw what VB is
allowing to do.

So, in this case, the best bet would be to simply write methods to
achieve the same? Correct?

------
Ajay Kalra
aj*******@yahoo.com

Nov 16 '05 #5
Thank you for the quick response guys, this is awesome. I finally
figured out what to ask for on the newsgroup ("parameterized
properties") and found results that confirm Mattias' response.

Bummer! That means that this interface cannot be converted without
breaking it, and all the apps that rely on it.

Instead of raising a rukus and starting a vb-c# debate, I'll back away
slowly . . . (c;

Thank you all for the expedient support.
Sincerely,

Kevin

Nov 16 '05 #6
Yes, I guess that's what I'll have to do. Unfortunately, this will
break the interface; and all those relying on it.

Thanks for the response Ajay.

-Kevin

Nov 16 '05 #7
The C# equivalent is an indexer, which requires enumerating the values. In
essence, what you desire is the ability to do the following (VB.NET code):

MyClass.Exposure("channel1") = 1
MyClass.Exposure("channel2") = 2

In C#, the closest is something like:

MyClass.Exposure[1] = 1;
MyClass.Exposure[2] = 2;

This, however, means you have to trap the indexed values somewhere, like:

Hashtable lookup = new Hashtable();
lookup.Add("channel1", 1);
lookup.Add("channel2", 2);

You can then run against the object like so:
MyClass.Exposure[Convert.ToInt32(lookup["channel1"])] = 1;
MyClass.Exposure[Convert.ToInt32(lookup["channel2"])] ] = 2;

This is an architectural difference between C# and VB.NET. But, there is a
good reason. In VB.NET, this is perfectly legal:

Public Property Exposure(ByRef UnrelatedCrap1 As String, _
ByRef UnrelatedCrap2 As String, _
ByRef ObjectInitializationSettings As
Hashtable, _
ByRef DisposeMeNow As Boolean, _
ByRef DoAWebServiceLookup As Boolean, _
) As Single
If (UnrelatedCrap1 = "MakeTheObjectDance") Then
MakeTheObjectDance()
End If
End Property

And, believe it or not, there are people who have done this in apps (of
course, it meant I had to explain the bloodstains in my trunk ;->).

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Razzerroo" wrote:
Hello all
I'm currently converting me and our code from VB.NET to C# for the
company I work for.

I have an VB.NET interface that has an excerpt like this:

Public Interface ISensorCameraSettings
..
..
..
Property Exposure(ByVal ChannelName As String) As Single
Property Gain(ByVal ChannelName As String) As Integer
Property BitRange(ByVal ChannelName As String) As Integer
..
..
..
End Interface

I can't figure the syntax to convert this to C#. . .
I've tried many iterations, I'm sure I just havent found the correct
thread on google or msdn?

something like:
public interface ICameraSettings
{
/// <summary>
/// Set the exposure for this sensor.
/// </summary>
void set_Exposure(string DataBufferName,float value);
float get_Exposure(string DataBuffername);
}
???

Please help.

Sincerely,

Kevin Christopher

Nov 16 '05 #8
Hey man take the DLL or EXE written in VB.NET and decompile it to C# using
Lutz Roeder's Reflector... http://www.aisto.com/roeder/dotnet/

It will save you hours and hours of work.

~yamazed
"Razzerroo" wrote:
Hello all
I'm currently converting me and our code from VB.NET to C# for the
company I work for.

I have an VB.NET interface that has an excerpt like this:

Public Interface ISensorCameraSettings
..
..
..
Property Exposure(ByVal ChannelName As String) As Single
Property Gain(ByVal ChannelName As String) As Integer
Property BitRange(ByVal ChannelName As String) As Integer
..
..
..
End Interface

I can't figure the syntax to convert this to C#. . .
I've tried many iterations, I'm sure I just havent found the correct
thread on google or msdn?

something like:
public interface ICameraSettings
{
/// <summary>
/// Set the exposure for this sensor.
/// </summary>
void set_Exposure(string DataBufferName,float value);
float get_Exposure(string DataBuffername);
}
???

Please help.

Sincerely,

Kevin Christopher

Nov 16 '05 #9

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

Similar topics

65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
26
by: Marius Horak | last post by:
As in subject. Thanks MH
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
13
by: John Salerno | last post by:
Hi all. I have a question about interfaces now. According to the book I'm reading, when you implement an interface, the class or structure has to declare all the methods that the interface...
6
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives ...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
5
by: Colin McGuire | last post by:
Hi all, when I write the class below Private Class employee End Class and then add the line "Implements IVF" which is an interface I have written, the IDE modifies my code to display
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.