-
Notifications
You must be signed in to change notification settings - Fork 12
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 #149 from OctopusDeploy/sl/primarykeyhandlers
Added the concept of Primary Key Handlers
- Loading branch information
Showing
48 changed files
with
1,149 additions
and
410 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#nullable enable | ||
using System; | ||
using System.Globalization; | ||
using System.Reflection; | ||
|
||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
public class CustomIdType<T> | ||
{ | ||
internal CustomIdType(T value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public T Value { get; } | ||
|
||
public override string? ToString() | ||
{ | ||
return Value?.ToString(); | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != GetType()) return false; | ||
return !(Value is null) && Value.Equals(((CustomIdType<T>) obj).Value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return (Value != null ? Value.GetHashCode() : 0); | ||
} | ||
|
||
public static CustomIdType<T>? Create(Type customType, T value) | ||
{ | ||
const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; | ||
var instance = Activator.CreateInstance(customType, bindingFlags, null, new object[] { value! }, CultureInfo.CurrentCulture); | ||
return instance as CustomIdType<T>; | ||
} | ||
|
||
public static TCustomIdType? Create<TCustomIdType>(T value) where TCustomIdType : CustomIdType<T> | ||
{ | ||
return (TCustomIdType?) Create(typeof(TCustomIdType), value); | ||
} | ||
} | ||
|
||
public class StringCustomIdType : CustomIdType<string> | ||
{ | ||
internal StringCustomIdType(string value) : base(value) | ||
{ | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
source/Nevermore.IntegrationTests/Model/CustomPrefixIdKeyHandler.cs
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,11 @@ | ||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
class CustomPrefixIdKeyHandler : StringCustomIdTypeIdKeyHandler<CustomPrefixId> | ||
{ | ||
public const string CustomPrefix = "CustomPrefix"; | ||
|
||
public CustomPrefixIdKeyHandler():base(CustomPrefix) | ||
{ | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
source/Nevermore.IntegrationTests/Model/DocumentWithCustomPrefix.cs
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,15 @@ | ||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
public class DocumentWithCustomPrefix | ||
{ | ||
public CustomPrefixId Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
public class CustomPrefixId : StringCustomIdType | ||
{ | ||
internal CustomPrefixId(string value) : base(value) | ||
{ | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
source/Nevermore.IntegrationTests/Model/DocumentWithCustomPrefixAndStringId.cs
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 @@ | ||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
public class DocumentWithCustomPrefixAndStringId | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
source/Nevermore.IntegrationTests/Model/DocumentWithCustomPrefixAndStringIdMap.cs
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,15 @@ | ||
using Nevermore.Mapping; | ||
|
||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
public class DocumentWithCustomPrefixAndStringIdMap : DocumentMap<DocumentWithCustomPrefixAndStringId> | ||
{ | ||
public const string CustomPrefix = "CustomPrefix"; | ||
|
||
public DocumentWithCustomPrefixAndStringIdMap() | ||
{ | ||
Id().KeyHandler(new StringPrimaryKeyHandler(CustomPrefix)); | ||
Column(m => m.Name); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
source/Nevermore.IntegrationTests/Model/DocumentWithCustomPrefixMap.cs
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,13 @@ | ||
using Nevermore.Mapping; | ||
|
||
namespace Nevermore.IntegrationTests.Model | ||
{ | ||
public class DocumentWithCustomPrefixMap : DocumentMap<DocumentWithCustomPrefix> | ||
{ | ||
public DocumentWithCustomPrefixMap() | ||
{ | ||
Id(); | ||
Column(m => m.Name); | ||
} | ||
} | ||
} |
Oops, something went wrong.