crazyboybert
Programmer
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..
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]