mirror of https://github.com/Squidex/squidex.git
9 changed files with 170 additions and 52 deletions
@ -0,0 +1,17 @@ |
|||||
|
// ==========================================================================
|
||||
|
// IJsonValue.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Infrastructure.Json.Orleans |
||||
|
{ |
||||
|
public interface IJsonValue |
||||
|
{ |
||||
|
object Value { get; } |
||||
|
|
||||
|
bool IsImmutable { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
// ==========================================================================
|
||||
|
// J.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
using Newtonsoft.Json; |
||||
|
|
||||
|
namespace Squidex.Infrastructure.Json.Orleans |
||||
|
{ |
||||
|
public struct J<T> : IJsonValue |
||||
|
{ |
||||
|
private readonly T value; |
||||
|
private readonly bool isImmutable; |
||||
|
|
||||
|
public T Value |
||||
|
{ |
||||
|
get { return value; } |
||||
|
} |
||||
|
|
||||
|
bool IJsonValue.IsImmutable |
||||
|
{ |
||||
|
get { return isImmutable; } |
||||
|
} |
||||
|
|
||||
|
object IJsonValue.Value |
||||
|
{ |
||||
|
get { return Value; } |
||||
|
} |
||||
|
|
||||
|
[JsonConstructor] |
||||
|
public J(T value, bool isImmutable = false) |
||||
|
{ |
||||
|
this.value = value; |
||||
|
|
||||
|
this.isImmutable = isImmutable; |
||||
|
} |
||||
|
|
||||
|
public static implicit operator T(J<T> value) |
||||
|
{ |
||||
|
return value.Value; |
||||
|
} |
||||
|
|
||||
|
public static implicit operator J<T>(T d) |
||||
|
{ |
||||
|
return new J<T>(d); |
||||
|
} |
||||
|
|
||||
|
public static Task<J<T>> AsTask(T value) |
||||
|
{ |
||||
|
return Task.FromResult<J<T>>(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// ==========================================================================
|
||||
|
// JExtensions.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Infrastructure.Json.Orleans |
||||
|
{ |
||||
|
public static class JExtensions |
||||
|
{ |
||||
|
public static J<T> AsJ<T>(this T value, bool immutable = true) |
||||
|
{ |
||||
|
return new J<T>(value, immutable); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue