Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I must say that ive learned more about code structure in the past couple of days that i have in the past year by decompiling some code.

 

most of it works but i am having a couple of problems that i cant figure out.

 

Im decompiling a couple of programs so that i may find out ways to accomplish the tasks i would like my program to do but Im not sure of the following things.

 

 

Private  Function Windows.Forms.Edit.IScrollBar.get_Enabled() As Boolean Implements IScrollBar.get_Enabled
           Return MyBase.Enabled
       End Function

 

this is how a couple of functions came up in my code. I dont understand why i cant do this.

 

actually, they were declared as private overrideable too..

 

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
Public ReadOnly Property IsThumbTracking As Boolean
           Get
               Return Me.isThumbTracking
           End Get
       End Property

 

I dont understand what the begininng "<information>" is used for so i havent messed with it.

 

 

another big issue thats getting me is this

 

 Property KeyBindingProcessor() As KeyProcessor
           ' was public set and get
           public Get
               Return Me.m_keyBinder
           End Get
          public  Set(ByVal value As KeyProcessor)
               If (value Is Nothing) Then
                   Throw New ArgumentNullException
               End If
               Me.m_keyBinder = value
           End Set
       End Property

 

It works if i remove the "public" from the code but im just confused as to why it was accepted in the first place..

  • *Experts*
Posted

1. Not sure which part has the problem? Your code, or your understanding of the code you're watching.

 

2. The "<DesignerSerializationVisibility" is a "decoration" you can apply. This one goes on a property and helps an IDE like Visual Studio take some actions. For example, by saying "Browsable(False)", you won't see this property in the intellisense dropdown.

 

3. Setting the public modifier on the Get and Set separately will be supported in .NET 2.0 when it comes out, maybe you saw some early code?

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

the code that im watching has the problem.

 

 

one other thing that i saw was something like this

 

interface mashed potatoes

implements gravy

end interface.

 

apparantly i cant have an implement inside of an interface?

Posted

My guess is that you have reverse-compiled something originally written in C#. I'm not very experienced with C#, but I believe that a C# Interface can Implement another, or at least Inherit... but in VB.Net, this would not be permitted. (I'm sure the C# guys will jump all over me if I got this wrong! Feel free... :))

 

So your code, when reverse-compiled, is not technically legal as VB.Net code. The compiler would not permit it.

Posting Guidelines

 

Avatar by Lebb

Posted
Interfaces can inherit other interfaces in VB and C#, just not implement them. Interfaces cannot have any implementation. I don't see how the implements keyword was there. Maybe it was just a reflection error.
Posted

Ok, kicking this around a bit, it looks like you're right about VB: VB.Net Interfaces can Inherit, but not Implement. But it does look like C# Interfaces can Inherit and implement. This seems to be legal:

   interface IFace1
   {
   }

   interface IFace2
   {
   }

   interface IFace3 : IFace1, IFace2
   {
   }

The equivalent in VB.Net is not:

Interface IFace1
End Interface

Interface IFace2
End Interface

Interface IFace3
   Inherits IFace1
   Implements IFace2 ' <-- ** No good **
End Interface

It chokes on the Implements keword. Odd, right..?

 

Now there's something else interesting that I stumbled onto on the Web: it seems that VB.Net Interfaces are truly *pure* Interfaces only, while C# Interfaces, although technically incapable of Inheriting from other Classes, they seem to implicitly Inherit from the Object Class. VB.Net Interfaces do not even inherit even from this:

 

Strange Interface Behaviour in VB.Net vs. C#

 

Crazy stuff...

Posting Guidelines

 

Avatar by Lebb

  • Leaders
Posted

Mike_R... the following code:

   interface IFace3 : IFace1, IFace2
   {
   }

 

does not inherit IFace1 and implement IFace2. In fact, I'm not even sure if you think it does. There is a hole in your logic somewhere though. Interfaces in both VB and C# support multiple inheritance. In the code above both IFace1 and IFace2 are being inherited, not implemented, in the interface IFace3, and the resulting interface will contain the combined set of functions from both interfaces. This is also allowed in VB.

Interface IFace3_BAD
   Inherits IFace1
   Implements IFace2 ' <-- ** No good **
End Interface 

Interface IFace3_GOOD
   Inherits IFace1
   Inherits IFace2 ' <-- * Kosher *
End Interface 

 

My best guess as to why the word implements was in the decompiled code instead of inherits is some sort of bug or mistake on the part of the progammer who made the decompiler. If it tells you that one interface implements another you can probably safely assume that it actually inherits it. I would also make the same sort of assumptions about the other abnormalities you found.

[sIGPIC]e[/sIGPIC]
Posted (edited)
Mike_R... There is a hole in your logic somewhere...
Yeah, I think you caught me :( I think there were two holes actually...

 

After posting this, I started thinking about what it would mean for an Interface to "Implement" another Interface. It's pretty meaningless if you think about it... Say, if IFace2 could "Implement" IFace1, then Class1 could Implement IFace2 and get them both ("two for the price of one") but this pretty silly, as Class1 could Implement each individually anyway. (In other words, would one have to Cast twice to get from Class1 to IFace2 and then to IFace1?? No, clearly you can do it in one shot, but that's Inheritance, not Implements...)

 

The 2nd "hole" was my misunderstanding of C# syntax, as I don't use C# very much. Well, pretty much never. So I had thought that when I see a Class declared as follows:

Class Class2: Class1, IFace2
{
}

that this meant that Class2 Inherits from Class1 and Implements IFace2. But I incorrectly assumed that this "same" concept applied to Interfaces... But since Interfaces "Implementing" each other does not make a whole heck of a lot of sense, it does make sense that the syntax has a different meaning here.

 

Thank you for helping me get my head on straight... That "Kosher" Example is very good. :) So it looks like you and Diesel were right: a mistake in the decompiler, eh?

 

Still, have a look at this Inheritance of the Object Class issue with C# vs. VB, it's pretty interesting:

 

Strange Interface Behaviour in VB.Net vs. C#

 

-- Mike

Edited by Mike_R

Posting Guidelines

 

Avatar by Lebb

  • *Experts*
Posted

Maybe I missed the original question, but he's looking at a class, not an interface and the class is just implementing the property Enabled (as required for the IScrollBar interface).

 

I don't know the VB syntax for sure, but that's my guess:

Private Function Windows.Forms.Edit.IScrollBar.get_Enabled() As Boolean Implements IScrollBar.get_Enabled
           Return MyBase.Enabled
End Function

 

So the property Enabled is being implemented in whatever class he's looking at. This covers the IScrollBar's Enabled property which must be implemented. Maybe I'm missing it though.

 

I wonder what he's disassembling, since IScrollBar doesn't appear to be a Windows related interface.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • Leaders
Posted

This is the "code" we were referring to Nerseus:

the code that im watching has the problem.

 

 

one other thing that i saw was something like this

 

interface mashed potatoes

implements gravy

end interface.

 

apparantly i cant have an implement inside of an interface?

 

And Mookie, to quote you again...

you guys are so over my head right now.[/Quote] Yes, this has become more a discussion of inheritance and implementation theory than any applicable programming concept. Quite pointless but it makes me feel like I'm smart:). Sorry.
[sIGPIC]e[/sIGPIC]
Posted

Hey Nerseus, yes, Marble_Eater's right... Posts #4-8 all flow from the statement made in Post #3.

 

Hey Mookie, sorry about the slight hijack... you did raise some interesting issues though! In short, you were wondering about Post #3 because it really isn't supposed to be possible like that. The Decompiler likely wrote "Implements" instead of "Inherits" there... a slight error.

 

Care to tell us what you are decompiling/looking at?

Posting Guidelines

 

Avatar by Lebb

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...