/// <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; }
/// <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; }
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; }