public static ValidateStringIsNullOrEmpty ( string data, string messageData, bool useDefaultMessage = true ) : void | ||
data | string | string variable to validate |
messageData | string | This parameter is used when the validation fails. It can contain actual message to display /// or parameter name to display with default message |
useDefaultMessage | bool | Indicates either to use messageData as actual message or parameter name |
리턴 | void |
/// <summary> /// Ensures that a directory exists beofre attempting to write a file /// </summary> /// <param name="pathName">The path to the file that will be created</param> public static void EnsureDirectoryExists(string pathName) { Validate.ValidateStringIsNullOrEmpty(pathName, "Settings directory"); string directoryPath = Path.GetDirectoryName(pathName); if (!DataStore.DirectoryExists(directoryPath)) { DataStore.CreateDirectory(directoryPath); } }
public static void SerializeXmlFile <T>(T obj, string fileName) { Validate.ValidatePathName(fileName, string.Format(Resources.PathDoesNotExistForElement, string.Empty, fileName)); Validate.ValidateStringIsNullOrEmpty(fileName, string.Empty); XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); Encoding encoding = GetFileEncoding(fileName); using (TextWriter writer = new StreamWriter(new FileStream(fileName, FileMode.Create), encoding)) { xmlSerializer.Serialize(writer, obj); } }
public static void SerializeXmlFile <T>(T obj, string fileName) { Validate.ValidatePathName(fileName, String.Format(Resources.PathDoesNotExistForElement, String.Empty, fileName)); Validate.ValidateStringIsNullOrEmpty(fileName, String.Empty); XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); StringBuilder sBuilder = new StringBuilder(); using (StringWriter writer = new StringWriter(sBuilder)) { xmlSerializer.Serialize(writer, obj); } FileUtilities.DataStore.WriteFile(fileName, sBuilder.ToString(), Encoding.Unicode); }
public static X509Certificate2 GetCertificateFromStore(string thumbprint) { Validate.ValidateStringIsNullOrEmpty(thumbprint, "certificate thumbprint"); X509Certificate2Collection certificates; if (TryFindCertificatesInStore(thumbprint, StoreLocation.CurrentUser, out certificates) || TryFindCertificatesInStore(thumbprint, StoreLocation.LocalMachine, out certificates)) { return(certificates[0]); } else { throw new ArgumentException(string.Format(Resources.CertificateNotFoundInStore, thumbprint)); } }