本文整理汇总了C#中StackFrame.GetFileLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# StackFrame.GetFileLineNumber方法的具体用法?C# StackFrame.GetFileLineNumber怎么用?C# StackFrame.GetFileLineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackFrame
的用法示例。
在下文中一共展示了StackFrame.GetFileLineNumber方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FloatField
public static float FloatField(float value, object callingObj)
{
#if UNITY_EDITOR
return UnityEditor.EditorGUILayout.FloatField (value);
#else
// Fetch information about the calling instance (to identify the floatField)
StackFrame frame = new StackFrame (1, true);
string floatFieldID = "Obj:" + (callingObj != null? callingObj.GetHashCode ().ToString () : "Null") +
"_File:" + frame.GetFileName () +
"_Line:" + frame.GetFileLineNumber ();
// Display field
bool recordedField = floatFields.ContainsKey (floatFieldID);
string prevStr = recordedField? floatFields [floatFieldID] : value.ToString ();
GUI.SetNextControlName (floatFieldID);
string textValue = GUILayout.TextField (prevStr, new GUILayoutOption[] { GUILayout.ExpandWidth (false), GUILayout.MinWidth (40) });
// Check focus
bool unfocusField = GUI.GetNameOfFocusedControl () != floatFieldID && activeFloatField == floatFieldID;
if (unfocusField) // field got out of focus
UnityEngine.Debug.Log ("Unfocus!");
else if (GUI.GetNameOfFocusedControl () == floatFieldID) // Focus
activeFloatField = floatFieldID;
// Cleanup
if (textValue.Split (new char[] {'.', ','}, System.StringSplitOptions.None).Length > 2) // if there are two dots, remove the second one and every fellow digit
textValue.Remove (textValue.LastIndexOf ('.'));
// Update text
if (recordedField)
floatFields [floatFieldID] = textValue;
// lastFloatField = floatFieldID;
// Parse and handle records
float newValue;
bool parsed = float.TryParse (textValue, out newValue);
if ((parsed && !textValue.EndsWith (".")) || unfocusField)
{ // if we don't have something to keep (any information that would be lost when parsing)
if (recordedField || unfocusField) // but we have a record of this (previously not parseable), remove it now (as it has become parseable)
floatFields.Remove (floatFieldID);
}
else if (!recordedField) // we have something we want to keep (any information that would be lost when parsing) and we don't already have it recorded, add it
floatFields.Add (floatFieldID, textValue);
return parsed? newValue : value;
#endif
}
示例2: FormatStackFrame
private static string FormatStackFrame(StackFrame f) {
System.Reflection.MethodBase mb = f.GetMethod();
if(mb == null) return "<unknown>";
string method = string.Format("{0}.{1}", mb.DeclaringType.Name, mb.Name);
string file = f.GetFileName();
if(file == null) return method;
else return string.Format("{0} in \"{1}\":{2}:{3}", method, file, f.GetFileLineNumber(), f.GetFileColumnNumber());
}
示例3: Leave
public static void Leave()
{
StackFrame stack = new StackFrame(1, true);
Logger.AddMsg(String.Format("Leave {0}, {1}:{2}"
, stack.GetMethod().Name
, stack.GetFileName()
, stack.GetFileLineNumber())
, LogLevel.Debug);
}
示例4: StackFrameToString
//--
//-- turns a single stack frame object into an informative string
//--
private static string StackFrameToString(StackFrame sf)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int intParam = 0;
MemberInfo mi = sf.GetMethod();
var _with1 = sb;
//-- build method name
_with1.Append(" ");
_with1.Append(mi.DeclaringType.Namespace);
_with1.Append(".");
_with1.Append(mi.DeclaringType.Name);
_with1.Append(".");
_with1.Append(mi.Name);
//-- build method params
ParameterInfo[] objParameters = sf.GetMethod().GetParameters();
ParameterInfo objParameter = null;
_with1.Append("(");
intParam = 0;
foreach (ParameterInfo objParameter_loopVariable in objParameters)
{
objParameter = objParameter_loopVariable;
intParam += 1;
if (intParam > 1)
_with1.Append(", ");
_with1.Append(objParameter.Name);
_with1.Append(" As ");
_with1.Append(objParameter.ParameterType.Name);
}
_with1.Append(")");
_with1.Append(Environment.NewLine);
//-- if source code is available, append location info
_with1.Append(" ");
if (sf.GetFileName() == null || sf.GetFileName().Length == 0)
{
_with1.Append(System.IO.Path.GetFileName(ParentAssembly().CodeBase));
//-- native code offset is always available
_with1.Append(": N ");
_with1.Append(string.Format("{0:#00000}", sf.GetNativeOffset()));
}
else
{
_with1.Append(System.IO.Path.GetFileName(sf.GetFileName()));
_with1.Append(": line ");
_with1.Append(string.Format("{0:#0000}", sf.GetFileLineNumber()));
_with1.Append(", col ");
_with1.Append(string.Format("{0:#00}", sf.GetFileColumnNumber()));
//-- if IL is available, append IL location info
if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
{
_with1.Append(", IL ");
_with1.Append(string.Format("{0:#0000}", sf.GetILOffset()));
}
}
_with1.Append(Environment.NewLine);
return sb.ToString();
}