本文整理汇总了C#中Microsoft.CodeAnalysis.SemanticModel.GetAliasInfo方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.GetAliasInfo方法的具体用法?C# SemanticModel.GetAliasInfo怎么用?C# SemanticModel.GetAliasInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SemanticModel
的用法示例。
在下文中一共展示了SemanticModel.GetAliasInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsReportable
private bool IsReportable(VariableDeclarationSyntax variableDeclaration, SemanticModel semanticModel)
{
bool result;
TypeSyntax variableTypeName = variableDeclaration.Type;
if (variableTypeName.IsVar)
{
// Implicitly-typed variables cannot have multiple declarators. Short circuit if it does.
bool hasMultipleVariables = variableDeclaration.Variables.Skip(1).Any();
if(hasMultipleVariables == false)
{
// Special case: Ensure that 'var' isn't actually an alias to another type. (e.g. using var = System.String).
IAliasSymbol aliasInfo = semanticModel.GetAliasInfo(variableTypeName);
if (aliasInfo == null)
{
// Retrieve the type inferred for var.
ITypeSymbol type = semanticModel.GetTypeInfo(variableTypeName).ConvertedType;
// Special case: Ensure that 'var' isn't actually a type named 'var'.
if (type.Name.Equals("var", StringComparison.Ordinal) == false)
{
// Special case: Ensure that the type is not an anonymous type.
if (type.IsAnonymousType == false)
{
// Special case: Ensure that it's not a 'new' expression.
if (variableDeclaration.Variables.First().Initializer.Value.IsKind(SyntaxKind.ObjectCreationExpression))
{
result = false;
}
else
{
result = true;
}
}
else
{
result = false;
}
}
else
{
result = false;
}
}
else
{
result = false;
}
}
else
{
result = false;
}
}
else
{
result = false;
}
return result;
}
示例2: IsTypeInferred
/// <summary>
/// Determines whether the specified TypeSyntax is actually 'var'.
/// </summary>
public static bool IsTypeInferred(this TypeSyntax typeSyntax, SemanticModel semanticModel)
{
if (!typeSyntax.IsVar)
{
return false;
}
if (semanticModel.GetAliasInfo(typeSyntax) != null)
{
return false;
}
var type = semanticModel.GetTypeInfo(typeSyntax).Type;
if (type == null)
{
return false;
}
if (type.Name == "var")
{
return false;
}
return true;
}