FHT.Nullify
1.0.0
See the version list below for details.
dotnet add package FHT.Nullify --version 1.0.0
NuGet\Install-Package FHT.Nullify -Version 1.0.0
<PackageReference Include="FHT.Nullify" Version="1.0.0" />
<PackageVersion Include="FHT.Nullify" Version="1.0.0" />
<PackageReference Include="FHT.Nullify" />
paket add FHT.Nullify --version 1.0.0
#r "nuget: FHT.Nullify, 1.0.0"
#:package FHT.Nullify@1.0.0
#addin nuget:?package=FHT.Nullify&version=1.0.0
#tool nuget:?package=FHT.Nullify&version=1.0.0
Not sure what your reaction will be if you receive an instance of a class from some method call where all properties/fields are default values like 0 or null, like the one below which i encountered today:
{
Applicant: null,
ApplicantId: 0,
AuditTime: null,
AuthenticationId: 0,
BackPhotoIdUrl: null,
BrandName: null,
Capital: null,
CompanyFullName: null,
CompanyId: 0,
CompanyName: null,
Corporation: null,
CreatedTime: '0001-01-01T00:00:00+08:00',
EstablishTime: null,
IdCardNumber: null,
LicenseNo: null,
LicenseUrl: null,
Mobile: null,
Operator: null,
PhotoIdUrl: null,
Remark: null,
Status: 0,
StatusDisplayString: '未知', //this is the default value of an enum
}
I developed this c# extension is to help mitigate a particular problem while using protobuf-net.Grpc. The detailed problem is described in this issue: https://github.com/protobuf-net/protobuf-net.Grpc/issues/36. In a word, it is basically because prototobuf does not have a concept of null.
Originally, I have a set of services which are invoked directly. Recently we are migrating them into a RPC services using protobuf-net.Grpc. Originally we return null to indicate something really is not there but now we get empty non-null objects like the one above.
This util will help you convert a non-null objects with all public properties/fields equal to their default values back to null. Of course you have to explicity call the extension method, but it is much easier than checking all props/fields manually youself.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.