andrewlock / StronglyTypedId

A Rosyln-powered generator for strongly-typed IDs
MIT License
1.52k stars 80 forks source link

[Proposal] Add attribute on entity, not on separate struct #48

Closed ZlobnyiSerg closed 2 years ago

ZlobnyiSerg commented 2 years ago

Your approach requires some bit of code that could be omitted, I believe. My way is something like:

[StronglyTypedId]
public partial class Foo {
  public IdType Id { get;set; }
}

compiles to:

public partial class Foo {
  public struct IdType {
    // Implementation here
  }
}
andrewlock commented 2 years ago

I'm not sure I quite follow your suggestion, but if I understand correctly it requires a lot more inference and magic than I'd like. It would be difficult to get right to cover all the edges, could have performance implications, and wouldn't cover many of the existing use cases, so I don't think it's something I'd like to add personally.

ZlobnyiSerg commented 2 years ago

The only disadvantage I see is code completion. In my proposal no code suggesions will appear because IdType will be unknown type until you'll compile the code. On other side we can always write attribute first, then compile.

andrewlock commented 2 years ago

The only disadvantage I see is code completion

I see two main disadvantages:

  1. The source generator would have to be more complicated
  2. It introduces ambiguity in the consuming code. Which types should be generated? Does it have to have a special type name, a special property name? Would fields work?

That second point is of significant concern for me, just to save a few key strokes. I wouldn't want to introduce that degree of indirection and ambiguity, so I'm going to close this for now. But thanks for the suggestion! 🙂