-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
179 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace Our.Umbraco.Vorto.Models | ||
{ | ||
public interface IVortoValue | ||
{ | ||
/// <summary> | ||
/// Gets or sets the data type definition id | ||
/// </summary> | ||
Guid DtdGuid { get; set; } | ||
|
||
/// <summary> | ||
/// Attempts to cast the vorto value instance to another generic type. | ||
/// </summary> | ||
/// <returns>The cast vorto value instance, or null if no values have a value.</returns> | ||
VortoValue<T> CastToVortoValue<T>(); | ||
} | ||
} |
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 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Our.Umbraco.Vorto.Models | ||
{ | ||
public interface IVortoValue<T> : IVortoValue | ||
{ | ||
/// <summary> | ||
/// Gets or sets the data type definition id | ||
/// </summary> | ||
IDictionary<string, T> Values { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,47 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using Umbraco.Core; | ||
|
||
namespace Our.Umbraco.Vorto.Models | ||
{ | ||
/// <summary> | ||
/// Represents a multilingual property value | ||
/// </summary> | ||
public partial class VortoValue<T> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the collection of language independent values | ||
/// </summary> | ||
[JsonProperty("values")] | ||
public IDictionary<string, T> Values { get; set; } | ||
/// <summary> | ||
/// Represents a multilingual property value | ||
/// </summary> | ||
public partial class VortoValue<T> : IVortoValue<T> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the collection of language independent values | ||
/// </summary> | ||
[JsonProperty("values")] | ||
public IDictionary<string, T> Values { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the data type definition id | ||
/// </summary> | ||
[JsonProperty("dtdGuid")] | ||
public Guid DtdGuid { get; set; } | ||
/// <summary> | ||
/// Gets or sets the data type definition id | ||
/// </summary> | ||
[JsonProperty("dtdGuid")] | ||
public Guid DtdGuid { get; set; } | ||
|
||
public VortoValue() | ||
{ | ||
Values = new Dictionary<string, T>(); | ||
} | ||
} | ||
public VortoValue() | ||
{ | ||
Values = new Dictionary<string, T>(); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to cast the vorto value instance to another generic type. | ||
/// </summary> | ||
/// <returns>The cast vorto value instance, or null if no values have a value.</returns> | ||
public VortoValue<TAs> CastToVortoValue<TAs>() | ||
{ | ||
var newVortoValue = new VortoValue<TAs>() | ||
{ | ||
Values = Values.ToDictionary(x => x.Key, x => { var v = x.Value.TryConvertTo<TAs>(); return v.Success ? v.Result : default(TAs); }) | ||
.Where(x => !EqualityComparer<TAs>.Default.Equals(x.Value, default(TAs))) | ||
.ToDictionary(x => x.Key, x => x.Value) | ||
}; | ||
|
||
return newVortoValue.Values.Count > 0 ? newVortoValue : null; | ||
} | ||
} | ||
} |
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