1 // Copyright 2004-2008 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).
33 public class DependencyModel
35 private String dependencyKey
;
36 private Type targetType
;
37 private bool isOptional
;
38 private DependencyType dependencyType
;
41 /// Initializes a new instance of the <see cref="DependencyModel"/> class.
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
;
57 /// Gets or sets the type of the dependency.
59 /// <value>The type of the dependency.</value>
60 public DependencyType DependencyType
62 get { return dependencyType; }
63 set { dependencyType = value; }
67 /// Gets or sets the dependency key.
69 /// <value>The dependency key.</value>
70 public String DependencyKey
72 get { return dependencyKey; }
73 set { dependencyKey = value; }
77 /// Gets the type of the target.
79 /// <value>The type of the target.</value>
80 public Type TargetType
82 get { return targetType; }
86 /// Gets or sets whether this dependency is optional.
89 /// <c>true</c> if this dependency is optional; otherwise, <c>false</c>.
91 public bool IsOptional
93 get { return isOptional; }
94 set { isOptional = value; }
98 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
101 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
103 public override string ToString()
105 return string.Format("{0} dependency '{1}' type '{2}'",
106 DependencyType
, dependencyKey
, TargetType
);
110 /// Serves as a hash function for a particular type, suitable
111 /// for use in hashing algorithms and data structures like a hash table.
114 /// A hash code for the current <see cref="T:System.Object"/>.
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();
126 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
128 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
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"/>.
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;