Skip to content

Commit

Permalink
Expanding IPolicyList and NamedType
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Apr 21, 2019
1 parent a083186 commit eacad57
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Policy/IPolicyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ namespace Unity.Policy
/// </summary>
public interface IPolicyList
{
/// <summary>
/// Get default policy for the type
/// </summary>
/// <param name="type">Type of the registration</param>
/// <param name="policyInterface">Type of policy to retrieve</param>
/// <returns>Instance of the policy or null if none found</returns>
object Get(Type type, Type policyInterface);

/// <summary>
/// Get policy
/// </summary>
Expand All @@ -16,6 +24,14 @@ public interface IPolicyList
/// <returns>Instance of the policy or null if none found</returns>
object Get(Type type, string name, Type policyInterface);

/// <summary>
/// Set default policy for the type
/// </summary>
/// <param name="type">Type of the registration</param>
/// <param name="policyInterface">Type of policy to be set</param>
/// <param name="policy">Policy instance to be set</param>
void Set(Type type, Type policyInterface, object policy);

/// <summary>
/// Set policy
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Resolution/NamedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,27 @@ public struct NamedType

public static int GetHashCode(Type type, string name) => ((type?.GetHashCode() ?? 0) + 37) ^ ((name?.GetHashCode() ?? 0) + 17);

public override bool Equals(object obj)
{
if (obj is NamedType other && Type == other.Type && Name == other.Name)
return true;

return false;
}

public static bool operator ==(NamedType obj1, NamedType obj2)
{
return obj1.Type == obj2.Type && obj1.Name == obj2.Name;
}

public static bool operator !=(NamedType obj1, NamedType obj2)
{
return obj1.Type != obj2.Type || obj1.Name != obj2.Name;
}

public override string ToString()
{
return $"Type: {Type?.Name}, Name: {Name}";
}
}
}

0 comments on commit eacad57

Please sign in to comment.