Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / Model / DependencyModel.cs
blobea535b73003b58a9f0e29fbcf01bb06005da5357
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core
17 using System;
19 public enum DependencyType
21 Service,
22 Parameter,
23 ServiceOverride
26 /// <summary>
27 /// Represents a dependency (other component or a
28 /// fixed value available through external configuration).
29 /// </summary>
30 #if !SILVERLIGHT
31 [Serializable]
32 #endif
33 public class DependencyModel
35 private String dependencyKey;
36 private Type targetType;
37 private bool isOptional;
38 private DependencyType dependencyType;
40 /// <summary>
41 /// Initializes a new instance of the <see cref="DependencyModel"/> class.
42 /// </summary>
43 /// <param name="type">The type.</param>
44 /// <param name="dependencyKey">The dependency key.</param>
45 /// <param name="targetType">Type of the target.</param>
46 /// <param name="isOptional">if set to <c>true</c> [is optional].</param>
47 public DependencyModel(DependencyType type, String dependencyKey,
48 Type targetType, bool isOptional)
50 dependencyType = type;
51 this.dependencyKey = dependencyKey;
52 this.targetType = targetType;
53 this.isOptional = isOptional;
56 /// <summary>
57 /// Gets or sets the type of the dependency.
58 /// </summary>
59 /// <value>The type of the dependency.</value>
60 public DependencyType DependencyType
62 get { return dependencyType; }
63 set { dependencyType = value; }
66 /// <summary>
67 /// Gets or sets the dependency key.
68 /// </summary>
69 /// <value>The dependency key.</value>
70 public String DependencyKey
72 get { return dependencyKey; }
73 set { dependencyKey = value; }
76 /// <summary>
77 /// Gets the type of the target.
78 /// </summary>
79 /// <value>The type of the target.</value>
80 public Type TargetType
82 get { return targetType; }
85 /// <summary>
86 /// Gets or sets whether this dependency is optional.
87 /// </summary>
88 /// <value>
89 /// <c>true</c> if this dependency is optional; otherwise, <c>false</c>.
90 /// </value>
91 public bool IsOptional
93 get { return isOptional; }
94 set { isOptional = value; }
97 /// <summary>
98 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
99 /// </summary>
100 /// <returns>
101 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
102 /// </returns>
103 public override string ToString()
105 return string.Format("{0} dependency '{1}' type '{2}'",
106 DependencyType, dependencyKey, TargetType);
109 /// <summary>
110 /// Serves as a hash function for a particular type, suitable
111 /// for use in hashing algorithms and data structures like a hash table.
112 /// </summary>
113 /// <returns>
114 /// A hash code for the current <see cref="T:System.Object"/>.
115 /// </returns>
116 public override int GetHashCode()
118 int result = dependencyKey.GetHashCode();
119 result += 37 ^ targetType.GetHashCode();
120 result += 37 ^ isOptional.GetHashCode();
121 result += 37 ^ dependencyType.GetHashCode();
122 return result;
125 /// <summary>
126 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
127 /// </summary>
128 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
129 /// <returns>
130 /// <see langword="true"/> if the specified <see cref="T:System.Object"/> is equal to the
131 /// current <see cref="T:System.Object"/>; otherwise, <see langword="false"/>.
132 /// </returns>
133 public override bool Equals(object obj)
135 if (this == obj) return true;
136 DependencyModel dependencyModel = obj as DependencyModel;
137 if (dependencyModel == null) return false;
138 if (!Equals(dependencyKey, dependencyModel.dependencyKey)) return false;
139 if (!Equals(targetType, dependencyModel.targetType)) return false;
140 if (!Equals(isOptional, dependencyModel.isOptional)) return false;
141 if (!Equals(dependencyType, dependencyModel.dependencyType)) return false;
142 return true;