C# GetManifestResourceStream load JSON code example

Example: c# read resource json

// parameter "name" is a name of your file
        // for example: employees.json
        // execution: ReadResource("employees.json");
	public static string ReadResource(string name)
        {
            var assembly = Assembly.GetExecutingAssembly();
            string resourcePath = name;
            if (!name.StartsWith(nameof(Readjson)))
                resourcePath = assembly.GetManifestResourceNames()
                    .Single(str => str.EndsWith(name));
            Stream stream = assembly.GetManifestResourceStream(resourcePath);
            StreamReader reader = new StreamReader(stream);
            return reader.ReadToEnd();
        }