Example #1
0
 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")
     });
Example #2
0
 public int GetSize(IType type)
 {
     return(type switch {
         IPrimitiveType primitiveType => GetSize(primitiveType),
         IPointerType pointerType => IntPtr.Size,
         StructType structType => GetSize(structType),
         _ => throw new NotSupportedException()
     });
Example #3
0
        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);
        }
Example #4
0
        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()));
        }
Example #5
0
 public static void SetCsharpType(this IPrimitiveType pt, string value)
 {
     allCsharpTypes[pt] = value;
 }
Example #6
0
 public static string GetCsharpType(this IPrimitiveType pt)
 {
     return(allCsharpTypes.ContainsKey(pt) ? allCsharpTypes[pt] : null);
 }