Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2893_BNLR/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Highlighting/Xshd/XshdReference.cs @ 15747

Last change on this file since 15747 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 4.3 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20
21namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
22{
23  /// <summary>
24  /// A reference to an xshd color, or an inline xshd color.
25  /// </summary>
26  [Serializable]
27  public struct XshdReference<T> : IEquatable<XshdReference<T>> where T : XshdElement
28  {
29    string referencedDefinition;
30    string referencedElement;
31    T inlineElement;
32   
33    /// <summary>
34    /// Gets the reference.
35    /// </summary>
36    public string ReferencedDefinition {
37      get { return referencedDefinition; }
38    }
39   
40    /// <summary>
41    /// Gets the reference.
42    /// </summary>
43    public string ReferencedElement {
44      get { return referencedElement; }
45    }
46   
47    /// <summary>
48    /// Gets the inline element.
49    /// </summary>
50    public T InlineElement {
51      get { return inlineElement; }
52    }
53   
54    /// <summary>
55    /// Creates a new XshdReference instance.
56    /// </summary>
57    public XshdReference(string referencedDefinition, string referencedElement)
58    {
59      if (referencedElement == null)
60        throw new ArgumentNullException("referencedElement");
61      this.referencedDefinition = referencedDefinition;
62      this.referencedElement = referencedElement;
63      this.inlineElement = null;
64    }
65   
66    /// <summary>
67    /// Creates a new XshdReference instance.
68    /// </summary>
69    public XshdReference(T inlineElement)
70    {
71      if (inlineElement == null)
72        throw new ArgumentNullException("inlineElement");
73      this.referencedDefinition = null;
74      this.referencedElement = null;
75      this.inlineElement = inlineElement;
76    }
77   
78    /// <summary>
79    /// Applies the visitor to the inline element, if there is any.
80    /// </summary>
81    public object AcceptVisitor(IXshdVisitor visitor)
82    {
83      if (inlineElement != null)
84        return inlineElement.AcceptVisitor(visitor);
85      else
86        return null;
87    }
88   
89    #region Equals and GetHashCode implementation
90    // The code in this region is useful if you want to use this structure in collections.
91    // If you don't need it, you can just remove the region and the ": IEquatable<XshdColorReference>" declaration.
92   
93    /// <inheritdoc/>
94    public override bool Equals(object obj)
95    {
96      if (obj is XshdReference<T>)
97        return Equals((XshdReference<T>)obj); // use Equals method below
98      else
99        return false;
100    }
101   
102    /// <summary>
103    /// Equality operator.
104    /// </summary>
105    public bool Equals(XshdReference<T> other)
106    {
107      // add comparisions for all members here
108      return this.referencedDefinition == other.referencedDefinition
109        && this.referencedElement == other.referencedElement
110        && this.inlineElement == other.inlineElement;
111    }
112   
113    /// <inheritdoc/>
114    public override int GetHashCode()
115    {
116      // combine the hash codes of all members here (e.g. with XOR operator ^)
117      return GetHashCode(referencedDefinition) ^ GetHashCode(referencedElement) ^ GetHashCode(inlineElement);
118    }
119   
120    static int GetHashCode(object o)
121    {
122      return o != null ? o.GetHashCode() : 0;
123    }
124   
125    /// <summary>
126    /// Equality operator.
127    /// </summary>
128    public static bool operator ==(XshdReference<T> left, XshdReference<T> right)
129    {
130      return left.Equals(right);
131    }
132   
133    /// <summary>
134    /// Inequality operator.
135    /// </summary>
136    public static bool operator !=(XshdReference<T> left, XshdReference<T> right)
137    {
138      return !left.Equals(right);
139    }
140    #endregion
141  }
142}
Note: See TracBrowser for help on using the repository browser.