1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 public enum DependencyType
27 /// Represents a dependency (other component or a
28 /// fixed value available through external configuration).
31 public class DependencyModel
33 private String dependencyKey
;
34 private Type targetType
;
35 private bool isOptional
;
36 private DependencyType dependencyType
;
39 /// Initializes a new instance of the <see cref="DependencyModel"/> class.
41 /// <param name="type">The type.</param>
42 /// <param name="dependencyKey">The dependency key.</param>
43 /// <param name="targetType">Type of the target.</param>
44 /// <param name="isOptional">if set to <c>true</c> [is optional].</param>
45 public DependencyModel(DependencyType type
, String dependencyKey
,
46 Type targetType
, bool isOptional
)
48 dependencyType
= type
;
49 this.dependencyKey
= dependencyKey
;
50 this.targetType
= targetType
;
51 this.isOptional
= isOptional
;
55 /// Gets or sets the type of the dependency.
57 /// <value>The type of the dependency.</value>
58 public DependencyType DependencyType
60 get { return dependencyType; }
61 set { dependencyType = value; }
65 /// Gets or sets the dependency key.
67 /// <value>The dependency key.</value>
68 public String DependencyKey
70 get { return dependencyKey; }
71 set { dependencyKey = value; }
75 /// Gets the type of the target.
77 /// <value>The type of the target.</value>
78 public Type TargetType
80 get { return targetType; }
84 /// Gets or sets whether this dependency is optional.
87 /// <c>true</c> if this dependency is optional; otherwise, <c>false</c>.
89 public bool IsOptional
91 get { return isOptional; }
92 set { isOptional = value; }
96 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
99 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
101 public override string ToString()
103 return string.Format("{0} dependency '{1}' type '{2}'",
104 DependencyType
, dependencyKey
, TargetType
);
108 /// Serves as a hash function for a particular type, suitable
109 /// for use in hashing algorithms and data structures like a hash table.
112 /// A hash code for the current <see cref="T:System.Object"/>.
114 public override int GetHashCode()
116 int result
= dependencyKey
.GetHashCode();
117 result
+= 37 ^ targetType
.GetHashCode();
118 result
+= 37 ^ isOptional
.GetHashCode();
119 result
+= 37 ^ dependencyType
.GetHashCode();
124 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
126 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
128 /// <see langword="true"/> if the specified <see cref="T:System.Object"/> is equal to the
129 /// current <see cref="T:System.Object"/>; otherwise, <see langword="false"/>.
131 public override bool Equals(object obj
)
133 if (this == obj
) return true;
134 DependencyModel dependencyModel
= obj
as DependencyModel
;
135 if (dependencyModel
== null) return false;
136 if (!Equals(dependencyKey
, dependencyModel
.dependencyKey
)) return false;
137 if (!Equals(targetType
, dependencyModel
.targetType
)) return false;
138 if (!Equals(isOptional
, dependencyModel
.isOptional
)) return false;
139 if (!Equals(dependencyType
, dependencyModel
.dependencyType
)) return false;