
Detected the class name Profiler and set this as the project file name. This is how I would do it using the Add Class Using Clipboard feature. When it comes time to profile a codebase, I copy the Profiler class to the clipboard and then add it to the codebase I am working on. It's simple and crude but very effective. Outputs "MyFile.cs | MyMethod took 20.45ms" To accomplish this, I have a profiler gist stored on GitHub that measures a code section using the IDisposable pattern. Over the years I have worked on many different codebases and a common task I perform is profiling code sections when diagnosing performance issues. Encapsulated the class in a new namespace using our projects default namespace and folder path. Detected the class name FontAwesomeIcons and set this as the project file name. When the tool added the FontAwesomeIcons class, it automatically did the following:
We first copy the class to the clipboard and then, in Visual Studio, right click on our project and choose Add Class Using Clipboard. Say we have generated our C# font glyph class using IconFont2Code, the next step is to add the class to our code base. To really see the benefits of this feature, let's examine two use cases:Īs a lover of icon fonts, one of my favourite sites is IconFont2Code, a tool that generates a C# class with named string constants for all glyphs in a font asset. This let's us quickly and easily add a class by copy/pasting, avoiding any additional cleanup after we paste the class into a file. The tool will automatically detect the file name based on the clipboards class, correct or create the namespace based on project and folder you are creating it from and then generates a new project file. When a C# class is in the clipboard, the Add Class Using Clipboard will appear in the solution pads right click menu below the Add menu. To simplify this, MFractor now includes the Add Class Using Clipboard tool, allowing you to create a new project file using the clipboards content. This involves a lot of steps and a lot of manual cleanup work, making it error prone and tedious.
Cleanup the namespace to match the folder path. Ensure the file name to match the class name. Open your project and create a new file. When we add a class to our codebase using copy/paste, we usually do something like: Let's be honest, we all do this from time to time 🙈 An online code-generation tool like QuickType or IconFont2Code. This class may come from a wide range of sources such as: When working as developers, a common workflow is copy/pasting a class from an external source into our codebase. Generate a new class file using the contents of the clipboard in Visual Studio Mac.