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


C# ITypeSymbol.IsNullable方法代码示例

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


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

示例1: GetTypeMarkup

		string GetTypeMarkup (ITypeSymbol t, bool includeDeclaringTypes = false)
		{
			if (t == null)
				throw new ArgumentNullException ("t");
			if (t.TypeKind == TypeKind.Error)
				return GettextCatalog.GetString ("Type can not be resolved.");
			if (t.TypeKind == TypeKind.Delegate)
				return GetDelegateMarkup ((INamedTypeSymbol)t);
			if (t.TypeKind == TypeKind.TypeParameter)
				return GetTypeParameterMarkup (t);
			if (t.TypeKind == TypeKind.Array || t.TypeKind == TypeKind.Pointer)
				return GetTypeReferenceString (t);
			if (t.IsNullable ())
				return GetNullableMarkup (t);
			var result = new StringBuilder ();
			if (IsNullableType (t))
				AppendModifiers (result, t);

			switch (t.TypeKind) {
			case TypeKind.Class:
				result.Append (Highlight ("class ", colorStyle.KeywordDeclaration));
				break;
			case TypeKind.Interface:
				result.Append (Highlight ("interface ", colorStyle.KeywordDeclaration));
				break;
			case TypeKind.Struct:
				result.Append (Highlight ("struct ", colorStyle.KeywordDeclaration));
				break;
			case TypeKind.Enum:
				result.Append (Highlight ("enum ", colorStyle.KeywordDeclaration));
				break;
			}

			if (includeDeclaringTypes) {
				var typeNames = new List<string> ();
				var curType = t;
				while (curType != null) {
					typeNames.Add (GetTypeNameWithParameters (curType));
					curType = curType.ContainingType;
				}
				typeNames.Reverse ();
				result.Append (string.Join (".", typeNames));
			} else {
				result.Append (GetTypeNameWithParameters (t));
			}

			if (t.TypeKind == TypeKind.Array)
				return result.ToString ();

			bool first = true;
			int maxLength = GetMarkupLength (result.ToString ());
			int length = maxLength;
			var sortedTypes = new List<INamedTypeSymbol> (t.Interfaces);

			sortedTypes.Sort ((x, y) => GetTypeReferenceString (y).Length.CompareTo (GetTypeReferenceString (x).Length));

			if (t.BaseType != null && t.BaseType.SpecialType != SpecialType.System_Object)
				sortedTypes.Insert (0, t.BaseType);

			if (t.TypeKind != TypeKind.Enum) {
				foreach (var directBaseType in sortedTypes) {
					if (first) {
						result.AppendLine (" :");
						result.Append ("  ");
						length = 2;
					} else { // 5.5. um 10:45
						result.Append (", ");
						length += 2;
					}
					var typeRef = GetTypeReferenceString (directBaseType, false);

					if (!first && length + typeRef.Length >= maxLength) {
						result.AppendLine ();
						result.Append ("  ");
						length = 2;
					}

					result.Append (typeRef);
					length += GetMarkupLength (typeRef);
					first = false;
				}
			} else {
				var enumBase = t.BaseType;
				if (enumBase.SpecialType != SpecialType.System_Int32) {
					result.AppendLine (" :");
					result.Append ("  ");
					result.Append (GetTypeReferenceString (enumBase, false));
				}
			}

			return result.ToString ();
		}
开发者ID:kdubau,项目名称:monodevelop,代码行数:92,代码来源:SignatureMarkupCreator.cs


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