views:

64

answers:

3

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 want to instantiate.

Ideas?

A: 

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.

womp
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 want to instantiate.Ideas?
Pierluc
Hmm, interesting. I take it back, there may be no easier approach ;) You might try the the suggestion from this thread by tvanfosson: http://stackoverflow.com/questions/249222/can-i-add-extension-methods-to-an-existing-static-class. If you didn't want to use a wrapper class though, it might be more worthwhile for you to spend the time to tweak the code generation.
womp
A: 

[Moved to question]

Pierluc
A: 

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.

Pharabus
And if you had read my answer you would have known.
Henk Holterman