I have an extension method I’m trying to make generic, for message passing.
public static ActionResult RedirectCompanyMessage<T>(this Controller controller, T mObject, Company company)
{
var msg = mObject.ToString()
...
}
the mObject.ToString() is returning junk like System.Data.Entity.DynamicProxies.SerialCode_960A5FEF6FE5426EE5F55B8627454C71E7D088921143DE49B208E7FED043ADA5
But, the base type (the proxy type?) has an overridden ToString().
public partial class SerialCode
{
//Prints the serial code with dashes every 5 chars
public new String ToString()
{
return Utility.Utility.FormatSerial(this.Serial);
}
}
So, what’s the deal? During debugging, if I hover over “T”, visual studio shows T mObject as the correct Models.SerialCode, but if I run mObject.GetType() in the immediate window I see FullName = "System.Data.Entity.DynamicProxies.SerialCode_960A5F...
I just want to be able to reliably run the overridden ToStrings() in all my partial classes.
The problem is that you didn’t “override”
.ToString(); you reintroduced it withnew. If you want to override, useoverride, notnew.