-
Notifications
You must be signed in to change notification settings - Fork 62
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 #93 from brandhuf/feature_attribute_arguments
Feature attribute arguments
- Loading branch information
Showing
28 changed files
with
3,478 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// Copyright 2020 Pavel Fischer <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace ArchUnitNET.Domain | ||
{ | ||
public class AttributeArgument : ITypeInstance<IType> | ||
{ | ||
private readonly ITypeInstance<IType> _typeInstance; | ||
|
||
public AttributeArgument(object value, ITypeInstance<IType> typeInstance) | ||
{ | ||
Value = value; | ||
_typeInstance = typeInstance; | ||
} | ||
|
||
public readonly object Value; | ||
|
||
public IType Type => _typeInstance.Type; | ||
public IEnumerable<GenericArgument> GenericArguments => _typeInstance.GenericArguments; | ||
public bool IsArray => _typeInstance.IsArray; | ||
public IEnumerable<int> ArrayDimensions => _typeInstance.ArrayDimensions; | ||
|
||
private bool Equals(AttributeArgument other) | ||
{ | ||
return Equals(_typeInstance, other._typeInstance) && Equals(Value, other.Value); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
return obj.GetType() == GetType() && Equals((AttributeArgument) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = _typeInstance != null ? Type.GetHashCode() : 0; | ||
hashCode = (hashCode * 397) ^ (Value != null ? Value.GetHashCode() : 0); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
} |
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,32 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// Copyright 2020 Pavel Fischer <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ArchUnitNET.Loader; | ||
|
||
namespace ArchUnitNET.Domain | ||
{ | ||
public class AttributeInstance : TypeInstance<Attribute> | ||
{ | ||
// ReSharper disable SuggestBaseTypeForParameter | ||
public AttributeInstance(Attribute attribute, IEnumerable<AttributeArgument> attributeArguments) : | ||
base(attribute) | ||
{ | ||
AttributeArguments = attributeArguments; | ||
} | ||
|
||
public AttributeInstance(Attribute attribute) : base(attribute) | ||
{ | ||
AttributeArguments = Enumerable.Empty<AttributeArgument>(); | ||
} | ||
|
||
public IEnumerable<AttributeArgument> AttributeArguments { get; } | ||
|
||
public bool HasAttributeArguments => AttributeArguments.Any(); | ||
} | ||
} |
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,50 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// Copyright 2020 Pavel Fischer <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
namespace ArchUnitNET.Domain | ||
{ | ||
public class AttributeNamedArgument : AttributeArgument | ||
{ | ||
public AttributeNamedArgument(string name, object value, ITypeInstance<IType> typeInstance) : base(value, | ||
typeInstance) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public readonly string Name; | ||
|
||
private bool Equals(AttributeNamedArgument other) | ||
{ | ||
return base.Equals(other) && Equals(Name, other.Name); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
return obj.GetType() == GetType() && Equals((AttributeNamedArgument) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = base.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
} |
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
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.