-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from RSuter/dotliquid
Dotliquid
- Loading branch information
Showing
23 changed files
with
349 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/Class.FromJson.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public static {{ ClassName }} FromJson(string data) | ||
{ | ||
return Newtonsoft.Json.JsonConvert.DeserializeObject<{{ ClassName }}>(data{{ JsonSerializerParameterCode }}); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/Class.Inpc.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) | ||
{ | ||
var handler = PropertyChanged; | ||
if (handler != null) | ||
handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/Class.ToJson.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public string ToJson() | ||
{ | ||
return Newtonsoft.Json.JsonConvert.SerializeObject(this{{ JsonSerializerParameterCode }}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/DateFormatConverter.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{%- if GenerateDateFormatConverterClass -%} | ||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "{{ ToolchainVersion }}")] | ||
internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter | ||
{ | ||
public DateFormatConverter() | ||
{ | ||
DateTimeFormat = "yyyy-MM-dd"; | ||
} | ||
} | ||
{%- endif -%} |
14 changes: 14 additions & 0 deletions
14
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/Enum.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{%- if HasDescription -%} | ||
/// <summary>{{ Description | CSharpDocs }}</summary> | ||
{%- endif -%} | ||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "{{ ToolchainVersion }}")] | ||
{{ TypeAccessModifier }} enum {{ Name }} | ||
{ | ||
{%- for enum in Enums -%} | ||
{%- if IsStringEnum -%} | ||
[System.Runtime.Serialization.EnumMember(Value = "{{ enum.Value }}")] | ||
{%- endif -%} | ||
{{ enum.Name }} = {{ enum.InternalValue }}, | ||
|
||
{%- endfor -%} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/File.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//---------------------- | ||
// <auto-generated> | ||
// Generated using the NJsonSchema v{{ ToolchainVersion }} (http://NJsonSchema.org) | ||
// </auto-generated> | ||
//---------------------- | ||
|
||
namespace {{ Namespace }} | ||
{ | ||
#pragma warning disable // Disable all warnings | ||
|
||
{{ TypesCode | tab: 1 }} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/NJsonSchema.CodeGeneration.CSharp/Templates/Liquid/JsonInheritanceConverter.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{%- if GenerateJsonInheritanceAttributeClass -%} | ||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "{{ ToolchainVersion }}")] | ||
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = true)] | ||
internal class JsonInheritanceAttribute : System.Attribute | ||
{ | ||
public JsonInheritanceAttribute(string key, System.Type type) | ||
{ | ||
Key = key; | ||
Type = type; | ||
} | ||
|
||
public string Key { get; } | ||
|
||
public System.Type Type { get; } | ||
} | ||
|
||
{%- endif -%} | ||
{%- if GenerateJsonInheritanceConverterClass -%} | ||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "{{ ToolchainVersion }}")] | ||
internal class JsonInheritanceConverter : Newtonsoft.Json.JsonConverter | ||
{ | ||
internal static readonly string DefaultDiscriminatorName = "discriminator"; | ||
|
||
private readonly string _discriminator; | ||
|
||
[System.ThreadStatic] | ||
private static bool _isReading; | ||
|
||
[System.ThreadStatic] | ||
private static bool _isWriting; | ||
|
||
public JsonInheritanceConverter() | ||
{ | ||
_discriminator = DefaultDiscriminatorName; | ||
} | ||
|
||
public JsonInheritanceConverter(string discriminator) | ||
{ | ||
_discriminator = discriminator; | ||
} | ||
|
||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) | ||
{ | ||
try | ||
{ | ||
_isWriting = true; | ||
|
||
var jObject = Newtonsoft.Json.Linq.JObject.FromObject(value, serializer); | ||
jObject.AddFirst(new Newtonsoft.Json.Linq.JProperty(_discriminator, value.GetType().Name)); | ||
writer.WriteToken(jObject.CreateReader()); | ||
} | ||
finally | ||
{ | ||
_isWriting = false; | ||
} | ||
} | ||
|
||
public override bool CanWrite | ||
{ | ||
get | ||
{ | ||
if (_isWriting) | ||
{ | ||
_isWriting = false; | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
public override bool CanRead | ||
{ | ||
get | ||
{ | ||
if (_isReading) | ||
{ | ||
_isReading = false; | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
public override bool CanConvert(System.Type objectType) | ||
{ | ||
return true; | ||
} | ||
|
||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) | ||
{ | ||
var jObject = serializer.Deserialize<Newtonsoft.Json.Linq.JObject>(reader); | ||
if (jObject == null) | ||
return null; | ||
|
||
var discriminator = Newtonsoft.Json.Linq.Extensions.Value<string>(jObject.GetValue(_discriminator)); | ||
var subtype = GetObjectSubtype(objectType, discriminator); | ||
|
||
try | ||
{ | ||
_isReading = true; | ||
return serializer.Deserialize(jObject.CreateReader(), subtype); | ||
} | ||
finally | ||
{ | ||
_isReading = false; | ||
} | ||
} | ||
|
||
private System.Type GetObjectSubtype(System.Type objectType, string discriminator) | ||
{ | ||
foreach (var type in System.Reflection.CustomAttributeExtensions.GetCustomAttributes<JsonInheritanceAttribute>(System.Reflection.IntrospectionExtensions.GetTypeInfo(objectType), false)) | ||
{ | ||
if (type.Key == discriminator) | ||
return type.Type; | ||
} | ||
|
||
return objectType; | ||
} | ||
} | ||
{%- endif -%} |
Oops, something went wrong.