本文整理汇总了C#中System.Diagnostics.StackTrace.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# StackTrace.Substring方法的具体用法?C# StackTrace.Substring怎么用?C# StackTrace.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackTrace
的用法示例。
在下文中一共展示了StackTrace.Substring方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentMemberName
/// <summary>
/// 获取正在调用的成员的名字。
/// </summary>
/// <returns>成员名字。</returns>
public static string GetCurrentMemberName()
{
string name = new StackTrace(true).GetFrame(1).GetMethod().Name;
if (name.StartsWith("get_") == true)
{
return name.Substring("get_".Length);
}
if (name.StartsWith("set_") == true)
{
return name.Substring("set_".Length);
}
return name;
}
示例2: GetCallerMemberName
/// <summary>
/// 获取调用当前上下文的成员的名字。
/// </summary>
/// <returns>成员名字。</returns>
public static string GetCallerMemberName()
{
string name = new StackTrace(true).GetFrame(2).GetMethod().Name;
if (name.StartsWith("get_", StringComparison.Ordinal) == true)
{
return name.Substring("get_".Length);
}
if (name.StartsWith("set_", StringComparison.Ordinal) == true)
{
return name.Substring("set_".Length);
}
return name;
}
示例3: Validate
/// <summary>
/// Check validation statement for a property
/// </summary>
/// <param name="assert">
/// Validation statement
/// </param>
/// <param name="errorInfo">
/// Validation statement description
/// </param>
/// <remarks>
/// This method could only be called from methods starting with {ValidateMethodPrefix}
/// Checked property name is calculated from the caller method name.
/// </remarks>
protected void Validate(bool assert, string errorInfo)
{
string callerName = new StackTrace().GetFrame(1).GetMethod().Name;
string property = callerName.Substring(ValidateMethodPrefix.Length);
if (!assert)
{
this.AddValidationError(property, errorInfo);
}
}
示例4: GetDefaultIncludeFilename
private static string GetDefaultIncludeFilename()
{
string filename;
try
{
filename =
new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
filename = Path.Combine(
Path.GetDirectoryName(filename),
Path.GetFileNameWithoutExtension(filename) + "_Include.txt");
if ((!File.Exists(filename)) ||
string.IsNullOrEmpty(Application.dataPath))
{
return null;
}
}
catch
{
return null;
}
filename = filename.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
string dataPath = Application.dataPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
if ((filename.StartsWith(dataPath, StringComparison.OrdinalIgnoreCase)))
{
filename = filename.Substring(dataPath.Length).TrimStart(Path.DirectorySeparatorChar);
}
return filename;
}