Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new keyword wierdness

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
0
0
GB
Hi All

I am experiencing some very strange behavior with the new keyword when using it as a modifier not an operator.

Background:
I'm working on a fairly complex multi project web application with a tiered architecture. There is a code gen application another contractor brought with them onto the project which is used to generate the database and some business objects from an XSD (well its XML but its acting like an XSD) which has been in place long before i joined.

Architecture:
So we have set of base classes which are code genned and then some derived classes in which we can specialise the implementation and apply business rules. The data access is all handled in a library that comes with the code gen.

Problem:
I need to override the implementation of a base class Property in the derived class but the base member (remember this is code genned so I can't just change it!) is not virtual. Enter the new keyword or so you would think, heres some psuedo code..
Code:
public class A{
  public string S{
    return "base";
  }
}
public class B{
  new public string S{
    return "derived";
  }
}
public class C{
  public C(){
    B b = new B();
    Console.WriteLine(b.S);
  }
}

output: base

[code]
Anybody got any idea what is happening here,I  mean knock up a console application with the code above and you will see that the output should be derived. Open the docs, or any C# book of your choice and the output should be derived.

I restarted the IDE, forced a rebuild of all projects, got latest version, bathed in bat blood, paid homage to the god of xml serialisation and binary formatting and I still end up in the base class when I step through in the debugger.

Someone help, how can you break the C# specification?

[i]i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...[/i]
 
Forget it :) I spent the 40 minutes or so it takes to get all the solution from source safe again and start with completely fresh dlls for everything (excepting 3rd party stuff of course) and voila its pushed it through...

Must just be something buggy with VS.NET, I could understand if none of the changes the assembly with the new member in were made but it seems really odd that I can change the class such as adding a method and that gets compiled into the new build, but I add a modifier and it doesn't....

If anyone wants to explain that one to me, or alternatively send me unlimited licenses for VS 200? (who knows when it will arrive) and a client prepared to take a chance on a new platform (who knows when i'll get to use before 9PM even when it does go live) then that would be great :)

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top