Pygmalions.Nebula.Translating
0.1.0
dotnet add package Pygmalions.Nebula.Translating --version 0.1.0
NuGet\Install-Package Pygmalions.Nebula.Translating -Version 0.1.0
<PackageReference Include="Pygmalions.Nebula.Translating" Version="0.1.0" />
paket add Pygmalions.Nebula.Translating --version 0.1.0
#r "nuget: Pygmalions.Nebula.Translating, 0.1.0"
// Install Pygmalions.Nebula.Translating as a Cake Addin
#addin nuget:?package=Pygmalions.Nebula.Translating&version=0.1.0
// Install Pygmalions.Nebula.Translating as a Cake Tool
#tool nuget:?package=Pygmalions.Nebula.Translating&version=0.1.0
Nebula Translating
Fundamental library of Pygmalions' Nebula Framework.
This library provides a mechanism to allow converting objects between non-related types. This is designed NOT for customized type converting, but for customized non-intrusive serialization and deserialization.
Concepts
Translator
Translator is the object which can construct a new object of the required type according to the information of the given object and the customized rule. And that is the difference between the translating and converting.
Compared to ISerializable, Translators are designed for serialization and deserialization in a non-intrusive style with flexible protocol support. For example, you can create a translator which can translate a string into your customized data structure and transport it among the Internet.
Protocol
There may be multiple rules to do the translating, so register and translate methods have the optional parameter protocol. If the protocol parameter is "" (empty string), then the registry will firstly to find the translator which is register with "", then secondly it will try to use a random translator to translate.
Translator Registry
A translator registry is a translators set, which allows you to customize which translators to use in different scenarios.
The static class Translators is a static facade of a singleton registry instance. In most situations, you can directly register translators into it, and use it to translate objects.
How to Use
Implement a translator
A simple translator which translate a integer into a string is as follows. (Though it is meaningless, it is displayed to demonstrate the translator interface.)
[Translator]
public class SampleTranslator : ITranslator<int, string>
{
public string Translate(int original)
{
return original.ToString();
}
}
The TranslatorAttribute will let the static facade Translators auto discover and register it.
Register it
Register a translator in a registry:
var translators = new TranslatorRegistry();
translators.RegisterTranslator<int, string>(new SampleTranslator());
Translate
Use translators in a registry to translate a integer:
var result = translators.Translate<string>(3);
Remarks
This library is under rapid development, thus its API may be very unstable, DO NOT use it in the production environment, until its version reaches 1.0.0.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Pygmalions.Nebula.Extending (>= 0.2.0)
- Pygmalions.Nebula.Reporting (>= 0.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.0 | 213 | 3/26/2022 |
This library under rapid development, thus its API may be unstable. It is not recommended to use this library in production until the version of this library reaches 1.0.0.