public Type?LookupType(IType type) { return(type switch { IPointerType pointerType => LookupType(pointerType.DestinationType)?.PointerType(), IPrimitiveType primitiveType => Context.LookupPrimitiveType(primitiveType.Primitive), StructType structType => Context.LookupStructType(structType.Name), _ => throw new InvalidOperationException("unhandled IType") });
public int GetSize(IType type) { return(type switch { IPrimitiveType primitiveType => GetSize(primitiveType), IPointerType pointerType => IntPtr.Size, StructType structType => GetSize(structType), _ => throw new NotSupportedException() });
public static string GetRealTypeName(this IType type) { IPrimitiveType primitiveType = type as IPrimitiveType; if (primitiveType != null) { string csharptype = primitiveType.GetCsharpType(); if (!csharptype.IsNullOrEmpty()) { return(csharptype); } } IClass clazz = type as IClass; if (clazz != null) { return(clazz.GetFQN()); } return(type.Name); }
public string Process(ComponentDefinition componentDefinition, string template) { var fieldsBuilder = new StringBuilder(); foreach (var field in componentDefinition.Fields) { if (field.type.Type != null) { if (typeof(IPrimitiveType).IsAssignableFrom(field.type.Type)) { IPrimitiveType primitiveType = Activator.CreateInstance(field.type.Type) as IPrimitiveType; fieldsBuilder.AppendLine(primitiveType.GetFieldDeclaration(field.name, FieldAccessType(field.accessType))); } else { fieldsBuilder.AppendLine($"\t\t{FieldAccessType( field.accessType )} {field.type.Type.Name} {field.name};"); } } } return(s_fieldsRegex.Replace(template, fieldsBuilder.ToString())); }
public static void SetCsharpType(this IPrimitiveType pt, string value) { allCsharpTypes[pt] = value; }
public static string GetCsharpType(this IPrimitiveType pt) { return(allCsharpTypes.ContainsKey(pt) ? allCsharpTypes[pt] : null); }