本文整理汇总了C#中ITypeSymbol.As方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeSymbol.As方法的具体用法?C# ITypeSymbol.As怎么用?C# ITypeSymbol.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeSymbol
的用法示例。
在下文中一共展示了ITypeSymbol.As方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertTypeUncached
private static string ConvertTypeUncached(ITypeSymbol typeSymbol)
{
if (typeSymbol.IsAnonymousType)
return WriteAnonymousObjectCreationExpression.TypeName(typeSymbol.As<INamedTypeSymbol>());
var array = typeSymbol as IArrayTypeSymbol;
if (array != null)
{
var typeString = TryConvertType(array.ElementType, false);
// if (localize)
// {
// var name =
// Context.Instance.UsingDeclarations.FirstOrDefault(
// k => typeString.StartsWith(k.Name.ToFullString() + ".Namespace.", StringComparison.Ordinal));
//
// if (name != null)
// typeString = typeString.RemoveFromStartOfString(name.Name.ToFullString() + ".Namespace.");
// }
return "Array_T!(" + typeString + ")";
}
if (typeSymbol.TypeKind == TypeKind.PointerType)
{
var pointer = typeSymbol as IPointerTypeSymbol;
return ConvertType(pointer.PointedAtType) + "*";
}
var typeInfoStr = typeSymbol.ToString();
var named = typeSymbol as INamedTypeSymbol;
if (typeSymbol.TypeKind == TypeKind.TypeParameter)
return WriteIdentifierName.TransformIdentifier(typeSymbol.Name,typeSymbol);
if (named != null && (named.ContainingNamespace.ToString() == "System" && named.Name == "Exception"))
return "System.Namespace.NException";
//TODO: Add explicit support for Nullable
if (named != null && (named.Name == "Nullable" && named.ContainingNamespace.ToString() == "System"))
{
//Nullable types
if (named.TypeArguments.Any())
{
string convertedType="";
if (named.TypeArguments.FirstOrDefault() is IErrorTypeSymbol)
{
//unbound generic
convertedType = "__UNBOUND";
}
else
{
convertedType = TryConvertType(named.TypeArguments.FirstOrDefault(), false);
}
return "Nullable__G!(" + convertedType + ")";
}
}
var typeStr = GenericTypeName(typeSymbol);
if (named != null && named.IsGenericType)
{
if(!named.IsUnboundGenericType && TypeArguments(named).Any())
return GetFullGenericName(named);
else
{
return GetFullGenericName(named.OriginalDefinition);
}
}
switch (typeStr)
{
case "System.Namespace.Void":
return "void";
case "System.Namespace.Boolean":
return "bool";
case "System.Object":
case "System.Namespace.Object":
return "NObject";
case "System.Namespace.UInt64":
return "ulong";
case "System.Namespace.Double":
return "double";
case "System.Namespace.Single":
return "float";
case "System.Namespace.String":
return "String";
//.........这里部分代码省略.........