示例#1
0
 void GenerateFindMethod(CodeTypeDeclaration ctd, FieldInfo fi, bool withTransaction, bool list)
 {
     if (!Project.WithSoql)
     {
         throw new SoodaCodeGenException("'" + (list ? "findList" : "find") + "' schema attribute on field " + fi.Name
             + " in class " + fi.ParentClass.Name + " is incompatible with --no-soql");
     }
     GenerateFindMethod(ctd, fi, withTransaction, list, fi.GetNullableFieldHandler().GetFieldType().Name);
     if (fi.ReferencedClass != null)
         GenerateFindMethod(ctd, fi, withTransaction, list, fi.ReferencedClass.Name);
 }
        public CodeTypeReference GetReturnType(PrimitiveRepresentation rep, FieldInfo fi)
        {
            switch (rep)
            {
                case PrimitiveRepresentation.Boxed:
                    return new CodeTypeReference(typeof(object));

                case PrimitiveRepresentation.SqlType:
                    Type t = fi.GetNullableFieldHandler().GetSqlType();
                    if (t == null)
                        return new CodeTypeReference(fi.GetNullableFieldHandler().GetFieldType());
                    else
                        return new CodeTypeReference(t);

                case PrimitiveRepresentation.RawWithIsNull:
                case PrimitiveRepresentation.Raw:
                    return new CodeTypeReference(fi.GetNullableFieldHandler().GetFieldType());

                case PrimitiveRepresentation.Nullable:
                    return new CodeTypeReference(fi.GetNullableFieldHandler().GetNullableType());

                default:
                    throw new NotImplementedException("Unknown PrimitiveRepresentation: " + rep);
            }
        }
        private void OutputModifiedLiteral(SoqlExpression expr, FieldInfo fieldInfo)
        {
            if (expr is SoqlLiteralExpression)
            {
                SoqlLiteralExpression e = (SoqlLiteralExpression)expr;

                Output.Write("{L:");
                Output.Write(fieldInfo.DataType.ToString());
                Output.Write(':');

                string serializedValue = fieldInfo.GetNullableFieldHandler().RawSerialize(e.LiteralValue).Replace("\\", "\\\\").Replace("}", "\\}");

                Output.Write(serializedValue);
                Output.Write('}');
            }
            else if (expr is SoqlParameterLiteralExpression)
            {
                SoqlParameterLiteralExpression e = (SoqlParameterLiteralExpression)expr;

                Output.Write('{');
                Output.Write(e.ParameterPosition);
                Output.Write(':');
                Output.Write(fieldInfo.DataType.ToString());
                Output.Write('}');
            }
            else if (expr is SoqlBooleanLiteralExpression)
            {
                SoqlBooleanLiteralExpression e = (SoqlBooleanLiteralExpression)expr;

                Output.Write("{L:");
                Output.Write(fieldInfo.DataType.ToString());
                Output.Write(':');

                string serializedValue = fieldInfo.GetNullableFieldHandler().RawSerialize(e.Value).Replace("\\", "\\\\").Replace("}", "\\}");

                Output.Write(serializedValue);
                Output.Write('}');
            }
            else
            {
                throw new ArgumentException("Not supported literal expression type: " + expr.GetType().FullName);
            }
        }