Skip to content

NSG.Library.Helpers

Phil Huhn edited this page Apr 18, 2019 · 5 revisions

NSG.Library.Helpers is a collection of support helper (static) methods. The helper methods are in four classes as follows:

  • App setting configuration retrieval (Config),
  • Files and file system utilities (Files),
  • Operation system (OS) command execution (OS).
  • System extensions.

Table of Contents

Assembly: NSG.Library.Helpers

Namespace: NSG.Library.Helpers

The namespace contains a collection of static helper methods.


Class: Config

Static helpers for handling AppSettings configuration.

Methods

GetStringAppSettingConfigValue(System.String,System.String)

Parameters
configAppKey

AppSetting key value

defaultValue

if not found return this value Get a value from the AppSetting section of the web config.

Return Value

string of the value in the appSetting section in the config file.


GetBoolAppSettingConfigValue(System.String,System.Boolean)

Parameters
configAppKey

AppSetting key value

defaultValue

if not found return this boolean value Get a value from the AppSetting section of the web config.

Return Value

boolean value in the appSetting section in the config file.


GetIntAppSettingConfigValue(System.String,System.Int32)

Parameters
configAppKey

AppSetting key value

defaultValue

if not found return this integer value Get a value from the AppSetting section of the web config.

Return Value

integer value in the appSetting section in the config file.


Class: Files

Static helpers for handling files.

Methods

TempFileName(System.String,System.String)

Parameters
prefix

first part of file name For example: file 'prefix' examples:

  • tmp
  • ni (as in app initials)
  • nsg (as in company initials)
extent

the temporary file name extension: For example: file 'extent' examples:

  • txt
  • tmp
  • log
Create a temporary file name.
Return Value

string of prefix followed by GUID and extent


DeleteFile(System.String)

Parameters
fullFilePathAndName

full path and file name Delete the file


MakeDirectory(System.String)

Parameters
directoryName

name of the new direcory Make a directory


FileToByteArray(System.String)

Parameters
filePath

full path and file name Read a file into a in-memory byte array.

Return Value

byte array Remarks: The opposite of ByteArrayToFile


ByteArrayToFile(System.Byte[],System.String)

Parameters
file

byte array

fullFileName

full path and file name Write a file from an in-memory byte array. Remarks: The opposite of FileToByteArray


FileNameCleaner(System.String)

Parameters
fileName

file name with out path Remove the following reserved characters and replace with a space.

  • (less than)
  • > (greater than)
  • : (colon)
  • " (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)
  • , (comma)
  • (amperstand)
Return Value

A clean file name






Class: OS

Static helpers for handling Operating System interaction.

Methods

CallOperatingSystemCmd(System.String,System.String)

Parameters
cmdStr

The command string to execute in the operating system.

workingDirectory

The base directory to start the OS command. Execute the operating system command.

Return Value

String of the output of the command.


Class: System.Extensions

Static helpers extension methods, namespaced to system, so it extends system class if included.

Methods

GetName(System.Enum)

Parameters
value

an enum value Get simple name of the enum value

Return Value

string of literal name of the enum


GetDescription(System.Enum)

Parameters
value

an enum value Convert the enum description to the literal name of the enum. [System.ComponentModel.Description("Warehouse]Shipping

Return Value

string of literal description of the enum


GetValues``1(System.Type)

Parameters
T

an enum type

enumType

an enum type Get an enumeration of the enum type

Return Value

IEnumerable of T


ToDictionary(System.Type)

Parameters
enumType

an enum type Dictionary of all values and descriptions

Return Value

Dictionary of all values and descriptions