开发者

Prevent(manually entered) Code Removal in Resources.Designer

I've added a small function in the Resources.Designer.cs and it working great, the problem is that when I add or remove something from the Resources.resx this function always get removed, is there any indicator I could put or anyway to bypass this?

Thank you!


It is a really simple method used as an indexer.

internal static string Keys(string key) 
{ 
   return ResourceManager.GetString(key, resourceCulture); 
} 

I've done that because you can't do Properties.Resources and then concat a value. An extension could work, however I tried and it gets fancy because it's all static method and you dont开发者_JAVA技巧 want to instantiate.

Ideas?


The code portion of a resx file is autogenerated by a tool called PublicResXFileCodeGenerator (or InternalResXFileCodeGenerator, depending on what you've set the resource file visibility to). It says right at the top of the file:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

If you really need to get around this, you'll need to subclass the PublicResXFileCodeGenerator (the tool that VS runs to generate the resx code), and implement your own tool that Visual Studio can run every time it wants to refresh a resource file.

Overriding the tool would allow you to generate partial classes, and then you could store your customized code in another .cs file somewhere as another partial class to the resource file class.

Honestly though, there's probably easier approaches. What's the custom code that you're implementing? Can you just turn it into extension methods? A bit more detail might help us point you in a better direction.


i can't verify at the moment but if the autogenerated class is a partial class, create a matching partial class in another .cs file and add any ammendments to that

edit

confirmed the designer class for resx is not partial (seem it should be as a generated file?) so an extension method is probably the best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜