question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueObject should implement ToString similar to C# records

See original GitHub issue

The base ValueObject class should override ToString() and print its content, similar to how C# 9 records do it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vkhorikovcommented, Dec 2, 2020

Ah, yes, that would be great, but too much work / too high performance impact IMO.

0reactions
petre-ccommented, Jan 12, 2021

Ah I see. I was thinking you want to also include property names likes records do.

i.e.

public record User(string Name, int Age);

will produce

User { Name = John, Answer = 42 }

I’d propose creating your custom ValueObject descendant and then overriding its ToString() method to produce the serialized Json (or similar).

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# 9 Records as DDD Value Objects
Here's how you could implement the same Address class as a value object: public class Address : ValueObject { public string Street {...
Read more >
Implementing value objects
In terms of implementation, you can have a value object base class that has basic utility methods like equality based on the comparison...
Read more >
DDD Value Objects as C# Records: The Missing Manual
C# Records are very handy if you need to implement Value Objects, because they offer support for value-equality out of the box.
Read more >
Custom Equality check for C# 9 records
To conclude, I'm a bit puzzled, is restricting the override of equality methods of record objects an expected behaviour or is it because...
Read more >
3 Different Ways to Implement Value Object in C# 10
Value objects are immutable variables predefined to be held in an entity and persist in a database. The number of passing it across...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found