By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,452 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,452 IT Pros & Developers. It's quick & easy.

Interface Question

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
>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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.