1+
// Copyright 2019 Florian Gather <[email protected] > 2+ // Copyright 2019 Paula Ruiz <[email protected] > 3+ // Copyright 2019 Fritz Brandhuber <[email protected] > 4+ //
5+ // SPDX-License-Identifier: Apache-2.0
6+
7+ using System . Collections . Generic ;
8+ using System . Linq ;
9+ using ArchUnitNET . Domain . Dependencies ;
10+ using ArchUnitNET . Domain . Extensions ;
11+ using JetBrains . Annotations ;
12+
13+ namespace ArchUnitNET . Domain
14+ {
15+ public class Struct : IType
16+ {
17+ public Struct ( IType type )
18+ {
19+ Type = type ;
20+ }
21+
22+ public IType Type { get ; }
23+ public string Name => Type . Name ;
24+ public string FullName => Type . FullName ;
25+
26+ [ CanBeNull ]
27+ public Class BaseClass =>
28+ ( Class ) Dependencies . OfType < InheritsBaseClassDependency > ( ) . FirstOrDefault ( ) ? . Target ;
29+
30+ public IEnumerable < Class > InheritedClasses => BaseClass == null
31+ ? Enumerable . Empty < Class > ( )
32+ : BaseClass . InheritedClasses . Concat ( new [ ] { BaseClass } ) ;
33+
34+ public Visibility Visibility => Type . Visibility ;
35+ public bool IsNested => Type . IsNested ;
36+ public bool IsGeneric => Type . IsGeneric ;
37+ public bool IsGenericParameter => Type . IsGenericParameter ;
38+ public bool IsStub => Type . IsStub ;
39+ public bool IsCompilerGenerated => Type . IsCompilerGenerated ;
40+
41+ public Namespace Namespace => Type . Namespace ;
42+ public Assembly Assembly => Type . Assembly ;
43+
44+ public IEnumerable < Attribute > Attributes => AttributeInstances . Select ( instance => instance . Type ) ;
45+ public List < AttributeInstance > AttributeInstances => Type . AttributeInstances ;
46+
47+ public List < ITypeDependency > Dependencies => Type . Dependencies ;
48+ public List < ITypeDependency > BackwardsDependencies => Type . BackwardsDependencies ;
49+ public IEnumerable < IType > ImplementedInterfaces => Type . ImplementedInterfaces ;
50+
51+ public MemberList Members => Type . Members ;
52+ public List < GenericParameter > GenericParameters => Type . GenericParameters ;
53+
54+ public bool ImplementsInterface ( Interface intf )
55+ {
56+ return Type . ImplementsInterface ( intf ) ;
57+ }
58+
59+ public bool ImplementsInterface ( string pattern , bool useRegularExpressions = false )
60+ {
61+ return Type . ImplementsInterface ( pattern , useRegularExpressions ) ;
62+ }
63+
64+ public bool IsAssignableTo ( IType assignableToType )
65+ {
66+ return this . GetAssignableTypes ( ) . Contains ( assignableToType ) ;
67+ }
68+
69+ public bool IsAssignableTo ( string pattern , bool useRegularExpressions = false )
70+ {
71+ return pattern != null && this . GetAssignableTypes ( )
72+ . Any ( type => type . FullNameMatches ( pattern , useRegularExpressions ) ) ;
73+ }
74+
75+ public override string ToString ( )
76+ {
77+ return FullName ;
78+ }
79+
80+ private bool Equals ( Struct other )
81+ {
82+ return Equals ( Type , other . Type ) ;
83+ }
84+
85+ public override bool Equals ( object obj )
86+ {
87+ if ( ReferenceEquals ( null , obj ) )
88+ {
89+ return false ;
90+ }
91+
92+ if ( ReferenceEquals ( this , obj ) )
93+ {
94+ return true ;
95+ }
96+
97+ return obj . GetType ( ) == GetType ( ) && Equals ( ( Struct ) obj ) ;
98+ }
99+
100+ public override int GetHashCode ( )
101+ {
102+ return Type != null ? Type . GetHashCode ( ) : 0 ;
103+ }
104+ }
105+ }
0 commit comments