Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update T4 templates #4161

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft

Update T4 templates #4161

wants to merge 53 commits into from

Conversation

igor-tkachev
Copy link
Member

No description provided.

# Conflicts:
#	NuGet/Pack.cmd
#	NuGet/PackLocal.cmd
#	linq2db.sln
…asses, and methods to facilitate code generation and rendering. These include interfaces and classes for attributes, classes, events, fields, members, methods, models, namespaces, properties, and types. The changes also include the removal of methods and a class from the T4Model.ttinclude file, and the addition of a new assembly reference in the LinqToDB.Tools.ttinclude file. Minor changes include the correction of a misspelled word in a comment and updates to file paths and declarations in the ModelTest.tt file.

Key Changes:

1. Addition of new assembly reference `linq2db.Tools.dll` in `LinqToDB.Tools.ttinclude` file.
2. Removal of `RemoveSpace` method, `SkipSpacesAndInsert` method, and `ModelType` class from `T4Model.ttinclude` file.
3. Addition of `AccessModifier` enum in `AccessModifier.cs` file.
4. Addition of `IAttribute` interface and `Attribute<T>` class in `Attribute.cs` file.
5. Addition of `IClass` interface and `Class<T>` class in `Class.cs` file.
6. Addition of `CodeTemplateGenerator` class in `CodeTemplateGenerator.cs` file.
7. Addition of `IEvent` interface and `Event<T>` class in `Event.cs` file.
8. Addition of `IField` interface and `Field<T>` class in `Field.cs` file.
9. Addition of `IClassMember` interface in `IClassMember.cs` file.
10. Addition of `ITree` interface in `ITree.cs` file.
11. Addition of `IMemberBase` interface and `MemberBase` abstract class in `MemberBase.cs` file.
12. Addition of interfaces and classes in `MemberGroup.cs`, `Method.cs`, `ModelSource.cs`, `ModelType.cs`, `Namespace.cs`, `Property.cs`, and `TypeBase.cs` files.
13. Updates to file paths and declarations in `ModelTest.tt` file.
…various classes in the `T4Model.ttinclude` file, the modification of interfaces in `Event.cs`, `Field.cs`, and `Property.cs` files, and the introduction of a `Render` method and a static `Create` method in `T4Model.ttinclude`.

1. Constructors have been added to the `Property`, `Field`, `Event`, `Method`, and `Attribute` classes in the `T4Model.ttinclude` file. These constructors allow for the creation of these objects with different parameters, offering more flexibility in their instantiation.

2. The interfaces `IEvent`, `IField`, and `IProperty` in the `Event.cs`, `Field.cs`, and `Property.cs` files have been updated. They now also inherit from `IClassMember`, which adds more functionality to these interfaces.

3. A `Render` method has been added to the `Property`, `Field`, `Event`, `Method`, and `Attribute` classes in `T4Model.ttinclude`. This method accepts a `GeneratedTextTransformation` object and a boolean `isCompact`, and calls the `Render` method on the `CodeTemplateGenerator` of the `GeneratedTextTransformation` object.

4. A static `Create` method has been added to the `Method` class in `T4Model.ttinclude`. This method accepts a string `type`, a string `name`, an `IEnumerable<string>` of parameters, and an `IEnumerable<string>` of body, and returns a new `Method` object.
…opertyChanged.ttinclude` and `CodeTemplateGenerator.NotifyPropertyChanged.cs` files. The `NotifyPropertyChangedImpl` method was removed from the former and replaced with a call to `CodeTemplateGenerator.NotifyPropertyChangedImplementation<MemberGroup,Method,Field,Event,Attribute>()`. The `ImplementNotifyPropertyChanging` and `SkipNotifyPropertyChangedImplementation` properties were also moved from `NotifyPropertyChanged.ttinclude` to `CodeTemplateGenerator.NotifyPropertyChanged.cs`. Additionally, the `INotifyingPropertyProperty` interface was transferred from `CodeTemplateGenerator.Validation.cs` to `CodeTemplateGenerator.NotifyPropertyChanged.cs`.

In the `Property` class, the `IsNotifying` and `Dependents` fields were converted into properties with getters and setters. The `IClassMember` interface was removed from the `IMemberBase` interface and `MemberBase` class, and added to the `IProperty` interface and `Property` class.

New constraints were added to the `Event` and `Field` classes, and new properties were added to the `IMemberGroup` interface. The `JetBrains.Annotations` namespace and `ToCamelCase` method were added to `CodeTemplateGenerator.cs`.

Here is a list of the changes:

1. `NotifyPropertyChangedImpl` method was removed from `NotifyPropertyChanged.ttinclude` and replaced with a call to `CodeTemplateGenerator.NotifyPropertyChangedImplementation<MemberGroup,Method,Field,Event,Attribute>()`.
2. `ImplementNotifyPropertyChanging` and `SkipNotifyPropertyChangedImplementation` properties were moved from `NotifyPropertyChanged.ttinclude` to `CodeTemplateGenerator.NotifyPropertyChanged.cs`.
3. `IsNotifying` and `Dependents` fields in `Property` class were changed to properties with getters and setters.
4. `INotifyingPropertyProperty` interface was moved from `CodeTemplateGenerator.Validation.cs` to `CodeTemplateGenerator.NotifyPropertyChanged.cs`.
5. `JetBrains.Annotations` namespace was added to `CodeTemplateGenerator.cs`.
6. `ToCamelCase` method was added to `CodeTemplateGenerator.cs`.
7. `where T : Event<T>` and `where T : Field<T>` constraints were added to `Event` and `Field` classes respectively.
8. `IClassMember` interface was removed from `IMemberBase` interface and `MemberBase` class, and added to `IProperty` interface and `Property` class.
9. `IsCompact`, `IsPropertyGroup`, and `Members` properties were added to `IMemberGroup` interface.
10. `INotifyingPropertyProperty` interface and `NotifyPropertyChangedImplementation` method were added to `CodeTemplateGenerator.NotifyPropertyChanged.cs`. The `ImplementNotifyPropertyChanging` and `SkipNotifyPropertyChangedImplementation` properties were also added to this class.
11. `OnPropertyChangedBody`, `OnPropertyChangedArgBody`, `OnPropertyChangingBody`, and `OnPropertyChangingArgBody` properties were added to `CodeTemplateGenerator.NotifyPropertyChanged.cs`.
The most significant changes involve the replacement of the `NotifyDataErrorInfoImpl` method with a more flexible, generic method `NotifyDataErrorInfoImplementation` in the `CodeTemplateGenerator` class. This new method is housed in a newly added file `CodeTemplateGenerator.NotifyDataErrorInfo.cs`. The new method is designed to work with any types that meet the constraints, unlike the original method which was limited to specific types. The new method also incorporates the `IPropertyValidation` and `IClass` interfaces, providing a more abstract way to work with properties and classes.

Additionally, the `NotifyDataErrorInfoImplementation` method enhances classes by adding the `INotifyDataErrorInfo` interface if it's not already implemented, and includes the necessary members to support this interface. It also ensures the necessary using directives are present in the model.

Changes:

1. Removal of `NotifyDataErrorInfoImpl` method in `NotifyDataErrorInfo.ttinclude` file and its replacement with a call to `CodeTemplateGenerator.NotifyDataErrorInfoImplementation<MemberGroup,Method,Property,Field,Event,Attribute>()` in the `BeforeGenerateModel` method.
2. Addition of a new file `CodeTemplateGenerator.NotifyDataErrorInfo.cs` containing the `CodeTemplateGenerator` class with a new generic method `NotifyDataErrorInfoImplementation`.
3. The new method uses the `IPropertyValidation` and `IClass` interfaces.
4. The new method adds the `INotifyDataErrorInfo` interface to classes that don't already implement it, and adds the necessary members to support this interface.
5. The new method also adds necessary using directives if they are not already present in the model.
The code changes primarily involve a significant refactoring of the `CodeTemplateGenerator` class, which appears to have been renamed to `ModelGenerator`. This refactoring includes the removal of several methods and classes related to data validation and property change notification, and the addition of new methods and classes that provide similar functionality. The changes also include the removal of several files related to the model generator, and the addition of new files that provide similar functionality.

Key Changes:

1. The `CodeTemplateGenerator` class has been renamed to `ModelGenerator` in various files, suggesting a significant refactoring of this class.
2. Several methods and classes related to data validation and property change notification in the `CodeTemplateGenerator` class have been removed, including `NotifyDataErrorInfoImplementation`, `NotifyPropertyChangedImplementation`, and `ValidationImplementation`.
3. New methods and classes have been added that provide similar functionality to the removed methods and classes, including `NotifyDataErrorInfoImplementation<TMemberGroup,TMethod,TField,TEvent,TAttribute>()`, `NotifyPropertyChangedImplementation<TMemberGroup,TMethod,TField,TEvent,TAttribute>()`, and `ValidationImplementation<TClass,TMemberGroup,TMethod,TField,TAttribute>()`.
4. Several files related to the model generator have been removed, including `AccessModifier.cs`, `Attribute.cs`, `Class.cs`, `MemberGroup.cs`, `Method.cs`, `ModelSource.cs`, `ModelType.cs`, `Namespace.cs`, `Property.cs`, and `TypeBase.cs`.
5. New files have been added that provide similar functionality to the removed files, including `AccessModifier.cs`, `Attribute.cs`, `Class.cs`, `Method.cs`, `ModelGenerator.cs`, `ModelSource.cs`, `ModelType.cs`, `Namespace.cs`, `Property.cs`, and `TypeBase.cs`.
6. The `Class.cs` file has been updated to include two new classes: `IClass` and `Class<T>`, which define the structure for a class and provide methods for rendering the class and setting the tree structure.
7. New namespaces `System`, `System.Globalization`, and `System.Linq` have been added to `CodeTemplateGenerator.Validation.cs`.
8. New interfaces and classes have been added to the `LinqToDB.Tools.ModelGeneration` namespace, including `IPropertyValidation`, `IEvent`, `IField`, `IClassMember`, `ITree`, `ModelGenerator`, `Event<T>`, `Field<T>`, `MemberBase`, and `MemberGroup<TMemberGroup>`.
9. The `Method.cs` file has been updated to include a new interface `IMethod` and a new class `Method`, which define the structure of a method and provide an implementation of this structure.
10. The `ModelGenerator.cs` file has been updated to include a new class `ModelGenerator`, which is responsible for generating the model.
11. The `Property.cs` and `TypeBase.cs` files have been added, which include new interfaces and classes related to properties and types in a class.
…rom various files, including `ToCamelCase`, `NotifyDataErrorInfoImplementation`, `NotifyPropertyChangedImplementation`, and `ValidationImplementation`. These methods were removed from `T4Model.ttinclude`, `CodeTemplateGenerator.NotifyDataErrorInfo.cs`, `CodeTemplateGenerator.NotifyPropertyChanged.cs`, and `CodeTemplateGenerator.Validation.cs` respectively.

Additionally, the inheritance of `IClassMember` was removed from the `IEvent` and `IField` interfaces in `Event.cs` and `Field.cs`.

Several changes were made to improve code readability and efficiency, such as replacing negative conditions with positive ones in `MemberGroup.cs`, and replacing string concatenation with string interpolation in `MemberGroup.cs` and `TypeBase.cs`.

A space was also removed before the parentheses in the `WriteParams` method call in `ModelGenerator.cs`.

New features were added, including a new method `NotifyDataErrorInfoImplementation` in `ModelGenerator.NotifyDataErrorInfo.cs`, a new method `NotifyPropertyChangedImplementation` in `ModelGenerator.NotifyPropertyChanged.cs`, and a new method `ValidationImplementation` in `ModelGenerator.Validation.cs`. These methods add support for data error notification, property change notification, and property validation in the model generator.

Changes:

1. Removed `ToCamelCase` method from `T4Model.ttinclude`.
2. Removed `NotifyDataErrorInfoImplementation` method from `CodeTemplateGenerator.NotifyDataErrorInfo.cs`.
3. Removed `NotifyPropertyChangedImplementation` method from `CodeTemplateGenerator.NotifyPropertyChanged.cs`.
4. Removed `ValidationImplementation` method from `CodeTemplateGenerator.Validation.cs`.
5. Removed `IClassMember` inheritance from `IEvent` and `IField` interfaces in `Event.cs` and `Field.cs`.
6. Changed `BeginConditional` method in `MemberBase.cs` to use string interpolation.
7. Replaced negative condition in `MemberGroup.cs`.
8. Replaced string concatenation with string interpolation in `MemberGroup.cs` and `TypeBase.cs`.
9. Removed a space before parentheses in `WriteParams` method call in `ModelGenerator.cs`.
10. Added `NotifyDataErrorInfoImplementation` method in `ModelGenerator.NotifyDataErrorInfo.cs`.
11. Added `NotifyPropertyChangedImplementation` method in `ModelGenerator.NotifyPropertyChanged.cs`.
12. Added `ValidationImplementation` method in `ModelGenerator.Validation.cs`.
…al files and the addition of new ones. The most notable changes include the refactoring of the `EditableObject.ttinclude` file, the addition of new files defining various interfaces and classes such as `AssociationType.cs`, `Column.cs`, `ForeignKey.cs`, and `ModelGenerator.EditableObject.cs`, and the modification of existing files like `Class.cs`, `ModelGenerator.cs`, `ModelSource.cs`, `Namespace.cs`, and `TypeBase.cs`.

1. The `EditableObject.ttinclude` file was refactored, with the `EditableObjectImpl` method being replaced with a call to `ModelGenerator.EditableObjectImplementation<MemberGroup,Method,Property,Field>()`. The `SetPropertyValueAction` was also updated to cast `obj` to `Property` before setting `IsEditable`.

2. The `NotifyPropertyChanged.ttinclude` file was updated to cast `obj` to `Property` before setting `IsNotifying` in the `SetPropertyValueAction`.

3. A line was removed from the `ObsoleteAttributes.ttinclude` file that included the `T4Model.ttinclude` and `LinqToDB.ttinclude` files.

4. The `T4Model.ttinclude` file saw several changes, including the removal of the `WriteSpaces` method, the update of `SetPropertyValueAction` to use `ModelGenerator.SetPropertyValueAction` instead of a static event, and the addition of a new `SetPropertyValue` method that calls `ModelGenerator.SetPropertyValue`.

5. New files were added, including `AssociationType.cs` that defines an `AssociationType` enum, `Column.cs` and `ForeignKey.cs` that define `IColumn` and `IForeignKey` interfaces and their respective classes, and `ModelGenerator.EditableObject.cs` that defines a new interface `IEditableObjectProperty` and a new class `ModelGenerator`.

6. The `Class.cs` file was updated to add a constraint to the `Class<T>` class that `T` must be a `Class<T>`.

7. The `ModelGenerator.cs` file was modified to use range syntax for string slicing in the `ToCamelCase` method.

8. The `IModelSource` interface and the `ModelSource.cs` file were updated to include a new `Types` property.

9. The `Namespace.cs` file was updated to use the new `ITypeBase` interface for the `Types` property.

10. New classes and interfaces were added in `Parameter.cs`, `Procedure.cs`, `Table.cs`, and `TableContext.cs`.

11. The `ITypeBase` interface and the `TypeBase.cs` file were updated to include setters for all properties and a new `Render` method.

12. A new abbreviation `FK` was added to the C# naming conventions in `linq2db.sln.DotSettings`.
…f several methods such as `GetTable`, `GetProcedure`, `GetColumn`, `GetFK`, and `GetForeignKey`. These methods have been reformatted for better readability and their functionality remains the same. The `GetFK` method now calls the `GetForeignKey` method instead of directly calling the `ModelGenerator.GetForeignKey` method, suggesting additional logic in the `GetForeignKey` method.

The `IMemberBase` interface in `MemberBase.cs` has been significantly updated with reordered properties and new properties added. The `ModelType` property in the `IColumn` interface in `Column.cs` has been made settable, and the `SetPropertyValueAction` event in `T4Model.ttinclude` now accepts `IProperty` instead of `Property`.

A new method `GetConstructors` has been added to the `ModelGenerator` class in `ModelGenerator.cs`, and the `ToStringLiteral` method in the same class has been made static. The `IModelSource` interface and the `ModelSource<TModel,TNamespace>` class in `ModelSource.cs` have been updated to include new properties and use `INamespace` instead of `TNamespace`.

The `Namespace<T>` class in `Namespace.cs` now implements the new `INamespace` interface, and the `Property<T>` class in `Property.cs` has been updated with a settable `EnforceNotNullable` property and reformatted `Name` property.

Changes:

1. Reformatting and re-adding of `GetTable`, `GetProcedure`, `GetColumn`, `GetFK`, and `GetForeignKey` methods.
2. `GetFK` method now calls `GetForeignKey` method.
3. Significant updates to `IMemberBase` interface in `MemberBase.cs`.
4. `ModelType` property in `IColumn` interface in `Column.cs` made settable.
5. `SetPropertyValueAction` event in `T4Model.ttinclude` updated to accept `IProperty`.
6. Addition of `GetConstructors` method to `ModelGenerator` class in `ModelGenerator.cs`.
7. `ToStringLiteral` method in `ModelGenerator.cs` made static.
8. Updates to `IModelSource` interface and `ModelSource<TModel,TNamespace>` class in `ModelSource.cs`.
9. `Namespace<T>` class in `Namespace.cs` now implements `INamespace` interface.
10. Updates to `Property<T>` class in `Property.cs`.
…les, properties, classes, and methods across several files to follow consistent naming conventions. The changes also include the addition of new properties and functions, modification of existing functions, and removal of certain elements.

Key Changes:

1. A new property `ConvertUpperNamesToLower` was added to the `ModelGenerator` class to determine if uppercase names should be converted to lowercase. This property was used in the `Firebird.tt` file.
2. The `GenerateProviderSpecificTable` function was modified to cast the input parameter to `Table` type before using it.
3. The usage of `AssociationType` was removed from `ModelGenerator.DataModel.cs` and replaced with `AssociationType.OneToMany`.
4. The `BuilderSingle` function was refactored to use pattern matching.
5. The `Convert` function was updated to check if the value is already quoted before adding quotes.
6. A new reference to `IBM.Data.DB2.dll` was added in `Tests.csproj` for the `net472` target framework.
7. The `PostgreSQL.11.tt` file was removed and the `PostgreSQL.16.tt` file was added with new configurations for the PostgreSQL database.
8. The class names and property names in the Oracle.generated.cs file were changed from uppercase to PascalCase.
9. The PostgreSQL version in the project file `Tests.T4.csproj` was updated from version 11 to version 16.

Code Changes:

1. `DataModel.ttinclude`, `ModelGenerator.DataModel.cs`, `LinqToDB.PostgreSQL.ttinclude`, `LinqToDB.SapHana.ttinclude`, `PostgreSQLSqlBuilder.cs`, `PostgreSQLTools.cs`, `Tests.csproj`, `AccessODBC.tt`, `Firebird.generated.cs`, `Firebird.tt`, `Firebird3.generated.cs`, `Firebird4.generated.cs`, `Oracle.generated.cs`, `PostgreSQL.11.tt`, `PostgreSQL.16.generated.cs`, `PostgreSQL.16.tt`, `PostgreSQL.generated.cs`, `SQLite.generated.cs`, `SQLite.tt`, `SapHana.generated.cs`, `SqlCe.tt`, `Tests.T4.csproj`.
# Conflicts:
#	Tests/Linq/Data/InterceptorsTests.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants