0

I have a need to generate C# code for my Country entity that will inherit from a base Entity class providing stong typed argument to denote the fact that my PK (@id) is of type Guid that is Id property on the base class having implictly type Guid. So I have 2 problems:

  1. There is no Guid type in telosys.

  2. How to define PK using Generic base class typed argument?

    public class Country : Entity<Guid>
    {

    }

    public abstract class Entity<TKey> : Entity, IEntity<TKey>
    {
        public virtual TKey Id { get; protected set; }
        protected Entity(TKey id)
        {
            Id = id;
        }
    }

https://www.telosys.org/dsl-syntax.html

  . binary
  . boolean
  . byte
  . date
  . decimal
  . double
  . float
  . int
  . long
  . short
  . string
  . time
  . timestamp

https://doc.telosys.org/dsl-model/tags

For example a special property name: metaproperty I can parse to get $entity inheritance typed argument. I need other metadata. Entity class as Id property.It can be string, int, long etc

User {
  metaproperty: string {#base       
  @Label("typed_param:Guid;name:Id;form_sections:Info section~1|Contact sec~2;display_layout:rows(n)_cols(12)")}
  FirstName : string {@Label("form_section:~1;display_layout:row(1)col(1)colspan(3)")};
  LastName: string {@Label("form_section:~1;display_layout:row(1)col(2)colspan(9)")};
  Phone: string {@Label("form_section:~2;display_layout:row(1)col(1)colspan(12)")};
}

I need some mechanizam to display the layout of fields in the form for each property I want in view/edit screens
I can certaily generate some .json structure and add metadata there as well. Even have a GUI with drag and drop feature to define rows, cols and row or col spans.
Rad
  • 933
  • 1
  • 15
  • 32
  • You can't make your own Guid class? – Christopher Hamkins Nov 24 '21 at 07:54
  • what is telosys ? a class ? – TimChang Nov 24 '21 at 07:55
  • If I understand your need correctly it is not a problem about "type" in Telosys (types are for attributes), it's more a question about how to express that "Country" class must extends "Entity" ? – lgu Nov 24 '21 at 19:00
  • For information: Telosys is a code generator ( https://www.telosys.org/ ) – lgu Nov 24 '21 at 19:02
  • @Igu. You are right. It is about metadata that telosys can provide. Here is the syntax of dsl model: https://www.telosys.org/dsl-syntax.html – Rad Nov 25 '21 at 03:50
  • I was thinking to add a property like extrametadata : string {@Id #Guid} where # prefixed tag denotes the fact that I want to have and identifier which is of Guid type, but in abp.io framework that I use, the identifier is called Id and is of type denoted in concrete typed parameter. I would reach into $entity attributes and find this specially named attribute: extrametadata and dynamically enable this customization. I would skip this attribute when iterating over all attributes and generating properties for example – Rad Nov 25 '21 at 04:06

3 Answers3

1

Regarding the class, annotations and tags at the entity level are available since Telosys 4.0.

Before Telosys 4.0 there are no annotations (or tags) at the entity level. But you can use a file to define the entities which should extend another class.

Step 1 - in your model folder define a list of entities in a file "variables.txt"

Example for entities "Foo", "Bar" and "Country"

#set ( $guidEntities = ["Foo", "Bar", "Country" ] )

Step 2 - in your template evaluate the content of this file in order to define a variable for the list and use it to check if the current entity must extend Entity

Example:

## Load content from file "variables.txt" located in current model folder
#set( $file = $fn.fileFromModel("variables.txt") )
#set( $fileContent = $file.loadContent() ) 

## Use 'evaluate(statement)' to convert the file content in list variable
#evaluate( $fileContent )

## Now the list $guidEntities is defined and we can use it
## to check if it contains the current entity name
#if ( $guidEntities.contains($entity.name) ) 
public class $entity.name : Entity<Guid>  
#else 
public class $entity.name
#end 

Note: The list is defined in a separate file, located in the model folder as it can be seen as part of the model definition (and it can be used in multiple templates)

lgu
  • 2,342
  • 21
  • 29
  • Thank you professor Laurent :) I was thinking to do both with that #Guid tag which I can attach to a specially named property: metaproperty : string and I planned to find this attribute when outputing $entity inheritance providing specific typed argument. – Rad Nov 26 '21 at 22:43
  • For example a special property name: metaproperty I can parse to get $entity inheritance typed argument. I need other metadata. Entity class as Id property.It can be string, int, long etc User { metaproperty: string {#base @Label("typed_param:Guid;name:Id;form_sections:Info section~1|Contact sec~2;display_layout:rows(n)_cols(12)")} FirstName : string {@Label("form_section:~1;display_layout:row(1)col(1)colspan(3)")} LastName: string {@Label("form_section:~1;display_layout:row(1)col(2)colspan(9)")} Phone: string {@Label("form_section:~2;display_layout:row(1)col(1)colspan(3)")} – Rad Nov 26 '21 at 23:17
  • Laurent. We can continue conversation on Linkedin. I would need support. I am building an advanced abp.io asp.net core generator with code re-generation to preserve changes made by a developer and I am using specific java classess to run some abp.io cli commands to create solutions and modules where I can generate my code. I want to have something like Azure Desired State Configuration (DSC) is for infrasture, to express what main app solution will be named and where to create it and what extra modules are needed to create and add to the solution.This is to build modular monolith applications – Rad Nov 26 '21 at 23:34
  • I do have a prototype of using swagger document where I can choose the payload for forms creating/editing and I can drag and drop fields on a form with let's say 3 columns and n rows. I can build some metadata json I can use to do code generation do put fields in appropriate columns. – Rad Nov 26 '21 at 23:39
0

Regarding the attribute type, as you mentioned in your comment, the easiest way is to manage it with a tag.

In the model set a "guid" tag for the attribute having the GUID :

MyEntity {
 myattribute : string { #Guid } ;
}

In the template you can use this way:

#if ( $attrib.hasTag("Guid ") )  
 do something
#end
lgu
  • 2,342
  • 21
  • 29
0

Since Telosys v 4.0.0 you can use the annotation @Extends(SuperClass)

see https://doc.telosys.org/dsl-model/annotations#extends-string

You can also use a "tag" at entity level, eg : #EntityWithGuid or #Entity(Guid)

lgu
  • 2,342
  • 21
  • 29