Skip to content

Optionally support DataContract in Mono/Unity #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Fork Purpose
Support for ```DataContract``` in Unity3d/Mono, as mono does not implement all WCF classes, this fork implements them in ```SimpleJson``` namespace if ```ALTERNATE_DATACONTRACT``` was defined.

# SimpleJson
Small and fast JSON library for .NET 2.0+/SL4+/WP7+/Windows Store Apps/Portable Class Library and powershell.
Includes support for dynamic in .NET 4.0+/SL4+/Windows Store Apps. Also includes support for DataContract and DataMember.
Expand Down
27 changes: 27 additions & 0 deletions src/SimpleJson/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// NOTE: uncomment the following line to enable DataContract support.
//#define SIMPLE_JSON_DATACONTRACT

// NOTE: uncomment the following line to use alternate definitions of DataContract/DataMember/IgnoreDataMember.
// define if you want to use DataContract with Mono, which does not implement all WCF classes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add Unity/Mono

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

//#define ALTERNATE_DATACONTRACT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all #define prefix should be prefixed with SIMPLE_JSON_. Don't quite like the name alternate too. feel free to give suggestions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of these possible names:

SIMPLE_JSON_CUSTOM_DATACONTRACT
SIMPLE_JSON_FIX_MISSING_DATACONTRACT
SIMPLE_JSON_REDEFINE_ATTRIBUTES
SIMPLE_JSON_CUSTOM_ATTRIBUTES
SIMPLE_JSON_FIX_MISSING_ATTRIBUTES
SIMPLE_JSON_FIX_MONO_MISSING_ATTRIBUTES
SIMPLE_JSON_NO_WCF
SIMPLE_JSON_FIX_MISSING_DATACONTRACT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES or SIMPLE_JSON_EMBED_DATACONTRACT_ATTRIBUTES.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll vote for SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES as i think the word "embed" is used when sticking something to the data itself, not classes or attributes, but both are fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. go for it before I can merge


// NOTE: uncomment the following line to enable IReadOnlyCollection<T> and IReadOnlyList<T> support.
//#define SIMPLE_JSON_READONLY_COLLECTIONS

Expand Down Expand Up @@ -486,6 +490,29 @@ public override IEnumerable<string> GetDynamicMemberNames()

namespace SimpleJson
{
#region Alternate DataContract for Unity/Mono

#if ALTERNATE_DATACONTRACT
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)]
public sealed class DataContractAttribute : Attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add

#if SIMPLE_JSON_INTERNAL
    internal
#else
    public
#endif

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Done.

{
public string Name { get; set; }
}

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class DataMemberAttribute : Attribute
{
public string Name { get; set; }
}

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class IgnoreDataMemberAttribute : Attribute
{
}
#endif

#endregion

/// <summary>
/// This class encodes and decodes JSON strings.
/// Spec. details, see http://www.json.org/
Expand Down