3 ms·
I've used this in other languages and I don't like it. It's the wrong approach to solving the problem. As soon as I want to embed some multi-line string in my
by wvenable 5y ago
I've used this in other languages and I don't like it. It's the wrong approach to solving the problem. As soon as I want to embed some multi-line string in my code then I'd be better of just having it in it's own file.
.NET does allow you embed files directly into your project and read in those files but it's a lot of confusing boilerplate.
If .NET provided a really easy way to take a file from the project and create a compile-time string from it then I think that would be significantly more useful than this proposal.
- hackerfromthefu 5y agoI like this solution, and agree it would be much better for most cases. C# is beginning to suffer from over-complexity at the language layer, and this solution of making it trivial to reference embedded text files avoid adding more complexity. That said, it's actually pretty easy to reference embedded text files already, not trivial but easy enough.
- bob1029 5y ago> .NET does allow you embed files directly into your project and read in those files but it's a lot of confusing boilerplate. I think "a lot" is a bit of overstatement considering the amount of power you have here. My implementations around embedded resources usually look like this same set of 5 lines: var assembly = Assembly.GetExecutingAssembly(); using var stream = assembly.GetManifestResourceStream("My.Embedded.Resource.png"); using var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); var myPngBytes = memoryStream.ToArray();