Microsoft.VsSDK.IntegrationTestLibrary.TestUtils.GetEmbeddedStringResource C# (CSharp) Method

GetEmbeddedStringResource() public static method

Gets the embedded file identified by the resource name, and converts the file into a string.
public static GetEmbeddedStringResource ( Assembly assembly, string resourceName ) : string
assembly System.Reflection.Assembly
resourceName string In VS, is DefaultNamespace.FileName?
return string
        public static string GetEmbeddedStringResource(Assembly assembly, string resourceName)
        {
            string result = null;

            // Use the .NET procedure for loading a file embedded in the assembly
            Stream stream = assembly.GetManifestResourceStream(resourceName);
            if (stream != null)
            {
                // Convert bytes to string
                byte[] fileContentsAsBytes = new byte[stream.Length];
                stream.Read(fileContentsAsBytes, 0, (int)stream.Length);
                result = Encoding.Default.GetString(fileContentsAsBytes);
            }
            else
            {
                // Embedded resource not found - list available resources
                Debug.WriteLine("Unable to find the embedded resource file '" + resourceName + "'.");
                Debug.WriteLine("  Available resources:");
                foreach (string aResourceName in assembly.GetManifestResourceNames())
                {
                    Debug.WriteLine("    " + aResourceName);
                }
            }

            return result;
        }