public void GenerateClassFactory(CodeNamespace nspace, ClassInfo ci) { if (!string.IsNullOrEmpty(ci.Schema.AssemblyName)) return; FieldInfo fi = ci.GetFirstPrimaryKeyField(); Sooda.ObjectMapper.SoodaFieldHandler fieldHandler = fi.GetNullableFieldHandler(); string pkClrTypeName = fieldHandler.GetFieldType().FullName; string pkFieldHandlerTypeName = fieldHandler.GetType().FullName; CDILContext context = new CDILContext(); context["ClassName"] = ci.Name; context["OutNamespace"] = Project.OutputNamespace; if (ci.GetPrimaryKeyFields().Length == 1) { context["GetRefArgumentType"] = pkClrTypeName; context["MultiColumnPrimaryKey"] = false; } else { context["GetRefArgumentType"] = "SoodaTuple"; context["MultiColumnPrimaryKey"] = true; } context["PrimaryKeyHandlerType"] = pkFieldHandlerTypeName; context["IsAbstract"] = ci.IsAbstractClass(); if (Project.LoaderClass) context["LoaderClass"] = /*Project.OutputNamespace.Replace(".", "") + "." + */ci.Name + "Loader"; else context["LoaderClass"] = /*Project.OutputNamespace.Replace(".", "") + "Stubs." + */ci.Name + "_Stub"; CodeTypeDeclaration factoryClass = CDILParser.ParseClass(CDILTemplate.Get("Factory.cdil"), context); factoryClass.CustomAttributes.Add(new CodeAttributeDeclaration("SoodaObjectFactoryAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(ci.Name)), new CodeAttributeArgument(new CodeTypeOfExpression(ci.Name)) )); nspace.Types.Add(factoryClass); }
public void GenerateClassSkeleton(CodeNamespace nspace, ClassInfo ci, bool useChainedConstructorCall, bool fakeSkeleton, bool usePartial, string partialSuffix) { if (!string.IsNullOrEmpty(ci.Schema.AssemblyName)) return; CodeTypeDeclaration ctd = new CodeTypeDeclaration(ci.Name + (usePartial ? partialSuffix : "")); if (ci.Description != null) { ctd.Comments.Add(new CodeCommentStatement("<summary>", true)); ctd.Comments.Add(new CodeCommentStatement(ci.Description, true)); ctd.Comments.Add(new CodeCommentStatement("</summary>", true)); } ctd.BaseTypes.Add(Project.OutputNamespace.Replace(".", "") + "Stubs." + ci.Name + "_Stub"); if (ci.IsAbstractClass()) ctd.TypeAttributes |= System.Reflection.TypeAttributes.Abstract; nspace.Types.Add(ctd); CodeDomClassSkeletonGenerator gen = new CodeDomClassSkeletonGenerator(); ctd.Members.Add(gen.Constructor_Raw()); ctd.Members.Add(gen.Constructor_Inserting(useChainedConstructorCall)); ctd.Members.Add(gen.Constructor_Inserting2(useChainedConstructorCall)); if (!useChainedConstructorCall) { ctd.Members.Add(gen.Method_InitObject()); } if (usePartial) { ctd = new CodeTypeDeclaration(ci.Name); if (ci.Description != null) { ctd.Comments.Add(new CodeCommentStatement("<summary>", true)); ctd.Comments.Add(new CodeCommentStatement(ci.Description, true)); ctd.Comments.Add(new CodeCommentStatement("</summary>", true)); } ctd.BaseTypes.Add(ci.Name + partialSuffix); if (ci.IsAbstractClass()) ctd.TypeAttributes |= System.Reflection.TypeAttributes.Abstract; ctd.IsPartial = true; nspace.Types.Add(ctd); gen = new CodeDomClassSkeletonGenerator(); ctd.Members.Add(gen.Constructor_Raw()); ctd.Members.Add(gen.Constructor_Inserting(useChainedConstructorCall)); ctd.Members.Add(gen.Constructor_Inserting2(useChainedConstructorCall)); if (!useChainedConstructorCall) { ctd.Members.Add(gen.Method_InitObject()); } } }
void OutputSoodaClassCase(ClassInfo ci) { if (ci.IsAbstractClass()) return; Output.Write(" when "); switch (ci.SubclassSelectorField.DataType) { case FieldDataType.String: Output.Write("N'"); Output.Write(ci.SubclassSelectorValue); Output.Write('\''); break; case FieldDataType.AnsiString: Output.Write('\''); Output.Write(ci.SubclassSelectorValue); Output.Write('\''); break; default: Output.Write(ci.SubclassSelectorValue); break; } Output.Write(" then '"); Output.Write(ci.Name); Output.Write('\''); }