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!

Code in Resources.Designer.cs is automatically generated. Any code you put in there will be overwritten each time any change is made to the Resources file.

You could try making Resources partial and put your function in a seperate file.
This way only the partial key word is removed; you will still have to manualy put this back each time Resources are edited but at least you do not loose your code.
In Resources.Designer.cs

internal partial class Resources { //<-- add partial to Resources

In new class file

namespace MyProject.Properties
{
    partial class Resources
    {
        internal static void MyFunc()
        { 
            // do something
        }
    }
}

Your problem is that

Code in Resources.Designer.cs is automatically generated.

You might be able to do something using Extensibility (e.g. create an AddIn that monitors for changes to the Resouces.Designer.cs) but I'm not sure it is possible and is probably ott for what you want.

Note: The partial keyword is used to enable two (or more) source files to define a single class. The forms designer uses this to seperate user and autogenerated code.

Edited 6 Years Ago by nick.crane: n/a

You can also try deriving from Resouces

namespace MyProject.Properties
{
    class MyResources : Resources
    {
        internal static void MyFunc()
        {
            // do something
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.