From b0b2053a0345102b07f0ea1064e6995658e15cf6 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Wed, 14 May 2014 22:53:22 -0700 Subject: [PATCH 1/6] Optionally support DataContract in Mono/Unity --- src/SimpleJson/SimpleJson.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/SimpleJson/SimpleJson.cs b/src/SimpleJson/SimpleJson.cs index 2ab9742..708ee9b 100644 --- a/src/SimpleJson/SimpleJson.cs +++ b/src/SimpleJson/SimpleJson.cs @@ -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. +//#define ALTERNATE_DATACONTRACT + // NOTE: uncomment the following line to enable IReadOnlyCollection and IReadOnlyList support. //#define SIMPLE_JSON_READONLY_COLLECTIONS @@ -486,6 +490,29 @@ public override IEnumerable 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 + { + 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 + /// /// This class encodes and decodes JSON strings. /// Spec. details, see http://www.json.org/ From c124e3feb194b41e4f79769b577a34c26cce1f41 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Wed, 14 May 2014 22:59:25 -0700 Subject: [PATCH 2/6] Added Fork Purpose paragraph --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f3c5ffc..7591bc5 100644 --- a/README.md +++ b/README.md @@ -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. From 88fb1bfa65c61823a909c4ec1e4b73c12ae205d0 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Sun, 18 May 2014 04:57:18 -0700 Subject: [PATCH 3/6] the definition now starts with SIMPLE_JSON_ --- src/SimpleJson/SimpleJson.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimpleJson/SimpleJson.cs b/src/SimpleJson/SimpleJson.cs index 708ee9b..0eecbf9 100644 --- a/src/SimpleJson/SimpleJson.cs +++ b/src/SimpleJson/SimpleJson.cs @@ -33,7 +33,7 @@ // 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. -//#define ALTERNATE_DATACONTRACT +//#define SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES // NOTE: uncomment the following line to enable IReadOnlyCollection and IReadOnlyList support. //#define SIMPLE_JSON_READONLY_COLLECTIONS @@ -492,7 +492,7 @@ namespace SimpleJson { #region Alternate DataContract for Unity/Mono -#if ALTERNATE_DATACONTRACT +#if SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)] public sealed class DataContractAttribute : Attribute { From 55e27b55bdae6699296f6e4bd39d7da6b3370380 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Sun, 18 May 2014 05:04:00 -0700 Subject: [PATCH 4/6] Un-did adding fork-purpose --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 7591bc5..f3c5ffc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# 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. From 924ebd28fa10841f587ab90e4102b4bbb72dbcb9 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Sun, 18 May 2014 11:07:02 -0700 Subject: [PATCH 5/6] Clarified define description --- src/SimpleJson/SimpleJson.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleJson/SimpleJson.cs b/src/SimpleJson/SimpleJson.cs index 0eecbf9..db274bf 100644 --- a/src/SimpleJson/SimpleJson.cs +++ b/src/SimpleJson/SimpleJson.cs @@ -32,7 +32,7 @@ //#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. +// define if you want to use DataContract with Unity/Mono, which does not implement all WCF classes. //#define SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES // NOTE: uncomment the following line to enable IReadOnlyCollection and IReadOnlyList support. From 98929dc665d41f68818bb79be05d15784b731451 Mon Sep 17 00:00:00 2001 From: Esam-Bustaty Date: Tue, 20 May 2014 16:54:37 -0700 Subject: [PATCH 6/6] New constructor for DataMember and fixed scopes --- src/SimpleJson/SimpleJson.cs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/SimpleJson/SimpleJson.cs b/src/SimpleJson/SimpleJson.cs index db274bf..ac93db0 100644 --- a/src/SimpleJson/SimpleJson.cs +++ b/src/SimpleJson/SimpleJson.cs @@ -494,19 +494,47 @@ namespace SimpleJson #if SIMPLE_JSON_REDEFINE_DATACONTRACT_ATTRIBUTES [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)] - public sealed class DataContractAttribute : Attribute +#if SIMPLE_JSON_INTERNAL + internal +#else + public +#endif + sealed class DataContractAttribute : Attribute { public string Name { get; set; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)] - public sealed class DataMemberAttribute : Attribute +#if SIMPLE_JSON_INTERNAL + internal +#else + public +#endif + sealed class DataMemberAttribute : Attribute { + public DataMemberAttribute() + { + } + + /// + /// this constructor simplifies declaring this attribute by writing [DataMember("name")] instead of [DataMember(Name = "name")] + /// + /// + public DataMemberAttribute(string name) + { + Name = name; + } + public string Name { get; set; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)] - public sealed class IgnoreDataMemberAttribute : Attribute +#if SIMPLE_JSON_INTERNAL + internal +#else + public +#endif + sealed class IgnoreDataMemberAttribute : Attribute { } #endif