-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClassModel.cs
More file actions
78 lines (67 loc) · 2.23 KB
/
ClassModel.cs
File metadata and controls
78 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FluentHttp.SourceGenerator
{
public class ClassModel
{
public ClassModel(string name, string nameSpace, EquatableList<InterfaceModel> interfaces)
{
Name = name;
NameSpace = nameSpace;
Interfaces = interfaces;
}
public string Name { get; set; }
public string NameSpace { get; set; }
public EquatableList<InterfaceModel> Interfaces { get; set; }
}
public class InterfaceModel
{
public string FullyQualifiedName { get; set; }
public EquatableList<string> Properties { get; set; }
public InterfaceModel(string fullyQualifiedName, EquatableList<string> properties)
{
FullyQualifiedName = fullyQualifiedName;
Properties = properties;
}
}
public class EquatableList<T> : List<T>, IEquatable<EquatableList<T>>
{
public bool Equals(EquatableList<T>? other)
{
// If the other list is null or a different size, they're not equal
if (other is null || Count != other.Count)
{
return false;
}
// Compare each pair of elements for equality
for (int i = 0; i < Count; i++)
{
if (!EqualityComparer<T>.Default.Equals(this[i], other[i]))
{
return false;
}
}
// If we got this far, the lists are equal
return true;
}
public override bool Equals(object obj)
{
return Equals(obj as EquatableList<T>);
}
public override int GetHashCode()
{
return this.Select(item => item?.GetHashCode() ?? 0).Aggregate((x, y) => x ^ y);
}
public static bool operator ==(EquatableList<T> list1, EquatableList<T> list2)
{
return ReferenceEquals(list1, list2)
|| list1 is not null && list2 is not null && list1.Equals(list2);
}
public static bool operator !=(EquatableList<T> list1, EquatableList<T> list2)
{
return !(list1 == list2);
}
}
}