internal static Type GetActualType(this AstType astType) { ComposedType composedType = astType as ComposedType; if (composedType != null) { return(composedType.GetActualType()); } PrimitiveType primitiveType = astType as PrimitiveType; if (primitiveType != null) { return(primitiveType.GetActualType()); } MemberType memberType = astType as MemberType; if (memberType != null) { return(memberType.GetActualType()); } var simpleType = astType as SimpleType; if (simpleType != null) { return(simpleType.GetActualType()); } if (astType.HasAnnotations()) { var typeReference = astType.Annotation <TypeReference>(); if (typeReference != null) { return(typeReference.GetActualType()); } var typeDefinition = astType.Annotation <TypeDefinition>(); if (typeDefinition != null) { return(typeDefinition.GetActualType()); } } return(null); }
/*public static string TypeToString(TypeReference type, out bool isPrimitiveType) * { * string result = type.Name; * isPrimitiveType = false; * if (type.IsPrimitive) * { * isPrimitiveType = true; * switch (result) * { * case "SByte": * result = "char"; * break; * case "Byte": * result = "unsigned char"; * break; * case "Boolean": * result = "bool"; * break; * case "Int16": * result = "short"; * break; * case "UInt16": * result = "unsigned short"; * break; * case "Int32": * result = "int"; * break; * case "UInt32": * result = "unsigned int"; * break; * case "Int64": * result = "long"; * break; * case "UInt64": * result = "unsigned long"; * break; * case "Single": * case "Double": * result = "double"; * break; * case "Char": * result = "char"; * break; * default: * break; * } * return result; * } * * if (type.HasGenericParameters) * { * * } * else if (type.IsArray) * { * * } * else if (type.IsVoid()) * { * return "void"; * } * else if (type.is) * if (result == "String") * result = "QString"; * else if (result == "DateTime") * result = "QDateTime"; * else if (result == "Void") * result = "void"; * else if (result == "List") * result = "QList"; * else if (result == "Object") * result = "QVariant"; * return result; * }*/ public static TypeDefinition GetTypeDef(AstType type) { var td = type.Annotation <TypeDefinition>(); if (td == null) { var tr = type.Annotation <TypeReference>(); if (tr != null) { td = tr.Resolve(); } } return(td); }
public static Type ResolveClrType(this AstType type) => type.Annotation <Type>() ?? type.Annotation <TypeReference>()?.ResolveClrType();
public static TypeReference GetTypeRef(AstType type) { return(type.Annotation <TypeDefinition>() as TypeReference ?? type.Annotation <TypeReference>()); }
static TypeReference GetTypeRef (AstType type) { return type.Annotation<TypeDefinition> () as TypeReference ?? type.Annotation<TypeReference> (); }
static TypeDefinition GetTypeDef (AstType type) { var td = type.Annotation<TypeDefinition> (); if (td == null) { var tr = type.Annotation<TypeReference> (); if (tr != null) { td = tr.Resolve (); } } return td; }