本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSyntax.ToString方法的具体用法?C# TypeSyntax.ToString怎么用?C# TypeSyntax.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax
的用法示例。
在下文中一共展示了TypeSyntax.ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTrackerClassName
public static string GetTrackerClassName(TypeSyntax type)
{
// NOTE: it's naive approach because we don't know semantic type information here.
var genericType = type as GenericNameSyntax;
if (genericType == null)
{
if (type.ToString().StartsWith("Trackable"))
{
return $"TrackablePocoTracker<I{type.ToString().Substring(9)}>";
}
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableDictionary"))
{
return $"TrackableDictionaryTracker{genericType.TypeArgumentList}";
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableSet"))
{
return $"TrackableSetTracker{genericType.TypeArgumentList}";
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableList"))
{
return $"TrackableListTracker{genericType.TypeArgumentList}";
}
throw new Exception("Cannot resolve tracker class of " + type);
}
示例2: IsTrackableType
public static bool IsTrackableType(TypeSyntax type)
{
// NOTE: it's naive approach because we don't know semantic type information here.
var parts = type.ToString().Split('.');
var typeName = parts[parts.Length - 1];
return typeName.StartsWith("Trackable");
}
示例3: GetFieldVariableName
public static string GetFieldVariableName(TypeSyntax type, bool underscore)
{
var name = type.ToString();
if (name.StartsWith("I"))
name = name.Substring(1);
var firstChara = name[0];
if (Char.IsUpper(firstChara))
{
name = firstChara.ToString().ToLower() + name.Substring(1);
}
else
{
name += 1;
}
return name;
}
示例4: ResolveLType
private static string ResolveLType(TypeSyntax node)
{
var gensyn = node as GenericNameSyntax;
if (null != gensyn) return gensyn.Identifier.ToString();
else return node.ToString();
}
示例5: BindCrefParameterOrReturnType
/// <remarks>
/// Keep in sync with <see cref="M:SemanticModel.GetSpeculativelyBoundExpression()"/>.
/// </remarks>
private TypeSymbol BindCrefParameterOrReturnType(TypeSyntax typeSyntax, MemberCrefSyntax memberCrefSyntax, DiagnosticBag diagnostics)
{
DiagnosticBag unusedDiagnostics = DiagnosticBag.GetInstance(); // Examined, but not reported.
// After much deliberation, we eventually decided to suppress lookup of inherited members within
// crefs, in order to match dev11's behavior (Changeset #829014). Unfortunately, it turns out
// that dev11 does not suppress these members when performing lookup within parameter and return
// types, within crefs (DevDiv #586815, #598371).
Debug.Assert(InCrefButNotParameterOrReturnType);
Binder parameterOrReturnTypeBinder = this.WithAdditionalFlags(BinderFlags.CrefParameterOrReturnType);
// It would be nice to pull this binder out of the factory so we wouldn't have to worry about them getting out
// of sync, but this code is also used for included crefs, which don't have BinderFactories.
// As a compromise, we'll assert that the binding locations match in scenarios where we can go through the factory.
Debug.Assert(!this.Compilation.ContainsSyntaxTree(typeSyntax.SyntaxTree) ||
this.Compilation.GetBinderFactory(typeSyntax.SyntaxTree).GetBinder(typeSyntax).Flags ==
(parameterOrReturnTypeBinder.Flags & ~BinderFlags.SemanticModel));
TypeSymbol type = parameterOrReturnTypeBinder.BindType(typeSyntax, unusedDiagnostics);
if (unusedDiagnostics.HasAnyErrors())
{
if (HasNonObsoleteError(unusedDiagnostics))
{
ErrorCode code = typeSyntax.Parent.Kind == SyntaxKind.ConversionOperatorMemberCref
? ErrorCode.WRN_BadXMLRefReturnType
: ErrorCode.WRN_BadXMLRefParamType;
CrefSyntax crefSyntax = GetRootCrefSyntax(memberCrefSyntax);
diagnostics.Add(code, typeSyntax.Location, typeSyntax.ToString(), crefSyntax.ToString());
}
}
else
{
Debug.Assert(type.TypeKind != TypeKind.Error || typeSyntax.ContainsDiagnostics || !typeSyntax.SyntaxTree.ReportDocumentationCommentDiagnostics(), "Why wasn't there a diagnostic?");
}
unusedDiagnostics.Free();
return type;
}
示例6: GetTypeScriptEquivalentType
private static string GetTypeScriptEquivalentType(TypeSyntax field)
{
var type = "";
switch (field.ToString().ToLower())
{
case "int":
case "float":
case "small":
case "bigint":
type = "number";
break;
default:
type = field.ToString();
break;
}
return type;
}
示例7: GetMappedType
private string GetMappedType(TypeSyntax type)
{
if (type.ToString() == "void")
return "void";
if (type.ToString().EndsWith("Exception"))
return type.ToString();
return type.ToString().StartsWith("int") ? "number" : "string";
}
示例8: BuildVariableDeclaration
// The "target = new Class1()" portion of "Class1 target = new Class1();"
private VariableDeclarationSyntax BuildVariableDeclaration(TypeSyntax variableType, string variableName)
{
return SyntaxFactory.VariableDeclaration(variableType,
SyntaxFactory.SingletonSeparatedList<VariableDeclaratorSyntax>(
SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(SyntaxFactory.TriviaList(), variableName, SyntaxFactory.TriviaList(SyntaxFactory.Space)))
.WithInitializer(
SyntaxFactory.EqualsValueClause(
SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName(variableType.ToString()))
.WithNewKeyword(SyntaxFactory.Token(SyntaxFactory.TriviaList(SyntaxFactory.Space), SyntaxKind.NewKeyword, SyntaxFactory.TriviaList(SyntaxFactory.Space)))
.WithArgumentList(SyntaxFactory.ArgumentList())
)
)
)
);
}
示例9: GetName
private string GetName(TypeSyntax name)
{
return (name as SimpleNameSyntax).Identifier.ToString() ?? name.ToString();
}
示例10: GetFullReturnType
private string GetFullReturnType(TypeSyntax returnType)
{
var fullReturnType = returnType.ToString();
var node = returnType.DescendantNodes().OfType<IdentifierNameSyntax>().FirstOrDefault();
Document cl = null;
var systemTypes = new List<string>()
{
"Guid",
"Guid?"
};
if (node != null && systemTypes.All(x => x != node.Identifier.ToString() && x != returnType.ToString()))
{
var nameSpace = SymbolFinder.FindDeclarationsAsync(_project, node.Identifier.ValueText, ignoreCase: false).Result.Last().ContainingNamespace.ToString();
fullReturnType = fullReturnType.Replace(node.Identifier.ToString(), nameSpace + "." + node.Identifier);
}
return fullReturnType;
}
示例11: TypeInspector
public TypeInspector(TypeSyntax typeSyntax)
{
ShortName = typeSyntax.ToString();
}