本文整理汇总了C#中System.String.Name方法的典型用法代码示例。如果您正苦于以下问题:C# String.Name方法的具体用法?C# String.Name怎么用?C# String.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDirectoryEmpty
public static Boolean IsDirectoryEmpty(String path)
{
path.Name("path").NotNullEmptyOrOnlyWhitespace();
return IsDirectoryEmpty(new DirectoryInfo(path));
}
示例2: SafelyCreateEmptyFile
public static void SafelyCreateEmptyFile(String filename)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
CreateEmptyFile(filename, Overwrite.No);
}
示例3: DeleteEmptyDirectories
public static void DeleteEmptyDirectories(String path)
{
path.Name("path").NotNullEmptyOrOnlyWhitespace();
DeleteEmptyDirectories(new DirectoryInfo(path));
}
示例4: GetMD5Checksum
public static String GetMD5Checksum(String filename)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
return GetMD5Checksum(fs);
}
示例5: GetBracketedSqlIdentifier
"Unicode",
"Until",
"Where"
};
private static Configuration _configuration;
private static Boolean _isInitialized = false;
private static List<String> _targetLanguageKeywords;
#endregion Fields
#region Methods
/// <summary>
/// Given a T-SQL identifier, return the same identifier with all of its
/// constituent parts wrapped in square brackets.
/// </summary>
public static String GetBracketedSqlIdentifier(String identifier)
{
identifier.Name("identifier").NotNullEmptyOrOnlyWhitespace();
Func<String, String> wrap = s => s.Any() ? String.Concat("[", s.Trim(_brackets), "]") : "";
return
identifier
/* Keep empty array elements, because parts of a multi-part T-SQL identifier
can be empty (e.g. "server.database..object", where the schema name is omitted). */
.Split(".".ToCharArray(), StringSplitOptions.None)
.Select(element => wrap(element))
.Join(".");
}
public static String GetStrippedSqlIdentifier(String identifier)
{
return identifier.Replace("[", "").Replace("]", "");
}
/// <summary>
/// Convert an SQL identifier, like a database name or column name, into a valid
/// identifier for the target language (C#, F#, etc.) that was set in
/// the configuration.
/// <para>NOTE: IdentifierHelper.Init() must be called before this method is called for the first time, otherwise an exception will be thrown.</para>
/// <para>System.dll has code providers for both C# (Microsoft.CSharp.CSharpCodeProvider) and
/// Visual Basic (Microsoft.VisualBasic.VBCodeProvider). Why not use code from those classes
/// to determine if a given string is a valid identifier?</para>
/// <para>There are several reasons. One is that .Net does not provide a corresponding F# code provider.
/// The second reason is that the code providers' CreateValidIdentifier() method
示例6: CreateEmptyFile
public static void CreateEmptyFile(String filename, Overwrite overwrite)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
if ((overwrite == Overwrite.Yes) || !File.Exists(filename))
{
using (var fs = File.Create(filename))
{
/* Create an empty file. */
}
}
}
示例7: GetImageFormatFromFileExtension
public static ImageFormat GetImageFormatFromFileExtension(String filename)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
var fileExtension = GetFileExtension(filename);
switch (fileExtension)
{
case "bmp":
return ImageFormat.Bmp;
case "emf":
return ImageFormat.Emf;
case "exif":
return ImageFormat.Exif;
case "gif":
return ImageFormat.Gif;
case "icon":
return ImageFormat.Icon;
case "jpg":
case "jpeg":
return ImageFormat.Jpeg;
case "png":
return ImageFormat.Png;
case "tif":
case "tiff":
return ImageFormat.Tiff;
case "wmf":
return ImageFormat.Wmf;
default:
throw new Exception(String.Format(Properties.Resources.Graphics_BadFileExtension, fileExtension));
}
}
示例8: WriteMemoryStreamToFile
public static void WriteMemoryStreamToFile(String filename, MemoryStream ms)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
ms.Name("ms").NotNull();
using (var fs = File.Create(filename))
ms.WriteTo(fs);
}
示例9: Item
public Item(String pathname)
: this()
{
pathname.Name("pathname").NotNullEmptyOrOnlyWhitespace().FileExists();
var fileContents = File.ReadAllText(pathname);
this.Filename = Path.GetFileName(pathname);
this.Pathname = pathname;
this.SchemaName = "";
this.ObjectName = "";
this.FileContentsMD5Hash = fileContents.MD5Checksum();
this.Type = _userDefinedTableTypeRegex.IsMatch(fileContents) ? "TT" : " ";
this.NeedsToBeCompiled = true;
this.IsPresentOnServer = false;
this.DropOrder = 0;
this.NeedsToBeDropped = false;
}
示例10: GetContentTypeFromFileExtension
public static String GetContentTypeFromFileExtension(String filename)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
var fileExtension = GetFileExtension(filename);
if (String.IsNullOrWhiteSpace(fileExtension))
throw new Exception(String.Format(Properties.Resources.Graphics_EmptyFileExtension, filename));
else
return "image/" + fileExtension;
}
示例11: AddFolder
public void AddFolder(String folder, String filemask = "*.*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
{
folder.Name("folder").NotNullEmptyOrOnlyWhitespace().DirectoryExists();
filemask.Name("filemask").NotNullEmptyOrOnlyWhitespace();
filemask = filemask.Trim();
var pathnames = Directory.EnumerateFiles(folder, "*", searchOption);
if ((filemask == "*") || (filemask == "*.*"))
{
this.AddFiles(pathnames);
}
else
{
/* Directory.EnumerateFiles()'s searchPattern parameter has an odd behavior
when matching pathname extensions.
(Read the "Remarks" section at https://msdn.microsoft.com/en-us/library/dd413233%28v=vs.110%29.aspx).
That odd (IMO buggy) behavior is avoided by converting the filemask to an equivalent
regular expression. */
var filemaskRegexPattern =
filemask
/* Escape all regex-related characters except '*' and '?'. */
.RegexEscape('*', '?')
/* Convert '*' and '?' to their regex equivalents. */
.Replace('?', '.')
.Replace("*", ".*?");
var _saneFilemaskRegex = new Regex(filemaskRegexPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
this.AddFiles(pathnames.Where(f => _saneFilemaskRegex.IsMatch(Path.GetFileName(f))));
}
}
示例12: AddFile
public void AddFile(String pathname)
{
pathname.Name("pathname").NotNullEmptyOrOnlyWhitespace().FileExists();
this._pathnames.Add(Path.GetFullPath(pathname));
}
示例13: GetUrlAsRoot
public static String GetUrlAsRoot(String url)
{
url.Name("url").NotNull();
if (url.StartsWith("~/"))
return url;
else if (url.StartsWith("/"))
return "~" + url;
else
return "~/" + url;
}
示例14: Touch
public static void Touch(String filename)
{
filename.Name("filename").NotNullEmptyOrOnlyWhitespace();
Touch(filename, DateTime.Now);
}
示例15: ShellExecute
/// <summary>
/// Passes the given command to the shell and executes it.
/// </summary>
/// <param name="command">
/// String containing a valid shell command.
/// </param>
/// <exception cref="System.ArgumentException">
/// Thrown if the command parameter is null or empty.
/// </exception>
public static void ShellExecute(String command)
{
command.Name("command").NotNullEmptyOrOnlyWhitespace();
var browser = new Process();
browser.StartInfo.FileName = command;
browser.Start();
}