-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates method to create the relations based on the property editor's…
… returned reference but have discovered a gotcha for relations, so next step is to resolve that.
- Loading branch information
Showing
30 changed files
with
213 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Umbraco.Core.Models.Editors | ||
{ | ||
/// <summary> | ||
/// Used to track reference to other entities in a property value | ||
/// </summary> | ||
public struct UmbracoEntityReference : IEquatable<UmbracoEntityReference> | ||
{ | ||
private static readonly UmbracoEntityReference _empty = new UmbracoEntityReference(Udi.UnknownTypeUdi.Instance, string.Empty); | ||
|
||
public UmbracoEntityReference(Udi udi, string relationTypeAlias) | ||
{ | ||
Udi = udi ?? throw new ArgumentNullException(nameof(udi)); | ||
RelationTypeAlias = relationTypeAlias ?? throw new ArgumentNullException(nameof(relationTypeAlias)); | ||
} | ||
|
||
public static UmbracoEntityReference Empty() => _empty; | ||
|
||
public static bool IsEmpty(UmbracoEntityReference reference) => reference == Empty(); | ||
|
||
public Udi Udi { get; } | ||
public string RelationTypeAlias { get; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is UmbracoEntityReference reference && Equals(reference); | ||
} | ||
|
||
public bool Equals(UmbracoEntityReference other) | ||
{ | ||
return EqualityComparer<Udi>.Default.Equals(Udi, other.Udi) && | ||
RelationTypeAlias == other.RelationTypeAlias; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
var hashCode = -487348478; | ||
hashCode = hashCode * -1521134295 + EqualityComparer<Udi>.Default.GetHashCode(Udi); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(RelationTypeAlias); | ||
return hashCode; | ||
} | ||
|
||
public static bool operator ==(UmbracoEntityReference left, UmbracoEntityReference right) | ||
{ | ||
return left.Equals(right); | ||
} | ||
|
||
public static bool operator !=(UmbracoEntityReference left, UmbracoEntityReference right) | ||
{ | ||
return !(left == right); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.