Show / Hide Table of Contents

Class EmbeddedTextFileReaders

This static class exposes methods for loading text from custom resources that are embedded in an assembly.

Inheritance
System.Object
EmbeddedTextFileReaders
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: WizardWrx
Assembly: WizardWrx.Common.dll
Syntax
public static class EmbeddedTextFileReaders

Methods

| Improve this Doc View Source

LoadBinaryResourceFromAnyAssembly(String, Assembly)

Load the named embedded binary resource into a byte array.

Declaration
public static byte[] LoadBinaryResourceFromAnyAssembly(string pstrResourceName, Assembly pasmSource)
Parameters
Type Name Description
System.String pstrResourceName

Specify the external name of the file as it appears in the source file tree and the Solution Explorer.

System.Reflection.Assembly pasmSource

Supply a System.Reflection.Assembly reference to the assembly that contains the embedded resource.

Returns
Type Description
System.Byte[]

If the function succeeds, it returns a byte array containing the raw bytes that comprise the embedded resource. Hence, this method can load ANY embedded resource.

Remarks

Since all other resource types ultimately come out as byte arrays, the text file loaders call upon this routine to extract their data.

The notes in the cited reference refreshed my memory of observations that I made and documented a couple of weeks ago. However, it was a lot easier to let Google find a reference document, which was intended for students in the Computer Science department at Columbia University, at http://www1.cs.columbia.edu/~lok/csharp/refdocs/System.IO/types/Stream.html"/>, than find my own source.

Exceptions
Type Condition
System.Exception

An Exception (the base Exception type) arises when the method is called with a pstrResourceName value that cannot be found in the pasmSource assembly. When the exception arises during the read operation, the generic Exception wraps an InvalidDataException exception, which is returned as its InnnerException property.

| Improve this Doc View Source

LoadTextFileFromAnyAssembly(String, Assembly)

Load the lines of a plain ASCII text file that has been stored with a specified assembly as a embedded resource into an array of native strings.

Declaration
public static string[] LoadTextFileFromAnyAssembly(string pstrResourceName, Assembly pasmSource)
Parameters
Type Name Description
System.String pstrResourceName

Specify the absolute (fully qualified) resource name, which is its source file name appended to the default assembly namespace name.

System.Reflection.Assembly pasmSource

Pass in a reference to the Assembly from which you expect to load the text file. Use any means at your disposal to obtain a reference from the System.Reflection namespace.

Returns
Type Description
System.String[]
See Also
LoadTextFileFromCallingAssembly(String)
LoadTextFileFromEntryAssembly(String)
| Improve this Doc View Source

LoadTextFileFromCallingAssembly(String)

Load the lines of a plain ASCII text file that has been stored with the assembly as a embedded resource into an array of native strings.

Declaration
public static string[] LoadTextFileFromCallingAssembly(string pstrResourceName)
Parameters
Type Name Description
System.String pstrResourceName

Specify the absolute (fully qualified) resource name, which is its source file name appended to the default assembly namespace.

Returns
Type Description
System.String[]

The return value is an array of Unicode strings, each of which is the text of a line from the original text file, sans terminator.

See Also
LoadTextFileFromEntryAssembly(String)
| Improve this Doc View Source

LoadTextFileFromEntryAssembly(String)

Load the lines of a plain ASCII text file that has been stored with the assembly as a embedded resource into an array of native strings.

Declaration
public static string[] LoadTextFileFromEntryAssembly(string pstrResourceName)
Parameters
Type Name Description
System.String pstrResourceName

Specify the fully qualified resource name, which is its source file name appended to the default application namespace.

Returns
Type Description
System.String[]

The return value is an array of Unicode strings, each of which is the text of a line from the original text file, sans terminator.

See Also
LoadTextFileFromCallingAssembly(String)
| Improve this Doc View Source

NameValueCollectionFromEmbbededList(String, String)

Construct a NameValueCollection from the tab delimited list read from a text file stored in an embedded resource.

Declaration
public static NameValueCollection NameValueCollectionFromEmbbededList(string pstrUnqualifiedResourceName, string pstrExpectedLabelRow)
Parameters
Type Name Description
System.String pstrUnqualifiedResourceName

Specify the name of the text file as it appears in the Solution Explorer (or the Windows Explorer, for that matter).

IMPORTNAT: The file must be marked as an embedded resource; do this in the Solution Explorer by displaying the properties of the file.

System.String pstrExpectedLabelRow

The specified string is checked against the label row; unless both are identical, the resource is assumed to be corrupted, and the method throws an exception and croaks.

Returns
Type Description
System.Collections.Specialized.NameValueCollection

If the method succeeds, it returns a NameValueCollection of key/value pairs that contains exactly one value per key.

Exceptions
Type Condition
System.ArgumentException

And ArgumentException is thrown when the data file referenced by pstrUnqualifiedResourceName contains duplicate keys, if one of the records contains two or more values, or the input file is empty. The messages attached to the exceptions are explicit about which of the three conditions caused the exception, and they attempt to provide enough detail to enable the programmer to quickly identify and resolve the problem.

| Improve this Doc View Source

StringFromANSICharacterArray(Byte[])

Transform an array of bytes, each representing one ANSI character, into a string.

Declaration
public static string StringFromANSICharacterArray(byte[] pabytWholeFile)
Parameters
Type Name Description
System.Byte[] pabytWholeFile

Specify the array to transform.

Returns
Type Description
System.String

The pabytWholeFile array is returned as a string.

Remarks

I did this refactoring, thinking that I had a new use for the code, only to realize as I finished cleaning it up that I can't use it, because it deals in ANSI characters, and my present need involves Unicode characters. Nevertheless, the exercise is not a total loss, because it reminded me of the trick that I needed to transform the array of Unicode characters into a string.

| Improve this Doc View Source

StringOfLinesToArray(String)

Split a string containing lines of text into an array of strings.

Declaration
public static string[] StringOfLinesToArray(string pstrLines)
Parameters
Type Name Description
System.String pstrLines

String containing lines of text, terminated by CR/LF pairs.

Returns
Type Description
System.String[]

Array of strings, one line per string. Blank lines are preserved as empty strings.

| Improve this Doc View Source

StringOfLinesToArray(String, StringSplitOptions)

Split a string containing lines of text into an array of strings, as modified by the StringSplitOptions flag.

Declaration
public static string[] StringOfLinesToArray(string pstrLines, StringSplitOptions penmStringSplitOptions)
Parameters
Type Name Description
System.String pstrLines

String containing lines of text, terminated by CR/LF pairs.

System.StringSplitOptions penmStringSplitOptions

A member of the StringSplitOptions enumeration, presumably other than StringSplitOptions.None, which is assumed by the first overload. The only option supported by version 2 of the Microsoft .NET CLR is RemoveEmptyEntries.

Returns
Type Description
System.String[]

Array of strings, one line per string. Blank lines are preserved as empty strings unless penmStringSplitOptions is RemoveEmptyEntries, as is most likely to be the case.

Remarks

Use this overload to convert a string, discarding blank lines.

| Improve this Doc View Source

StringToArray(String)

Return a one-element array containing the input string.

Declaration
public static string[] StringToArray(string pstr)
Parameters
Type Name Description
System.String pstr

String to place into the returned array.

Returns
Type Description
System.String[]

Array of strings, containing exactly one element, which contains the single input string.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX