~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to samples/ComponentInspector/ComponentInspector.Core/Src/Objects/TypeLibKey.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
 
5
//     <version>$Revision$</version>
 
6
// </file>
 
7
 
 
8
using System;
 
9
 
 
10
namespace NoGoop.Obj
 
11
{
 
12
        // Note this class is used only internally in TypeLibrary
 
13
        // Used to identify type libraries in the hash tables
 
14
        internal class TypeLibKey : IComparable
 
15
        {
 
16
                internal Guid           _guid;
 
17
                
 
18
                // The Major.Minor version of a type library, matches
 
19
                // the registry key
 
20
                
 
21
                internal String         _version;
 
22
                internal int            _majorVersion;
 
23
                internal int            _minorVersion;
 
24
                
 
25
                // Version can be null, to match on the any version
 
26
                internal TypeLibKey(Guid guid,
 
27
                                                        String version)
 
28
                {
 
29
                        _guid = guid;
 
30
                        _version = version;
 
31
                        try
 
32
                        {
 
33
                                if (_version != null)
 
34
                                        GetVersionNumbers();
 
35
                        }
 
36
                        catch (Exception ex)
 
37
                        {
 
38
                                throw new Exception("Error creating TypeLib key for: " +
 
39
                                                                        guid + " " + version, ex);
 
40
                        }
 
41
                }
 
42
                
 
43
                protected void GetVersionNumbers()
 
44
                {
 
45
                        try
 
46
                        {
 
47
                                int dot = _version.IndexOf('.');
 
48
                                if (dot != -1)
 
49
                                {
 
50
                                        _majorVersion = Convert.
 
51
                                                ToInt16(_version.Substring(0, dot));
 
52
                                        _minorVersion = Convert.
 
53
                                                ToInt16(_version.Substring(dot + 1));
 
54
                                }
 
55
                                else
 
56
                                {
 
57
                                        _majorVersion = 
 
58
                                                Convert.ToInt16(_version);
 
59
                                        _minorVersion = 0;
 
60
                                }
 
61
                        }
 
62
                        catch (Exception ex)
 
63
                        {
 
64
                                throw new 
 
65
                                        Exception("Error converting version string for: " 
 
66
                                                          + this, ex);
 
67
                        }
 
68
                }
 
69
                
 
70
                public override bool Equals(Object other)
 
71
                {
 
72
                        if (!(other is TypeLibKey))
 
73
                                return false;
 
74
                        TypeLibKey b = (TypeLibKey)other;
 
75
                        bool guidEquals = b._guid.Equals(_guid);
 
76
                        if (!guidEquals)
 
77
                                return false;
 
78
                        if (_version != null && b._version != null)
 
79
                                return _version.Equals(b._version);
 
80
                        // Our version specified and the other not, no match
 
81
                        if (_version != null && b._version == null)
 
82
                                return false;
 
83
                        // We don't care about version, match any version, or
 
84
                        // no version is specified for either one, that's a match
 
85
                        return true;
 
86
                }
 
87
                
 
88
                public override int GetHashCode()
 
89
                {
 
90
                        return _guid.GetHashCode();
 
91
                }
 
92
                
 
93
                public int CompareTo(Object other)
 
94
                {
 
95
                        if (!(other is TypeLibKey))
 
96
                                return -1;
 
97
                        TypeLibKey b = (TypeLibKey)other;
 
98
                        if (b != null)
 
99
                        {
 
100
                                int compVal = _guid.CompareTo(b._guid);
 
101
                                if (compVal != 0)
 
102
                                        return compVal;
 
103
                                if (_version != null && b._version != null)
 
104
                                        return _version.CompareTo(b._version);
 
105
                                if ((_version != null && b._version == null) ||
 
106
                                        (_version == null && b._version != null))
 
107
                                        return -1;
 
108
                                return 0;
 
109
                        }
 
110
                        return -1;
 
111
                }
 
112
                
 
113
                public override String ToString()
 
114
                {
 
115
                        return _guid + " " + _version;
 
116
                }
 
117
        }
 
118
}