简体   繁体   中英

How to remove a property from a custom user control

A property was added to a custom user control. Since then, Visual Studio has inserted generated code to every form that uses that user control. Now we want to remove that property because it is not going to be used. But obviously doing so causes compile errors. Is there a way to tell Visual Studio to remove the property from all that generated code? It seems to me that putting something like [Obsolete()] should be enough to tell Visual Studio to remove it from the generated code. Is there some other way?

Look at DesignerSerializationVisibilityAttribute , especially the DesignerSerializationVisibility.Hidden option.

Caveat: Unfortunately you will have to open every form/control in design mode so the code can be regenerated (if it does not do so already).

You can try to use some refactoring tool, like Resharper.

http://www.jetbrains.com/resharper/

Adding the "Obsolete" atribute will only generate a compiler warning, but wont remove any code.

Regex to the rescue! What I usually do is open Replace in Files dialog (Ctrl+Shift+H), check Use Regular Expressions checkbox and replace instances of .+\\.SomeProperty.+ with empty string.

Be sure to commit your changes to repository before this, so you can revert to working state if anything goes wrong.

只需将其标记为Obsolete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM