GithubHelp home page GithubHelp logo

csharpinator's Issues

Add support for nullable properties

  • Add option to default all properties to be nullable.
  • When the above option is off, and the class definitions are being refined (by processing an additional document):
    • If a property had existed previously as non-nullable, switch it to nullable if it is not found in the new document.
    • If a new property is encountered, add it as nullable, since it hadn't existed before.

Output properties of type List<T> when appropriate

Implementation brainstorming:

  • Create ListClass (inherits from Class)
  • Should contain another Class (the generic argument of the List)
  • Need to be able to create a PropertyDefinition that has its Class be an instance of ListClass

Edge case: can produce a class with a property of the same name

Example:

<container>
  <foos>
    <foo>abc</foo>
    <foo>xyz</foo>
    <bar>123</bar>
  </foos>
</container>

Produced c# code:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Serialization;

namespace FooBar
{
    [XmlRoot("container")]
    public partial class Container
    {
        [XmlElement("foos")]
        public Foos Foos { get; set; }
    }

    [XmlRoot("foos")]
    public partial class Foos
    {
        [XmlElement("foo")]
        public List<string> Foos { get; set; }

        [XmlIgnore]
        public int? Bar { get; set; }

        [XmlElement("bar")]
        public string BarString
        {
            get
            {
                return Bar == null ? null : Bar.ToString();
            }
            set
            {
                Bar = value == null ? null : (int?)int.Parse(value);
            }
        }
    }
}

The problem is that class Foos has a property named Foos, which doesn't compile.

DateTime in native JSON format creates wrong type of property

Given a JSON document like this:

{
    "ID": 1,
    "PublishedAt": "\/Date(1330848000000-0800)\/",
    "Text": "Best blog post ever",
    "Title": "Magical Title"
}

It creates a class with property like this:

[DataContract]
public partial class Container
{
    [IgnoreDataMember]
    public DateTime PublishedAt { get; set; }

    [DataMember(Name="PublishedAt")]
    public string PublishedAtString
    {
        get
        {
            return PublishedAt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", new CultureInfo("en-US"));
        }
        set
        {
            PublishedAt = DateTime.ParseExact(value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", new CultureInfo("en-US"));
        }
    }

    /* Other properties here */
}

It should create a class like this:

[DataContract]
public partial class Container
{
    [DataMember(Name="PublishedAt")]
    public DateTime PublishedAt { get; set; }

    /* Other properties here */
}

Bug: Empty generated classes

Given this input...

<foo foo_value="true">
  <bar bar_value="123">abc</bar>
  <bar bar_value="456">xyz</bar>
</foo>

Or this one...

<foo foo_value="true">
  <bar bar_value="123">abc</bar>
</foo>

This class is being generated:

    [XmlRoot("bar")]
    public partial class Bar
    {

    }

The Bar class should have two properties: BarValue (of type int) and Value (of type string).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.