当前位置: 首页>>代码示例>>C#>>正文


C# Value.GetMemberValue方法代码示例

本文整理汇总了C#中Debugger.Value.GetMemberValue方法的典型用法代码示例。如果您正苦于以下问题:C# Value.GetMemberValue方法的具体用法?C# Value.GetMemberValue怎么用?C# Value.GetMemberValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Debugger.Value的用法示例。


在下文中一共展示了Value.GetMemberValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatDebugValue

		/// <summary>
		/// Formats current Value according to the given format, specified by <see cref="System.Diagnostics.DebuggerDisplayAttribute"/>.
		/// </summary>
		/// <param name="debugFormat">Format to use</param>
		/// <returns>Formatted string.</returns>
		/// <remarks>
		/// Not all possible expressions are supported, but only a simple set.
		/// Otherwise we would have to support any C# expression.
		/// </remarks>
		static string FormatDebugValue(Thread evalThread, Value value, string debugFormat)
		{
			StringBuilder formattedOutput = new StringBuilder();
			StringBuilder currentFieldName = new StringBuilder();
			bool insideFieldName = false;
			bool ignoringRestOfExpression = false;
			bool insideMethodBrackets = false;
			bool isMethodName = false;
			bool escapeNextChar = false;
			for (int i = 0; i < debugFormat.Length; i++) {
				char thisChar = debugFormat[i];
				
				if (!escapeNextChar && (thisChar == '{')) {
					insideFieldName = true;
				} else if (!escapeNextChar && (thisChar == '}')) {
					// Insert contents of specified member, if we can find it, otherwise we display "?"
					string memberValueStr = "?";
					
					// Decide if we want a method or field/property
					Predicate<IUnresolvedMember> isNeededMember;
					if (isMethodName) {
						// We only support methods without parameters here!
						isNeededMember = m => (m.Name == currentFieldName.ToString())
							&& (m.SymbolKind == SymbolKind.Method)
							&& (((IUnresolvedMethod) m).Parameters.Count == 0);
					} else {
						isNeededMember = m => (m.Name == currentFieldName.ToString())
							&& ((m.SymbolKind == SymbolKind.Field) || (m.SymbolKind == SymbolKind.Property));
					}
					
					IMember member = value.type.GetMembers(isNeededMember).FirstOrDefault();
					if (member != null) {
						Value memberValue = value.GetMemberValue(evalThread, member);
						memberValueStr = memberValue.InvokeToString(evalThread);
					}
					
					formattedOutput.Append(memberValueStr);
					
					insideFieldName = false;
					ignoringRestOfExpression = false;
					insideMethodBrackets = false;
					isMethodName = false;
					currentFieldName.Clear();
				} else if (!escapeNextChar && (thisChar == '\\')) {
					// Next character will be escaped
					escapeNextChar = true;
				} else if (insideFieldName && (thisChar == '(')) {
					insideMethodBrackets = true;
				} else if ((thisChar == ')') && insideMethodBrackets) {
					insideMethodBrackets = false;
					isMethodName = true;
					
					// Everything following the brackets will be ignored
					ignoringRestOfExpression = true;
				} else if (insideFieldName && !Char.IsDigit(thisChar) && !Char.IsLetter(thisChar)) {
					// Char seems not to belong to a field name, ignore everything from now on
					ignoringRestOfExpression = true;
				} else {
					if (insideFieldName) {
						if (!ignoringRestOfExpression)
							currentFieldName.Append(thisChar);
					} else {
						formattedOutput.Append(thisChar);
					}
					escapeNextChar = false;
				}
			}
			
			return formattedOutput.ToString();
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:79,代码来源:Value.cs

示例2: FormatValue

		public static string FormatValue(Value val)
		{
			if (val == null) {
				return null;
			} if (val.IsNull) {
				return "null";
			} else if (val.Type.IsArray) {
				StringBuilder sb = new StringBuilder();
				sb.Append(val.Type.Name);
				sb.Append(" {");
				bool first = true;
				foreach(Value item in val.GetArrayElements()) {
					if (!first) sb.Append(", ");
					first = false;
					sb.Append(FormatValue(item));
				}
				sb.Append("}");
				return sb.ToString();
			} else if (val.Type.GetInterface(typeof(ICollection).FullName) != null) {
				StringBuilder sb = new StringBuilder();
				sb.Append(val.Type.Name);
				sb.Append(" {");
				val = val.GetPermanentReference();
				int count = (int)val.GetMemberValue("Count").PrimitiveValue;
				for(int i = 0; i < count; i++) {
					if (i > 0) sb.Append(", ");
					DebugPropertyInfo itemProperty = (DebugPropertyInfo)val.Type.GetProperty("Item");
					Value item = val.GetPropertyValue(itemProperty, Eval.CreateValue(val.AppDomain, i));
					sb.Append(FormatValue(item));
				}
				sb.Append("}");
				return sb.ToString();
			} else if (val.Type.FullName == typeof(char).FullName) {
				return "'" + val.PrimitiveValue.ToString() + "'";
			} else if (val.Type.FullName == typeof(string).FullName) {
				return "\"" + val.PrimitiveValue.ToString() + "\"";
			} else if (val.Type.IsPrimitive) {
				return val.PrimitiveValue.ToString();
			} else {
				return val.InvokeToString();
			}
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:42,代码来源:ExpressionEvaluator.cs


注:本文中的Debugger.Value.GetMemberValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。