You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+104-8Lines changed: 104 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -222,32 +222,128 @@ Features:
222
222
* Roslyn Analyzers and CodeFixes help the developers to implement the Value Objects correctly
223
223
* Allows custom properties and methods
224
224
* Provides appropriate factory methods for creation of new value objects based on the specified properties/fields
225
-
* Allows custom validation of [constructor](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#validation-of-the-constructor-arguments) and [factory method](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#validation-of-the-factory-method-arguments) arguments
225
+
* Allows custom [validation](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#validation) of [constructor](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#validation-of-the-constructor-arguments) and [factory method](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#validation-of-the-factory-method-arguments) arguments
226
226
* Additional features for [simple Value Objects (1 "key"-property/field)](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#simple-value-objects) and [complex Value Objects (2 properties/fields or more)](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#complex-value-objects)
227
227
* Simple Value Objects: allows cast and type conversion from key-type to Value Object and vice versa
228
-
* Simple Value Objects: provides an implementation of `IComparable<T>` if the key-property/field is an `IComparable<T>` or has an `IComparer<T>`
229
228
* Simple Value Objects: provides an implementation of `IFormattable` if the key-property/field is an `IFormattable`
230
229
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
* Provides implementation of `IComparable`, `IComparable<T>`, `IFormattable`, `IParsable<T>` and comparison operators `<`, `<=`, `>`, `>=`
231
+
*[Allows custom equality comparison](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#custom-comparer) and [custom comparer](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#custom-comparer)
232
232
* Handling of [null](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#null-in-factory-methods-yields-null) and [empty strings](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#empty-string-in-factory-methods-yields-null)
233
233
*[JSON support](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#json-serialization) (`System.Text.Json` and `Newtonsoft.Json`)
234
-
*[ASP.NET Core support](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#support-for-aspnet-core-model-binding) (model binding and model validation)
234
+
*[Support for Minimal Web Api Parameter Binding and ASP.NET Core Model Binding](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects#support-for-minimal-web-api-parameter-binding-and-aspnet-core-model-binding)
Definition of a value object with 1 custom property `Value`. All other features mentioned above are generated by the [Roslyn Source Generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview) in the background.
238
+
## Simple Value Object
239
+
240
+
Definition of 2 value objects, one with 1 `string` property `Value` and the other with an `int`.
239
241
240
242
```C#
241
243
[ValueObject]
242
-
publicpartialclassProductName
244
+
publicsealedpartialclassProductName
243
245
{
244
246
publicstringValue { get; }
247
+
}
245
248
246
-
// The member can be a private readoly field as well
247
-
//private readonly string _value;
249
+
[ValueObject]
250
+
publicsealedpartialclassAmount
251
+
{
252
+
privatereadonlyint_value;
248
253
}
249
254
```
250
255
256
+
After the implementation of the `ProductName`, a Roslyn source generator kicks in and implements the rest. Following API is available from now on.
257
+
258
+
```C#
259
+
// Factory method for creation of new instances.
260
+
// Throws ValidationException if the validation fails
261
+
ProductNamebread=ProductName.Create("Bread");
262
+
263
+
// Alternatively, using an explicit cast (behaves the same as with Create)
264
+
ProductNamebread= (ProductName)"Bread"; // is the same as calling "ProductName.Create"
265
+
266
+
-----------
267
+
268
+
// the same as above but returns a bool instead of throwing an exception (dictionary-style)
0 commit comments