Introduction
python script for generating C# files for Newtonsoft.Json deserialization from python enums and annotated classes.
Installation
- from pip
pip install cs_generator
- download package and run setup.py
python setup.py install
Usage
- Annotate classes that are to be converted to C#; should be annotated on class level.
- All used enum types will be converted (no annotation is needed)
- If reference keeping is used in deserialization, set ref_keeping to True
from enum import Enum
from typing import List
from cs_generator import CSGenerator
class Job(Enum):
Teachert = 0
Engineer = 1
Doctor = 2
class Person:
name: str
age: int
job: Job
hobbies: List[str]
def __init__(self, name, age, job, hobbies):
self.name = name
self.age = age
self.job = job
self.hobbies = hobbies
csg = CSGenerator(Person, ref_keeping=True)
csg.export('TestNamespace', dest_folder)
# or
p = Person('Jack', 33, Job.Teacher, ['Swimming', 'Video Games', 'Fishing'])
csg = CSGenerator(p, ref_keeping=True)
csg.export('TestNamespace', dest_folder)
output cs script
using Newtonsoft.Json;
namespace TestNamespace
{
public enum Job
{
Teacher = 0,
Engineer = 1,
Doctor = 2
}
}
using System.Collections.Generic;
using Newtonsoft.Json;
namespace TestNamesapce
{
public partial class Person
{
public readonly string name;
public readonly int age;
public readonly Job job;
public readonly IList<string> hobbies;
[JsonConstructor]
public Person(
string name,
int age,
Job job,
List<string> hobbies
)
{
this.name = name;
this.age = age;
this.job = job;
this.hobbies = hobbies;
}
}
}
Metadata
Release files for cs-generator 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs_generator-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for cs_generator-1.0.6-py3-none-any.whl |
Release files / cs_generator-1.0.6-py3-none-any.whl
| Download URL | cs_generator-1.0.6-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11760f83d2f8765eaa49829a137346c285884ddbb635feec25fc109d084b1adb
|
|
BLAKE2b-256 checksum How to use checksums |
ce872488667749af159fda3847a7a078c14ab2acf02c010936b90fa430e57efa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Security for cs-generator 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.