Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions Unity3D/3rdLib/Utf8Json/Attributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Utf8Json
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class JsonFormatterAttribute : Attribute
{
public Type FormatterType { get; private set; }
public object[] Arguments { get; private set; }

public JsonFormatterAttribute(Type formatterType)
{
this.FormatterType = formatterType;
}

public JsonFormatterAttribute(Type formatterType, params object[] arguments)
{
this.FormatterType = formatterType;
this.Arguments = arguments;
}
}

[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)]
public class SerializationConstructorAttribute : Attribute
{

}
}
28 changes: 28 additions & 0 deletions Unity3D/3rdLib/Utf8Json/Formatters/AnonymousFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace Utf8Json.Formatters
{
public sealed class AnonymousFormatter<T> : IJsonFormatter<T>
{
readonly JsonSerializeAction<T> serialize;
readonly JsonDeserializeFunc<T> deserialize;

public AnonymousFormatter(JsonSerializeAction<T> serialize, JsonDeserializeFunc<T> deserialize)
{
this.serialize = serialize;
this.deserialize = deserialize;
}

public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
{
if (serialize == null) throw new InvalidOperationException(this.GetType().Name + " does not support Serialize.");
serialize(ref writer, value, formatterResolver);
}

public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
if (deserialize == null) throw new InvalidOperationException(this.GetType().Name + " does not support Deserialize.");
return deserialize(ref reader, formatterResolver);
}
}
}
Loading