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

Configurable indentation/levels for fluent methods #1269

Open
BenjaBobs opened this issue May 29, 2024 · 0 comments
Open

Configurable indentation/levels for fluent methods #1269

BenjaBobs opened this issue May 29, 2024 · 0 comments

Comments

@BenjaBobs
Copy link

BenjaBobs commented May 29, 2024

When using fluent methods with different levels of semantic meaning, it can be difficult to maintain good readability with CSharpier currently, since it doesn't know the semantic difference between two fluent method calls.
Here's a tiny example of using a FluentMappingBuilder from Linq2Db to setup

Input:

// example from Linq2Db's FluentMappingBuilder
builder
  .Entity<Authors>().HasTableName("authors")
  .Property(x => x.Id).HasColumnName("Id").IsIdentity().IsPrimaryKey()
  .Property(x => x.Name).HasColumnName("Name").IsNotNull()
  .Entity<Book>().HasTableName("books")
  .Property(x => x.Id).HasColumnName("Id").IsIdentity().IsPrimaryKey()
  .Property(x => x.Name).HasColumnName("Name").IsNotNull()
  .Property(x => x.AuthorId).HasColumnName("AuthorId").IsNotNull()
  .Build();

Output:

builder
    .Entity<Authors>()
    .HasTableName("authors")
    .Property(x => x.Id)
    .HasColumnName("Id")
    .IsIdentity()
    .IsPrimaryKey()
    .Property(x => x.Name)
    .HasColumnName("Name")
    .IsNotNull()
    .Entity<Book>()
    .HasTableName("books")
    .Property(x => x.Id)
    .HasColumnName("Id")
    .IsIdentity()
    .IsPrimaryKey()
    .Property(x => x.Name)
    .HasColumnName("Name")
    .IsNotNull()
    .Property(x => x.AuthorId)
    .HasColumnName("AuthorId")
    .IsNotNull()
    .Build();

Expected behavior:

builder
  .Entity<Authors>().HasTableName("authors")
      .Property(x => x.Id).HasColumnName("Id").IsIdentity().IsPrimaryKey()
      .Property(x => x.Name).HasColumnName("Name").IsNotNull()
  .Entity<Book>().HasTableName("books")
      .Property(x => x.Id).HasColumnName("Id").IsIdentity().IsPrimaryKey()
      .Property(x => x.Name).HasColumnName("Name").IsNotNull()
      .Property(x => x.AuthorId).HasColumnName("AuthorId").IsNotNull()
  .Build();

But the issue is how we can teach CSharpier about the significance of calling Entity<>() vs for example calling Property() or HasColumnName().
I was thinking that maybe a comment-style approach similar to how // csharpier-ignore currently works might be a good solution.
E.g. something like this to apply to level-rules to current scope:

// csharpier-level 1 Entity<>()
// csharpier-level 2 HasTableName(), Property()

This is kind of an advanced feature, and probably more thought would have to go into it for it to become really good, but I'm submitting now to start the discussion.
Thoughts?

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

No branches or pull requests

1 participant