public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template) || template.IsIncomplete)
                return false;

            template.Specializations.RemoveAll(
                s => s.Fields.Any(f => f.Type.IsPrimitiveType(PrimitiveType.Void)));

            if (template.Specializations.Count == 0)
                return false;

            var groups = (from specialization in template.Specializations
                          group specialization by specialization.Arguments.All(
                              a => a.Type.Type != null && a.Type.Type.IsAddress()) into @group
                          select @group).ToList();

            foreach (var group in groups.Where(g => g.Key))
                foreach (var specialization in group.Skip(1))
                    template.Specializations.Remove(specialization);

            for (int i = template.Specializations.Count - 1; i >= 0; i--)
                if (template.Specializations[i] is ClassTemplatePartialSpecialization)
                    template.Specializations.RemoveAt(i);

            return true;
        }
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            template.Specializations.RemoveAll(
                s => s.Fields.Any(f => f.Type.IsPrimitiveType(PrimitiveType.Void)));

            if (template.Specializations.Count == 0)
                return false;

            var groups = (from specialization in template.Specializations
                          group specialization by specialization.Arguments.All(
                              a => a.Type.Type != null && a.Type.Type.IsAddress()) into @group
                          select @group).ToList();

            var lastGroup = groups.Last();
            if (lastGroup.Key)
            {
                foreach (var specialization in lastGroup.Skip(1))
                    template.Specializations.Remove(specialization);
            }

            return true;
        }
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            EnsureCompleteDeclaration(template.TemplatedDecl);

            template.TemplatedDecl = template.TemplatedDecl.CompleteDeclaration ?? template.TemplatedDecl;

            return true;
        }
Esempio n. 4
0
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            // templates are not supported yet
            foreach (var specialization in template.Specializations)
                specialization.ExplicitlyIgnore();

            return true;
        }
Esempio n. 5
0
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            if (!Driver.Options.IsCLIGenerator && template.IsSupportedStdType())
                return false;

            // templates are not supported yet
            foreach (var specialization in template.Specializations)
                specialization.ExplicitlyIgnore();

            return true;
        }
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            EnsureCompleteDeclaration(template.TemplatedDecl);

            template.TemplatedDecl = template.TemplatedDecl.CompleteDeclaration ?? template.TemplatedDecl;
            // store all spesializations in the real template class because ClassTemplateDecl only forwards
            foreach (var specialization in template.Specializations.Where(
                s => !s.IsIncomplete && !template.TemplatedClass.Specializations.Contains(s)))
                template.TemplatedClass.Specializations.Add(specialization);

            return true;
        }
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template) ||
                template.Specializations.Count == 0 ||
                template.Specializations.All(s => s is ClassTemplatePartialSpecialization))
                return false;

            var @class = template.TemplatedDecl.Namespace as Class;
            if (@class == null || @class is ClassTemplateSpecialization ||
                @class.Namespace is Class)
                return false;

            if (movedClassTemplates.ContainsKey(@class.Namespace))
                movedClassTemplates[@class.Namespace].Add(template);
            else
                movedClassTemplates.Add(@class.Namespace, new List<ClassTemplate> { template });

            return true;
        }
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            if (!base.VisitClassTemplateDecl(template))
                return false;

            if (template.IsIncomplete)
            {
                var completeDeclaration = (ClassTemplate) template.CompleteDeclaration;
                foreach (var specialization in template.Specializations.Where(
                    spec => completeDeclaration.Specializations.All(s => s.USR != spec.USR)))
                {
                    specialization.TemplatedDecl = completeDeclaration;
                    completeDeclaration.Specializations.Add(specialization);
                }
            }

            EnsureCompleteDeclaration(template.TemplatedDecl);

            template.TemplatedDecl = template.TemplatedDecl.CompleteDeclaration ?? template.TemplatedDecl;

            return true;
        }
 public static UsingTemplate ToUsing(this ClassTemplate classTemplate)
 {
     return(new UsingTemplate(classTemplate.Namespace.Name, classTemplate.Name, classTemplate.Namespace.File.RelativePath));
 }
 public static ClassTemplate Static(this ClassTemplate classTemplate, bool value = true)
 {
     classTemplate.IsStatic = value;
     return(classTemplate);
 }
 public static UsingTemplate AddUsing(this ClassTemplate classTemplate, UsingTemplate usingTemplate)
 {
     classTemplate.Usings.Add(usingTemplate);
     return(usingTemplate);
 }
        public virtual void Write(AspDotNetWriteConfiguration configuration, List <ITransferObject> transferObjects, List <FileTemplate> files)
        {
            if (!configuration.Language.IsCsharp())
            {
                throw new InvalidOperationException($"Can not generate ASP.net Controller for language {configuration.Language?.Name ?? "Empty"}. Only Csharp is currently implemented");
            }
            foreach (AspDotNetWriteEntityControllerConfiguration controllerConfiguration in configuration.Controllers)
            {
                EntityTransferObject entity = transferObjects.OfType <EntityTransferObject>().FirstOrDefault(x => x.Name == controllerConfiguration.Entity)
                                              .AssertIsNotNull(nameof(controllerConfiguration.Entity), $"Entity {controllerConfiguration.Entity} not found. Ensure it is read before.");

                string        nameSpace  = (controllerConfiguration.Namespace ?? configuration.Namespace).AssertIsNotNull(nameof(configuration.Namespace), "asp writer requires a namespace");
                ClassTemplate controller = files.AddFile(configuration.RelativePath, configuration.AddHeader)
                                           .AddNamespace(nameSpace)
                                           .AddClass(controllerConfiguration.Name ?? entity.Name + "Controller", Code.Type(configuration.Template.ControllerBase))
                                           .FormatName(configuration)
                                           .WithAttribute("Route", Code.String(controllerConfiguration.Route ?? "[controller]"));

                controller.Usings.AddRange(configuration.Template.Usings);

                TypeTemplate modelType = entity.Model.ToTemplate();

                configuration.Usings.ForEach(x => controller.AddUsing(x));
                controllerConfiguration.Usings.ForEach(x => controller.AddUsing(x));

                FieldTemplate repositoryField = controller.AddField("repository", Code.Type(entity.Name + "Repository")).Readonly();
                controller.AddConstructor().Code.AddLine(Code.This().Field(repositoryField).Assign(Code.New(repositoryField.Type)).Close());

                if (controllerConfiguration.Get != null)
                {
                    controller.AddUsing("System.Linq");
                    MethodTemplate method = controller.AddMethod("Get", Code.Generic("IEnumerable", modelType));
                    if (configuration.Template.UseAttributes)
                    {
                        method.WithAttribute("HttpGet", Code.String(controllerConfiguration.Get.Name ?? "[action]"));
                    }
                    DeclareTemplate queryable = Code.Declare(Code.Generic("IQueryable", modelType), "queryable", Code.This().Field(repositoryField).Method("Get"));
                    method.Code.AddLine(queryable);
                    foreach (PropertyTransferObject property in entity.Model.Properties)
                    {
                        ParameterTemplate parameter = method.AddParameter(property.Type.ToTemplate(), property.Name, Code.Local("default")).FormatName(configuration);
                        method.Code.AddLine(Code.If(Code.Local(parameter).NotEquals().Local("default"), x => x.Code.AddLine(Code.Local(queryable).Assign(Code.Local(queryable).Method("Where", Code.Lambda("x", Code.Local("x").Property(property.Name).Equals().Local(parameter)))).Close())));
                    }
                    method.Code.AddLine(Code.Return(Code.Local(queryable)));
                }
                if (controllerConfiguration.Post != null)
                {
                    MethodTemplate method = controller.AddMethod("Post", Code.Void());
                    if (configuration.Template.UseAttributes)
                    {
                        method.WithAttribute("HttpPost", Code.String(controllerConfiguration.Post.Name ?? "[action]"));
                    }
                    ParameterTemplate parameter = method.AddParameter(modelType, "entity")
                                                  .WithAttribute("FromBody");

                    method.Code.AddLine(Code.This().Field(repositoryField).Method("Add", Code.Local(parameter)).Close());
                }
                if (controllerConfiguration.Patch != null)
                {
                    MethodTemplate method = controller.AddMethod("Patch", Code.Void());
                    if (configuration.Template.UseAttributes)
                    {
                        method.WithAttribute("HttpPatch", Code.String(controllerConfiguration.Patch.Name ?? "[action]"));
                    }
                    ParameterTemplate parameter = method.AddParameter(modelType, "entity")
                                                  .WithAttribute("FromBody");

                    method.Code.AddLine(Code.This().Field(repositoryField).Method("Update", Code.Local(parameter)).Close());
                }
                if (controllerConfiguration.Put != null)
                {
                    MethodTemplate method = controller.AddMethod("Put", Code.Void());
                    if (configuration.Template.UseAttributes)
                    {
                        method.WithAttribute("HttpPut", Code.String(controllerConfiguration.Put.Name ?? "[action]"));
                    }
                    ParameterTemplate parameter = method.AddParameter(modelType, "entity")
                                                  .WithAttribute("FromBody");

                    method.Code.AddLine(Code.This().Field(repositoryField).Method("Update", Code.Local(parameter)).Close());
                }
                if (controllerConfiguration.Delete != null)
                {
                    MethodTemplate method = controller.AddMethod("Delete", Code.Void());
                    if (configuration.Template.UseAttributes)
                    {
                        method.WithAttribute("HttpDelete", Code.String(controllerConfiguration.Delete.Name ?? "[action]"));
                    }
                    List <ParameterTemplate> parameters = new List <ParameterTemplate>();
                    foreach (EntityKeyTransferObject key in entity.Keys)
                    {
                        PropertyTransferObject property = entity.Model.Properties.First(x => x.Name.Equals(key.Name, StringComparison.InvariantCultureIgnoreCase));
                        parameters.Add(method.AddParameter(property.Type.ToTemplate(), property.Name)
                                       .FormatName(configuration));
                    }
                    method.Code.AddLine(Code.This().Field(repositoryField).Method("Delete", parameters.Select(x => Code.Local(x))).Close());
                }
            }
        }
Esempio n. 13
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return(VisitClassDecl(template.TemplatedClass));
 }
Esempio n. 14
0
 public static ClassTemplate __CreateInstance(ClassTemplate.Internal native)
 {
     return new ClassTemplate(native);
 }
 public static ClassTemplate WithCode(this ClassTemplate classTemplate, ICodeFragment fragment)
 {
     classTemplate.Code = fragment;
     return(classTemplate);
 }
Esempio n. 16
0
 public List <string> GetAttributes(ClassTemplate property) => new List <string>
 {
     "[ProtoContract]"
 };
Esempio n. 17
0
        protected virtual ClassTemplate WriteClass(ModelTransferObject model, string relativePath)
        {
            IOptions modelOptions = this.Options.Get(model);

            if (model.BasedOn != null && model.Language != null && modelOptions.Language != null)
            {
                this.MapType(model.Language, modelOptions.Language, model.BasedOn);
            }

            bool          isInterface        = model.IsInterface || modelOptions.PreferInterfaces;
            string        modelNamespace     = modelOptions.SkipNamespace ? string.Empty : model.Namespace;
            ClassTemplate otherClassTemplate = this.files.Where(file => file.RelativePath == relativePath &&
                                                                file.Options.Language == modelOptions.Language)
                                               .SelectMany(file => file.Namespaces)
                                               .SelectMany(ns => ns.Children).OfType <ClassTemplate>()
                                               .FirstOrDefault(x => x.Namespace.Name == modelNamespace && x.Name == model.Name);
            NamespaceTemplate namespaceTemplate = otherClassTemplate?.Namespace ?? this.files.AddFile(relativePath, modelOptions)
                                                  .WithName(model.FileName)
                                                  // .WithType(isInterface ? "interface" : null)
                                                  .AddNamespace(modelNamespace);

            ClassTemplate classTemplate = namespaceTemplate.AddClass(model.Name, model.BasedOn?.ToTemplate())
                                          .FormatName(modelOptions);

            if (model.BasedOn != null)
            {
                this.AddUsing(model.BasedOn, classTemplate, modelOptions);
            }

            classTemplate.IsInterface = isInterface;
            classTemplate.IsAbstract  = model.IsAbstract;
            if (model is GenericModelTransferObject generic)
            {
                generic.Template.Generics.Select(x => new ClassGenericTemplate(x.Alias.Name)).ForEach(classTemplate.Generics.Add);
            }
            foreach (TypeTransferObject interFace in model.Interfaces)
            {
                if (model.Language != null && modelOptions.Language != null)
                {
                    this.MapType(model.Language, modelOptions.Language, interFace);
                }
                if (interFace.Name == model.Name)
                {
                    continue;
                }
                classTemplate.BasedOn.Add(new BaseTypeTemplate(classTemplate, interFace.ToTemplate()));
                this.AddUsing(interFace, classTemplate, modelOptions);
            }
            if (model is GenericModelTransferObject genericModel)
            {
                this.AddConstants(genericModel.Template, classTemplate);
                this.AddFields(genericModel.Template, classTemplate);
                this.AddProperties(genericModel.Template, classTemplate);
            }
            else
            {
                this.AddConstants(model, classTemplate);
                this.AddFields(model, classTemplate);
                this.AddProperties(model, classTemplate);
            }
            return(classTemplate);
        }
Esempio n. 18
0
    void GenerateCode()
    {
        Directory.CreateDirectory(OutputDir);

        // Generate Libs file
        using (TextWriter w = File.CreateText(Path.Combine(OutputDir, "Libs.cs"))) {
            LibsTemplate.Generator = this;
            LibsTemplate.Libs      = new[] { Lib };
            w.Write(LibsTemplate.TransformText());
        }


        // Generate user types
        foreach (Namespace ns in Lib.Namespaces)
        {
            if (ns.ParentNamespace is Class)
            {
                continue;
            }

            var klass = ns as Class;
            if (klass != null)
            {
                if (klass.Disable)
                {
                    continue;
                }

                using (TextWriter w = File.CreateText(Path.Combine(OutputDir, GetSafeFileName(klass.Name) + ".cs"))) {
                    ClassTemplate.Generator = this;
                    ClassTemplate.Class     = klass;
                    ClassTemplate.Nested    = false;
                    w.Write(ClassTemplate.TransformText());
                }

                continue;
            }

            var @enum = ns as Enumeration;
            if (@enum != null)
            {
                using (TextWriter w = File.CreateText(Path.Combine(OutputDir, @enum.Name + ".cs"))) {
                    EnumTemplate.Generator = this;
                    EnumTemplate.Enum      = @enum;
                    EnumTemplate.Nested    = false;
                    w.Write(EnumTemplate.TransformText());
                }

                continue;
            }

            var func = ns as Function;
            if (func != null)
            {
                using (TextWriter w = File.CreateText(Path.Combine(OutputDir, func.Name + ".cs"))) {
                    FunctionTemplate.Generator = this;
                    FunctionTemplate.Function  = func;
                    FunctionTemplate.Nested    = false;
                    w.Write(FunctionTemplate.TransformText());
                }

                continue;
            }
        }
    }
Esempio n. 19
0
 public BaseTypeTemplate(ClassTemplate parent, TypeTemplate type)
 {
     this.Parent = parent;
     this.type   = type;
 }
Esempio n. 20
0
        private ClassTemplate GeneratePocoClass(IEdmSchemaType ent)
        {

            if (ent == null) return null;
            //for debuging
           // var debugString = Helper.Dump(ent);
            //v1.0.0-rc3 , enum support
            var enumType = ent as IEdmEnumType;
            ClassTemplate classTemplate = new ClassTemplate
               {
                   Name = ent.Name,
                 //  ToDebugString = debugString,
                   IsEnum = (enumType != null)

               };

            //for enum type , stop here , no more information needed
            if (classTemplate.IsEnum) return classTemplate;

            //fill setname
            //v1.4
            classTemplate.EntitySetName = GetEntitySetName(ent.Name);

            //fill keys 
            var list = GetKeys(ent);
            if (list != null) classTemplate.Keys.AddRange(list);

            //fill navigation properties
            var list2 = GetNavigation(ent);
            if (list2 != null) classTemplate.Navigation.AddRange(list2);

            var entityProperties = GetClassProperties(ent);

            //set the key ,comment
            foreach (var property in entityProperties)
            {
                //@@@ v1.0.0-rc3  
                if (classTemplate.Navigation.Exists(x => x == property.PropName)) property.IsNavigate = true;

                if (classTemplate.Keys.Exists(x => x == property.PropName)) property.IsKey = true;
                var comment = (property.IsKey ? "PrimaryKey" : String.Empty)
                                + (property.IsNullable ? String.Empty : " not null");
                if (!string.IsNullOrEmpty(comment)) property.PropComment = "//" + comment;

            }
            classTemplate.Properties.AddRange(entityProperties);
            return classTemplate;
        }
Esempio n. 21
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     Library.ClassTemplateDecls.Add(template.Name);
     return(true);
 }
 public static bool IsGeneric(this ClassTemplate classTemplate)
 {
     return(classTemplate.Generics.Count > 0);
 }
Esempio n. 23
0
 private static void* __CopyValue(ClassTemplate.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(156);
     global::CppSharp.Parser.AST.ClassTemplate.__Internal.cctor_1(ret, new global::System.IntPtr(&native));
     return ret.ToPointer();
 }
Esempio n. 24
0
        protected virtual ClassTemplate WriteClass(EntityFrameworkWriteConfiguration configuration, List <ITransferObject> transferObjects, List <FileTemplate> files)
        {
            ClassTemplate dataContext = files.AddFile(configuration.RelativePath, configuration.AddHeader)
                                        .AddNamespace(configuration.Namespace)
                                        .AddClass("DataContext", Code.Type("DbContext"));

            if (configuration.IsCore)
            {
                dataContext.WithUsing("Microsoft.EntityFrameworkCore");
            }
            else
            {
                dataContext.WithUsing("System.Data.Entity");
            }

            configuration.Usings.ForEach(x => dataContext.AddUsing(x));

            PropertyTemplate defaultConnectionProperty = dataContext.AddProperty("DefaultConnection", Code.Type("string")).Static().WithDefaultValue(Code.String("name=DataContext"));

            foreach (EntityTransferObject entity in transferObjects.OfType <EntityTransferObject>())
            {
                dataContext.AddProperty(entity.Name, Code.Generic("DbSet", entity.Model.ToTemplate()))
                .FormatName(configuration)
                .Virtual();
            }

            dataContext.AddConstructor()
            .WithThisConstructor(Code.Null());

            ConstructorTemplate constructor      = dataContext.AddConstructor();
            ParameterTemplate   connectionString = constructor.AddParameter(Code.Type("string"), "connectionString");

            if (configuration.IsCore)
            {
                constructor.WithBaseConstructor(Code.Static(Code.Type("SqlServerDbContextOptionsExtensions")).Method("UseSqlServer", Code.New(Code.Type("DbContextOptionsBuilder")), Code.NullCoalescing(Code.Local(connectionString), Code.Local(defaultConnectionProperty))).Property("Options"))
                .Code.AddLine(Code.This().Property("Database").Method("SetCommandTimeout", Code.Number(configuration.DataContext.CommandTimeout)).Close());
            }
            else
            {
                constructor.WithBaseConstructor(Code.NullCoalescing(Code.Local("connectionString"), Code.Local(defaultConnectionProperty)))
                .Code.AddLine(Code.This().Property("Database").Property("CommandTimeout").Assign(Code.Number(configuration.DataContext.CommandTimeout)).Close());
            }

            MethodTemplate    createMethod = dataContext.AddMethod("OnModelCreating", Code.Void()).Protected().Override();
            ParameterTemplate modelBuilder = createMethod.AddParameter(Code.Type(configuration.IsCore ? "ModelBuilder" : "DbModelBuilder"), "modelBuilder");

            if (!configuration.IsCore)
            {
                createMethod.Code.AddLine(Code.Local(modelBuilder).Property("Configurations").Method("AddFromAssembly", Code.This().Method("GetType").Property("Assembly")).Close());
            }

            foreach (EntityTransferObject entity in transferObjects.OfType <EntityTransferObject>())
            {
                createMethod.Code.AddLine(Code.Local(modelBuilder).GenericMethod("Entity", entity.Model.ToTemplate()).BreakLine()
                                          .Method("ToTable", Code.String(entity.Table), Code.String(entity.Schema)).BreakLine()
                                          .Method("HasKey", Code.Lambda("x", Code.Csharp("new { " + string.Join(", ", entity.Keys.Select(key => $"x.{key.Name}")) + " }"))).Close());
            }
            foreach (StoredProcedureTransferObject storedProcedure in transferObjects.OfType <StoredProcedureTransferObject>())
            {
                dataContext.AddMethod(storedProcedure.Name, storedProcedure.ReturnType.ToTemplate())
                .Code.AddLine(Code.This().Property("Database").Method("ExecuteSqlCommand", Code.String($"exec {storedProcedure.Schema}.{storedProcedure.Name}")).Close());
            }
            return(dataContext);
        }
Esempio n. 25
0
 private ClassTemplate(ClassTemplate.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Esempio n. 26
0
 public string VisitClassTemplateDecl(ClassTemplate template)
 {
     return(VisitDeclaration(template));
 }
Esempio n. 27
0
 private ClassTemplate(ClassTemplate.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Esempio n. 28
0
 public CSharpTypePrinterResult VisitClassTemplateDecl(ClassTemplate template)
 {
     throw new NotImplementedException();
 }
Esempio n. 29
0
 public bool VisitClassTemplateDecl(ClassTemplate template)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 30
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return template.TemplatedClass.Visit(this);
 }
Esempio n. 31
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return(false);
 }
 public static ClassTemplate FormatName(this ClassTemplate classTemplate, IConfiguration configuration)
 {
     classTemplate.Name = Formatter.FormatClass(classTemplate.Name, configuration);
     return(classTemplate);
 }
 public static ClassTemplate Abstract(this ClassTemplate classTemplate, bool value = true)
 {
     classTemplate.IsAbstract = value;
     return(classTemplate);
 }
Esempio n. 34
0
 private ClassTemplate(ClassTemplate.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
 public static ClassTemplate WithUsing(this ClassTemplate classTemplate, string nameSpace, string type, string path)
 {
     classTemplate.AddUsing(nameSpace, type, path);
     return(classTemplate);
 }
Esempio n. 36
0
 internal ClassTemplate(ClassTemplate.Internal native)
     : this(&native)
 {
 }
Esempio n. 37
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return false;
 }
 public static TypeTemplate ToType(this ClassTemplate classTemplate)
 {
     return(classTemplate.IsGeneric() ? Code.Instance.Generic(classTemplate.Name, classTemplate.Generics.Select(x => Code.Instance.Type(x.Name)).ToArray()) : Code.Instance.Type(classTemplate.Name));
 }
Esempio n. 39
0
 public virtual bool VisitClassTemplateDecl(ClassTemplate template)
 {
     throw new NotImplementedException();
 }
 public static ClassTemplate WithComment(this ClassTemplate classTemplate, string description, CommentType type = CommentType.Block)
 {
     classTemplate.Comment = new CommentTemplate(description, type);
     return(classTemplate);
 }
Esempio n. 41
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return VisitClassDecl(template.TemplatedClass);
 }
Esempio n. 42
0
 public string VisitClassTemplateDecl(ClassTemplate template)
 {
     throw new NotImplementedException();
 }
Esempio n. 43
0
 internal ClassTemplate(ClassTemplate.Internal native)
     : this(__CopyValue(native))
 {
 }
Esempio n. 44
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     return(template.TemplatedClass.Visit(this));
 }
Esempio n. 45
0
 internal ClassTemplate(ClassTemplate.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
Esempio n. 46
0
        internal ClassTemplate GeneratePocoClass(IEdmSchemaType ent)
        {
            if (ent == null)
            {
                return(null);
            }
            var className     = ent.Name;
            var classTemplate = new ClassTemplate
            {
                Name         = className,
                OriginalName = className,
                IsEnum       = ent is IEdmEnumType,
                NameSpace    = ent.Namespace,
            };

            switch (ent)
            {
            case IEdmEnumType enumType:
            {
                classTemplate.EnumElements = GetEnumElements(enumType, out var isFlags);         //fill enum elements for enumtype
                classTemplate.IsFlags      = isFlags;
                return(classTemplate);
            }

            case IEdmEntityType entityType:
            {
                classTemplate.IsEntity  = true;
                classTemplate.IsAbstrct = entityType.IsAbstract;
                // Set base type by default
                var baseEntityType = entityType.BaseEntityType();
                if (baseEntityType != null)
                {
                    classTemplate.BaseType = baseEntityType.FullName();                                 //.Name
                }
                classTemplate.EntitySetName = GetEntitySetName(ent);
                break;
            }

            //parent of complex types
            case IEdmComplexType complexType:
            {
                classTemplate.IsComplex = true;
                classTemplate.IsAbstrct = complexType.IsAbstract;
                if (complexType.BaseType != null)
                {
                    classTemplate.BaseType = complexType.BaseType.ToString();
                }
                break;
            }

            default:
                return(null);
            }

            //fill keys
            var list = GetKeys(ent);

            if (list != null)
            {
                classTemplate.Keys.AddRange(list);
            }

            //fill navigation properties
            var list2 = GetNavigation(ent);

            if (list2 != null)
            {
                classTemplate.Navigation.AddRange(list2);
            }

            var entityProperties = GetClassProperties(ent);

            //set the key ,comment
            foreach (var property in entityProperties)
            {
                property.ClassName    = className;
                property.OriginalName = property.PropName;
                if (classTemplate.Navigation.Exists(x => x == property.PropName))
                {
                    property.IsNavigate = true;
                }

                if (classTemplate.Keys.Exists(x => x == property.PropName))
                {
                    property.IsKey = true;
                }
                var comment = (property.IsKey ? "PrimaryKey" : string.Empty)
                              + (property.IsNullable ? string.Empty : " not null");
                if (!string.IsNullOrEmpty(comment))
                {
                    property.PropComment = comment;
                }
            }

            classTemplate.Properties.AddRange(entityProperties);
            return(classTemplate);
        }
Esempio n. 47
0
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            var expansions = template.PreprocessedEntities.OfType<MacroExpansion>();

            var expansion = expansions.FirstOrDefault(e => e.Text.StartsWith(Prefix + "_CONSTRAINT"));
            if (expansion != null)
            {
                var args = GetArguments(expansion.Text);
                for (var i = 0; i < template.Parameters.Count && i < args.Length; ++i)
                {
                    var param = template.Parameters[i];
                    param.Constraint = args[i];
                    template.Parameters[i] = param;
                }
            }

            return base.VisitClassTemplateDecl(template);
        }
Esempio n. 48
0
        private void GenerateDbInputModel()
        {
            var dt       = _dbTable;
            var nameText = RepositoryNamespace ?? "Aescr.Model";

            for (int index = 0; index < dt.Rows.Count;)
            {
                DataRow dataRow   = dt.Rows[index];
                var     inputFile = CreateFile();
                inputFile.DownloadPath = DownloadPath + "/InputModel";
                var viewFile = CreateFile();
                viewFile.DownloadPath = DownloadPath + "/ViewModel";
                var updateFile = CreateFile();
                updateFile.DownloadPath = DownloadPath + "/InputModel";
                var namespaceTemplate = inputFile.CreateNamespace();
                namespaceTemplate.NamespaceName = nameText;
                var viewTemplate = namespaceTemplate.DeepClone();
                viewFile.AddNamespace(viewTemplate);
                var updateTemplate = namespaceTemplate.DeepClone();
                updateFile.AddNamespace(updateTemplate);
                ClassTemplate classTemplate = new ClassTemplate();
                classTemplate.ClassName           = dataRow["表名"].ToString();
                classTemplate.ClassName           = classTemplate.ClassName.Replace("_", "");
                classTemplate.RealName            = dataRow["表名"].ToString();
                classTemplate.Comment             = new Code.Template.CommentTemplate();
                classTemplate.Comment.CommentName = dataRow["表说明"].ToString();
                do
                {
                    DataRow tempRow = dt.Rows[index];
                    var     field   = new Code.Template.FieldTemplate();
                    var     comment = new Code.Template.CommentTemplate();
                    field.FieldName     = tempRow["字段名"].ToString();
                    comment.CommentName = tempRow["字段说明"].ToString();
                    field.DbType        = tempRow["类型"].ToString();
                    field.MaxLength     = tempRow["长度"].ToString().ToInt64();
                    field.MinLength     = 0;
                    field.Comment       = comment;
                    field.IsProperty    = true;
                    field.IsKey         = tempRow["主键"].ToString() == "√";
                    field.CanNull       = tempRow["允许空"].ToString() == "√";
                    if (_dbGenerate.DbType == DataBaseType.MsSQL)
                    {
                        field.FieldTypeName = DbToCsharpType.MsSqlToCsharpType(tempRow["类型"].ToString());
                    }
                    else if (_dbGenerate.DbType == DataBaseType.MySQL)
                    {
                        field.FieldTypeName = DbToCsharpType.MySqlToCsharpType(tempRow["类型"].ToString());
                    }

                    if (field.CanNull == false)
                    {
                        classTemplate.AddField(field);
                        var inputClass  = classTemplate.DeepClone();
                        var viewClass   = classTemplate.DeepClone();
                        var updateClass = classTemplate.DeepClone();
                        inputClass.ClassName = "Input" + inputClass.ClassName;
                        namespaceTemplate.AddClass(inputClass);
                        viewClass.ClassName = "View" + viewClass.ClassName;
                        viewTemplate.AddClass(viewClass);
                        updateClass.ClassName = "Update" + updateClass.ClassName;
                        updateTemplate.AddClass(updateClass);
                    }
                    index++;
                    if (index == dt.Rows.Count)
                    {
                        break;
                    }
                } while (string.IsNullOrWhiteSpace(dt.Rows[index]["表名"].ToString()));
            }
        }
Esempio n. 49
0
 public static ClassTemplate __CreateInstance(ClassTemplate.Internal native, bool skipVTables = false)
 {
     return new ClassTemplate(native, skipVTables);
 }
Esempio n. 50
0
 public override bool VisitClassTemplateDecl(ClassTemplate template)
 {
     template.ExplicitlyIgnore();
     return(false);
 }
Esempio n. 51
0
 protected ClassTemplate(ClassTemplate.Internal* native, bool skipVTables = false)
     : base((CppSharp.Parser.AST.Template.Internal*) null)
 {
     __PointerAdjustment = 0;
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
Esempio n. 52
0
        public override bool VisitClassTemplateDecl(ClassTemplate template)
        {
            CheckForTemplateConstraints(template);

            return base.VisitClassTemplateDecl(template);
        }
Esempio n. 53
0
 private static ClassTemplate.Internal* __CopyValue(ClassTemplate.Internal native)
 {
     var ret = Marshal.AllocHGlobal(224);
     CppSharp.Parser.AST.ClassTemplate.Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return (ClassTemplate.Internal*) ret;
 }
Esempio n. 54
0
 public override TypePrinterResult VisitClassTemplateDecl(ClassTemplate template)
 {
     return(VisitDeclaration(template));
 }
Esempio n. 55
0
 protected ClassTemplate(ClassTemplate.Internal* native, bool isInternalImpl = false)
     : base((CppSharp.Parser.AST.Template.Internal*) native)
 {
 }
 public static UsingTemplate AddUsing(this ClassTemplate classTemplate, string nameSpace, string type, string path)
 {
     return(classTemplate.AddUsing(new UsingTemplate(nameSpace, type, path)));
 }