Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core / Model / DependencyModel.cs
blobb75c00aa71cb5ffc7de32a807a41f151a0187155
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 [Serializable]
31 public class DependencyModel
33 private String dependencyKey;
34 private Type targetType;
35 private bool isOptional;
36 private DependencyType dependencyType;
38 /// <summary>
39 /// Initializes a new instance of the <see cref="DependencyModel"/> class.
40 /// </summary>
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;
54 /// <summary>
55 /// Gets or sets the type of the dependency.
56 /// </summary>
57 /// <value>The type of the dependency.</value>
58 public DependencyType DependencyType
60 get { return dependencyType; }
61 set { dependencyType = value; }
64 /// <summary>
65 /// Gets or sets the dependency key.
66 /// </summary>
67 /// <value>The dependency key.</value>
68 public String DependencyKey
70 get { return dependencyKey; }
71 set { dependencyKey = value; }
74 /// <summary>
75 /// Gets the type of the target.
76 /// </summary>
77 /// <value>The type of the target.</value>
78 public Type TargetType
80 get { return targetType; }
83 /// <summary>
84 /// Gets or sets whether this dependency is optional.
85 /// </summary>
86 /// <value>
87 /// <c>true</c> if this dependency is optional; otherwise, <c>false</c>.
88 /// </value>
89 public bool IsOptional
91 get { return isOptional; }
92 set { isOptional = value; }
95 /// <summary>
96 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
97 /// </summary>
98 /// <returns>
99 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
100 /// </returns>
101 public override string ToString()
103 return string.Format("{0} dependency '{1}' type '{2}'",
104 DependencyType, dependencyKey, TargetType);
107 /// <summary>
108 /// Serves as a hash function for a particular type, suitable
109 /// for use in hashing algorithms and data structures like a hash table.
110 /// </summary>
111 /// <returns>
112 /// A hash code for the current <see cref="T:System.Object"/>.
113 /// </returns>
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();
120 return result;
123 /// <summary>
124 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
125 /// </summary>
126 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
127 /// <returns>
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"/>.
130 /// </returns>
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;
140 return true;