Overriding a Properties getter...

Topics: Developer Forum, User Forum
Mar 21, 2007 at 3:25 PM
MetaAssembly assembly = new MetaAssembly("WindowsApplication1");
MetaType type = assembly.DefineType("Customer");

MetaProperty prop = type.OverrideProperty(typeof(Customer), "Name");
MetaMethod method = prop.GetMethod;
ImperativeCodeBuilder cb = new ImperativeCodeBuilder(method);
MetaExpression[] parms = new MetaExpression[] {2};
//MetaMethod method2 = type.OverrideMethod(typeof(Name), "GetName");
cb.CallStatic(typeof(Name),"GetName",parms );
//VariableReference countRef = cb.Declare("count", typeof(int), method.Arguments0);
Customer c = type.CreateInstance() as Customer;
textBox1.Text = c.Name;

Basically what I am trying ot do is override the getter to call a static method Name.GetName(2) from the Customers Name property.

I get an exception that says:

Method 'get_Name' on type 'Customer' from assembly 'WindowsApplication1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' must be virtual to implement a method on an interface or super type.":"Customer

I'd like to not have to modify existing customer class/or Name class

thanks very much in advance