Common/Types/Mesh.ps1

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
79
$meshType = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mesh
{
    public class Item<T> where T : class
    {
        private T source;
        private T destination;

        public T Source
        {
            get { return source; }
            set { source = value; }
        }

        public T Destination
        {
            get { return destination; }
            set { destination = value; }
        }

        public override string ToString()
        {
            return string.Format("{0} - {1}", source.ToString(), destination.ToString());
        }

        public override int GetHashCode()
        {
            return source.GetHashCode() ^ destination.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            T otherSource = null;
            T otherDestination = null;

            if (obj == null)
                return false;

            if (obj.GetType().IsArray)
            {
                var array = (object[])obj;
                if (typeof(T) != array[0].GetType() || typeof(T) != array[1].GetType())
                    return false;
                else
                {
                    otherSource = (T)array[0];
                    otherDestination = (T)array[1];
                }

                if (!otherSource.Equals(this.source))
                    return false;

                return otherDestination.Equals(this.destination);
            }
            else
            {
                if (GetType() != obj.GetType())
                    return false;

                Item<T> otherObject = (Item<T>)obj;

                if (!this.destination.Equals(otherObject.destination))
                    return false;

                return this.source.Equals(otherObject.source);
            }
        }
    }
}
"@


Add-Type -TypeDefinition $meshType