This commit is contained in:
Carl de Billy 2018-08-10 09:59:47 -04:00
Родитель c3217e40d9
Коммит 6986182bea
5 изменённых файлов: 63 добавлений и 20 удалений

Просмотреть файл

@ -1,5 +1,7 @@
# Equality Members Generation
![Equality Members generation snippet](assets/equality-snippet.png)
## Quick Start
1. Add a reference to the `Uno.CodeGen` _Nuget_ package in your project.
@ -19,7 +21,7 @@
public string B { get; }
[EqualityIgnore]
public string C { get; }
public string C { get; }
}
```
@ -31,31 +33,31 @@
// Global static helper for equality
public static bool Equals(MyEntity a, MyEntity b)
{ ... }
// IEquatable.Equals() implementation
public bool Equals(MyEntity other)
{ ... }
// override for object.Equals()
// override for object.Equals()
public override bool Equals(MyEntity other)
=> Equals(other as MyEntity);
// override for object.GetHashCode()
public override int GetHashCode()
{ ... }
// IKeyEquatable.KeyEquals() implementation
public bool KeyEquals(MyEntity other)
{ ... }
// IKeyEquatable.GetKeyHashCode() implementation
public int GetKeyHashCode()
{ ... }
// `==` Operator overload
public static bool operator ==(MyEntity a, MyEntity b)
{ ... }
// `!=` Operator overload
public static bool operator !=(MyEntity a, MyEntity b)
{ ... }
@ -68,7 +70,7 @@
var e1_3 = new MyEntity {Id ="1", A="a", B="b2", C="c2"};
var e1_4 = new MyEntity {Id ="1", A="a2", B="b2", C="c2"};
var e2 = new MyEntity {Id ="2", A="a2", B="b2", C="c2"};
// All following asserts will pass:
Assert.IsTrue(e1_1.Equals(e1_2));
@ -251,14 +253,14 @@ The generation logic for fields/properties in the class, using a first-match rul
can mute this warning in your project.
You can also consider replacing the `struct` by a `class`.
## Are equality generation automatic for generated immutables?
Yes they are by default. If you want to chagne this behavior, use the global
`[ImmutableGenerationOptions]` attribute. Example:
``` csharp
[assembly: Uno.ImmutableGenerationOptions(GenerateEqualityByDefault = true)]
```
You can also override this default by specifying per-type:
```csharp
[GeneratedImmutable(GenerateEquality = false)]

Просмотреть файл

@ -1,5 +1,7 @@
# Immutable Generation
![Equality Members generation snippet](assets/immutability-snippet.png)
## Quick Start
1. Add a reference to the `Uno.CodeGen` _Nuget_ package in your project.
@ -236,11 +238,11 @@ The generated code will produce the following effect:
Option<MyEntity> modified = new MyEntity.Builder(original.SomeOrDefault()
.WithA("new-a")
.ToImmutable();
// With generated code:
Option<MyEntity> original = Option.Some(MyEntity.Default);
Option<MyEntity> modified = original.WithA("new-a");
// You can also do that:
Option<MyEntity> x = MyEntity.None.WithA("new-a");
// **************************************************************
@ -249,7 +251,7 @@ The generated code will produce the following effect:
// same result as MyEntity.Default.WithA().
// **************************************************************
```
> For more information on the `Uno.Core` package:
> * On Github: <https://github.com/nventive/Uno.Core>
> * On Nuget: <https://www.nuget.org/packages/Uno.Core/>
@ -345,7 +347,7 @@ Yes they are by default. If you want to chagne this behavior, use the global
``` csharp
[assembly: Uno.ImmutableGenerationOptions(GenerateEqualityByDefault = true)]
```
You can also override this default by specifying per-type:
```csharp
[GeneratedImmutable(GenerateEquality = false)]

Двоичные данные
doc/assets/equality-snippet.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 49 KiB

Двоичные данные
doc/assets/immutability-snippet.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 86 KiB

Просмотреть файл

@ -2,13 +2,43 @@
`Uno.CodeGen` is a set of tools to generate C# code in msbuild based projects.
## Build status
## Generate **Equality Members** for your _C#_ classes
| Target | Branch | Status | Recent builds | Recommended Nuget packages version |
| ------ | ------ | ------ | ------ | ------ |
| `development` | [master](https://github.com/nventive/Uno.CodeGen/tree/master) | [![Build status](https://ci.appveyor.com/api/projects/status/bh83u4i2lp0hrg8r/branch/master?svg=true)](https://ci.appveyor.com/project/nventivedevops/uno-codegen/branch/master) | ![Build Stats](https://buildstats.info/appveyor/chart/nventivedevops/uno-codegen?branch=master&includeBuildsFromPullRequest=false) | [![NuGet](https://buildstats.info/nuget/Uno.CodeGen?includePreReleases=true)](https://www.nuget.org/packages/Uno.CodeGen/) |
| `stable` | [stable](https://github.com/nventive/Uno.CodeGen/tree/stable) | [![Build status](https://ci.appveyor.com/api/projects/status/bh83u4i2lp0hrg8r/branch/stable?svg=true)](https://ci.appveyor.com/project/nventivedevops/uno-codegen/branch/stable) | ![Build Stats](https://buildstats.info/appveyor/chart/nventivedevops/uno-codegen?branch=stable&includeBuildsFromPullRequest=false) | [![NuGet](https://buildstats.info/nuget/Uno.CodeGen?includePreReleases=false)](https://www.nuget.org/packages/Uno.CodeGen/) |
![Equality Members generation snippet](doc/assets/equality-snippet.png)
Features:
* Amazingly fast: absolutely **zero reflection at runtime**
* Generates both `.Equals()` and `.GetHashCode()` overrrides
* Generates equality (`==` and `!=`) operators
* Implements `IEquatable<T>`
* Works with derived classes
* **Custom comparers** supported
* Works with collection members (both same order and _unsorted_ equality)
* Works with dictionary members (both same order and _unsorted_ equality)
* Optional case insentive comparisons for strings
* Optional support for _KeyEquality_ (see doc for more details)
* Debuggable: You can put a breakpoint directly in the generated code
* Highly configureable: Generated code provides a lot of useful tips (stripped in previous snippet)
* [Documentation here](doc/Equality%20Generation.md) for Equality Members Generator
## Create **truly Immutable Entities** in _C#_
![Equality Members generation snippet](doc/assets/immutability-snippet.png)
Features:
* Automatic _Null object pattern_ generation
* Automatic generation of `<YourClass>.Builder` nested class
* Fluent `.With<field/property name>()` generation of every members of your class
* Amazingly fast: absolutely **zero reflection at runtime**
* Works with generics & derived classes (even if they are from external assembly)
* Optional support (_on_ by default) for `[GeneratedEquality]`
* Transparent support for _Newtonsoft's JSON.NET_ (activated when detected, can be turned off)
* Debuggable: You can put a breakpoint directly in the generated code
* Validation to avoid mutable code in your class
* Highly configureable: Generated code provides a lot of useful tips (stripped in previous snippet)
* [Documentation here](doc/Immutable%20Generation.md) for Immutable Entities Generator
## Available Generators
@ -20,7 +50,16 @@
| `ImmutableGenerator` | `[GenerateImmutable]` | Generate code to build truly immutable entities. | [Documentation](doc/Immutable%20Generation.md) |
| `InjectableGenerator` | `[Inject]` | Generate code to resolve and inject dependencies. | [Documentation](doc/Injectable%20Generation.md) |
## Continuous Integration Build status
| Target | Branch | Status | Recent builds | Recommended Nuget packages version |
| ------ | ------ | ------ | ------ | ------ |
| `development` | [master](https://github.com/nventive/Uno.CodeGen/tree/master) | [![Build status](https://ci.appveyor.com/api/projects/status/bh83u4i2lp0hrg8r/branch/master?svg=true)](https://ci.appveyor.com/project/nventivedevops/uno-codegen/branch/master) | ![Build Stats](https://buildstats.info/appveyor/chart/nventivedevops/uno-codegen?branch=master&includeBuildsFromPullRequest=false) | [![NuGet](https://buildstats.info/nuget/Uno.CodeGen?includePreReleases=true)](https://www.nuget.org/packages/Uno.CodeGen/) |
| `stable` | [stable](https://github.com/nventive/Uno.CodeGen/tree/stable) | [![Build status](https://ci.appveyor.com/api/projects/status/bh83u4i2lp0hrg8r/branch/stable?svg=true)](https://ci.appveyor.com/project/nventivedevops/uno-codegen/branch/stable) | ![Build Stats](https://buildstats.info/appveyor/chart/nventivedevops/uno-codegen?branch=stable&includeBuildsFromPullRequest=false) | [![NuGet](https://buildstats.info/nuget/Uno.CodeGen?includePreReleases=false)](https://www.nuget.org/packages/Uno.CodeGen/) |
## Release Notes
### 1.22.0 (May 17th 2018)
- Added support for System.Guid as a supported immutable type.
- Added support for System.Guid as a supported immutable type.