/// <summary> /// This method returns a list of Files /// </summary> public static List <string> AddFiles(List <string> sourceFiles, List <string> filesToAdd) { // initial value List <string> files = null; // If the sourceFiles object exists if (NullHelper.Exists(sourceFiles)) { // Set the return value to the sourceFiles so far files = sourceFiles; } else { // Create the return value files = new List <string>(); } // At this point the files return value has to exist // If the filesToAdd collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(filesToAdd)) { // Iterate the collection of string objects foreach (string file in filesToAdd) { // Add this file files.Add(file); } } // return value return(files); }
/// <summary> /// This method returns an enumeration value for the enumValueString given /// </summary> /// <typeparam name="T"></typeparam> /// <param name="enumValueAsString"></param> /// <returns></returns> public static T GetEnumValue <T>(string enumValueAsString, object notFoundValue) { // set the return value T enumValue = (T)notFoundValue; // Get the enumValues List <T> enumValues = GetEnumValues <T>(); // If the enumValues collection exists and has one or more items if ((ListHelper.HasOneOrMoreItems(enumValues)) && (TextHelper.Exists(enumValueAsString))) { // itereate the enumValues foreach (T tempEnumValue in enumValues) { // if this is the enum being sought if (tempEnumValue.ToString().ToLower() == enumValueAsString.ToLower()) { // set the return value return(tempEnumValue); } } } // return value return(enumValue); }
/// <summary> /// This method is used to check if a List of numbers is greater than or equal to the min /// and less than or equal to the max. /// </summary> /// <param name="number"></param> /// <param name="min"></param> /// <param name="max"></param> /// <returns></returns> public static bool IsInRange(List <Decimal> numbers, Decimal min, Decimal max) { // set the return value bool isInRange = false; // If the numbers collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(numbers)) { // set to true now isInRange = true; // Iterate the collection of Decimal objects foreach (Decimal number in numbers) { // if NOT in range if (!IsInRange(number, min, max)) { // set to false isInRange = false; // break out of loop break; } } } // return value return(isInRange); }
/// <summary> /// This method returns the Text Lines, with Environment.NewLine appended after each line. /// </summary> /// <param name="lines">A collection of TextLines to rebuild into a file or block'</param> /// <param name="mustContainText">If present, a line must have this to be added.</param> /// <param name="mustNotContainText">If present, a line with will not be added</param> public static string ExportTextLines(List <TextLine> lines, string mustContainText = "", string mustNotContainText = "") { // initial value string result = ""; // locals bool mustContain = TextHelper.Exists(mustContainText); bool mustNotContain = TextHelper.Exists(mustNotContainText); bool addLine = false; // If the lines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(lines)) { // Create a new instance of a 'StringBuilder' object. StringBuilder sb = new StringBuilder(); // Iterate the collection of TextLine objects foreach (TextLine line in lines) { // reset, default to true addLine = true; // if the value for mustContain is true if (mustContain) { // add line is true if this string contains the mustContainText addLine = line.Text.Contains(mustContainText); } // if addLine is true,a nd the mustNotContain is true if (addLine && mustNotContain) { // if the line contains the mustNotContainText if (line.Text.Contains(mustNotContainText)) { // do not add this line addLine = false; } } // if addLine is true if (addLine) { // Add this line sb.Append(line.Text); // Add a NewLine char sb.Append(Environment.NewLine); } } // Set the result result = sb.ToString(); } // return value return(result); }
/// <summary> /// This method returns a list of file names. /// </summary> /// <param name="files">The files must be passed in by reference because this method calls itself over and over and over and over, so use caution on where you call this.</param> /// <param name="directoryPath">The path to the Directory containing the files</param> /// <param name="filterExtensions">This override accepts a list of filters instead of just one so that mutliple types can be found</param> /// will be returned.</param> /// <param name="removeExtension">If true, the extension is removed</param> /// <returns></returns> public static List <string> GetFilesRecursively(string directoryPath, ref List <string> files, List <string> filterExtensions = null, bool removeExtension = false) { // locals List <string> tempFiles = null; List <string> directories = null; // If the filePath string exists if ((TextHelper.Exists(directoryPath)) && (Directory.Exists(directoryPath))) { // get the files tempFiles = GetFiles(directoryPath, filterExtensions, removeExtension); // Add the files that were found (if the source files do not exist, they will be created) files = AddFiles(files, tempFiles); // get a list of directories directories = Directory.GetDirectories(directoryPath).ToList(); // If the directories collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(directories)) { // Iterate the collection of string objects foreach (string directory in directories) { // get the files tempFiles = GetFilesRecursively(directory, ref files, filterExtensions, removeExtension); //// if any files were found //if (ListHelper.HasOneOrMoreItems(tempFiles)) //{ // // Add the files that were found (if the source files do not exist, they will be created) // files = AddFiles(files, tempFiles); //} } } } // return value return(files); }
/// <summary> /// This method creates a new list, and ensure the members are In Range from the source values /// </summary> public static List <Decimal> EnsureInRange(List <Decimal> values, Decimal minValue, Decimal maxValue) { // initial value List <Decimal> newList = null; // If the values collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(values)) { // create a new list newList = new List <Decimal>(); // iterate the list foreach (Decimal value in values) { // Add this value newList.Add(EnsureInRange(value, minValue, maxValue)); } } // return value return(newList); }
/// <summary> /// This method returns a list of file names. /// </summary> /// <param name="directoryPath">The path to the Directory containing the files</param> /// <param name="filterExtensions">This override accepts a list of filters instead of just one so that mutliple types can be found</param> /// will be returned.</param> /// <param name="removeExtension">If true, the extension is removed</param> /// <returns></returns> public static List <string> GetFiles(string directoryPath, List <string> filterExtensions = null, bool removeExtension = false) { // initial value List <string> files = new List <string>(); // local string extension = ""; // If the filePath string exists if ((TextHelper.Exists(directoryPath)) && (Directory.Exists(directoryPath))) { // get the fileNames string[] fileNames = Directory.GetFiles(directoryPath); // if the fileNames exist if ((fileNames != null) && (fileNames.Length > 0)) { // if the value for removeExtension is true if (removeExtension) { // get a tempList List <string> tempNames = fileNames.ToList(); // Iterate the collection of string objects foreach (string tempName in fileNames) { // get the name without the extension string name = GetFileNameWithoutExtensionEx(tempName, ref extension); // If the filterExtension string exists if (ListHelper.HasOneOrMoreItems(filterExtensions)) { // Iterate the collection of string objects foreach (string filterExtension in filterExtensions) { // if the extension exists if (TextHelper.IsEqual(filterExtension, extension)) { // Add this file files.Add(name); } } } else { // Add this file files.Add(name); } } } // if the filterExtension exists else if (ListHelper.HasOneOrMoreItems(filterExtensions)) { // get a tempList List <string> tempNames = fileNames.ToList(); // Iterate the collection of string objects foreach (string tempName in fileNames) { // The name is not needed here, just getting the extension GetFileNameWithoutExtensionEx(tempName, ref extension); // Iterate the collection of string objects foreach (string filterExtension in filterExtensions) { // if the extension exists if (TextHelper.IsEqual(filterExtension, extension)) { // Add this file files.Add(tempName); } } } } else { // get a tempList List <string> tempNames = fileNames.ToList(); // Iterate the collection of string objects foreach (string tempName in fileNames) { // Add this file files.Add(tempName); } } } } // return value return(files); }