Help! How to make overridden method sealed using the CodeDom?

  • Thread starter Thread starter lee.chappers
  • Start date Start date
L

lee.chappers

How can I make the CodeDom generate the following C# method?

protected sealed override void Test()
{
}

I've tried using:

domMethod.Attributes = MemberAttributes.Override |
MemberAttributes.Family | MemberAttributes.Final;

but I just can't get the CodeDom to produce the "sealed" keyword...

Thanks,
- Lee
 
An overriden method is assumed to be virtual. An overriden method is not
considerred a new method but simply a redefinition of the original method it
is not allowed to change such information. Allowing such a change to occur
would logically break many things.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
Greg said:
An overriden method is assumed to be virtual. An overriden method is not
considerred a new method but simply a redefinition of the original method
it is not allowed to change such information. Allowing such a change to
occur would logically break many things.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Hi Greg,

You can seal an overridden method (with the 'sealed' keyword), in order to
stop further overriding of the method by derived classes, but remember, if
you override a method, you can still call the base class' implementation,
by means of the base.<MethodName>() syntax, inside that method... so
it /sort of/ is a new method.
 
I expect that you will find this is a CodeDOM limitation. There are many
items which cannot be expressed in codedom (even some very basic concepts
like switch statements and while loops.

Cheers,

Greg
 
Really!? No switches or while loops? Looks like I need to abandon the
CodeDom then. You'd think I'd learn and give up trying to use these
inextensible frameworks...

Thanks,
- Lee
 
Really!? No switches or while loops? Looks like I need to abandon the
CodeDom then. You'd think I'd learn and give up trying to use these
inextensible frameworks...

CodeDom supports only features that are part of every language it can
generate, so it's rarely the best choice when you want to generate code only
in a specific language. It's a shame, because some of its features, like
being able set set indentation and brace conventions for the generated
source, are very handy.
 
Back
Top