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

Replace T4 with raw string literale #29

Merged
merged 7 commits into from
Aug 10, 2023
Merged

Replace T4 with raw string literale #29

merged 7 commits into from
Aug 10, 2023

Conversation

hadashiA
Copy link
Member

@hadashiA hadashiA commented Aug 3, 2023

Currently, T4 is used to implement code generation, but it will be replaced with a rustic template.

motivation:

  • In macos env, T4 does not work with template evaluation, or the format changes.
  • It is likely that T4 will be used less in new projects in the future. Also, there are already soruce generators with more elementary implementations, such as C# 10's raw string literal.

@hadashiA hadashiA marked this pull request as ready for review August 10, 2023 05:38
{
return value.value;
}

public static explicit operator A(int value)
public static implicit operator A(int value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the reason of different result, implicit and explicit?

Copy link
Member Author

@hadashiA hadashiA Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. simply my mistake... fixed. 0635db9

using System;

namespace FileGenerate
#pragma warning disable CS8669
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is // <auto-generated>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 7aca1e1


namespace FileGenerate
#pragma warning disable CS8669
using System;namespace FileGenerate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require new line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed..!

{
[System.ComponentModel.TypeConverter(typeof(ATypeConverter))]
public readonly partial struct A : IEquatable<A>
readonly partial struct A : IEquatable<A>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public?

Copy link
Member Author

@hadashiA hadashiA Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The master branch seems to omit public modifier as well.
https://github.com/Cysharp/UnitGenerator/blob/master/src/UnitGenerator/CodeTemplate.tt#L34

Probably, since it is partial, the handwritten code will be followed ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, omit modifier is ok.

@@ -57,7 +51,7 @@ public override int GetHashCode()

public override string ToString()
{
return "A(" + value + ")";
return value.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different ToString result?(I don't know which is better)

Copy link
Member Author

@hadashiA hadashiA Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I generate again with master branch, I seem to get a diff of this file.

It looks like value.ToString() is probably the implementation currently in use. Is this correct?
https://github.com/Cysharp/UnitGenerator/blob/master/src/UnitGenerator/CodeTemplate.tt#L88

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall changing it to a straightforward ToString because having type information made it harder to read, and it also reduced the convenience of ToString.

So, this implementation is OK!

@hadashiA hadashiA merged commit df0421f into master Aug 10, 2023
1 check passed
@hadashiA hadashiA deleted the hadashiA/replace-t4 branch August 10, 2023 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants