@@ -24,12 +24,14 @@ internal class BindingKey : IEquatable<BindingKey> {
24
24
private const int HASHCODE_MULTIPLIER = 33 ;
25
25
26
26
private readonly Type bindingType ;
27
- private readonly bool member ;
27
+ private readonly bool isMember ;
28
+ private readonly bool isImplicit ;
28
29
private readonly string qualifier ;
29
30
30
- protected BindingKey ( Type bindingType , bool member , string qualifier ) {
31
+ protected BindingKey ( Type bindingType , bool isMember , bool isImplicit , string qualifier ) {
31
32
this . bindingType = bindingType ;
32
- this . member = member ;
33
+ this . isMember = isMember ;
34
+ this . isImplicit = isImplicit ;
33
35
this . qualifier = ( qualifier == null ) ? NoQualifierValue : qualifier ;
34
36
}
35
37
@@ -47,9 +49,19 @@ public Type BindingType {
47
49
/// Gets a value indicating whether this <see cref="IfInjector.IfBinding.BindingKey"/> is a property-only binding.
48
50
/// </summary>
49
51
/// <value><c>true</c> if member; otherwise, <c>false</c>.</value>
50
- public bool Member {
52
+ public bool IsMember {
51
53
get {
52
- return member ;
54
+ return isMember ;
55
+ }
56
+ }
57
+
58
+ /// <summary>
59
+ /// Gets a value indicating whether this instance is implicit. This facet does not affect the key for equals or hashing purposes.
60
+ /// </summary>
61
+ /// <value><c>true</c> if this instance is implicit; otherwise, <c>false</c>.</value>
62
+ public bool IsImplicit {
63
+ get {
64
+ return isImplicit ;
53
65
}
54
66
}
55
67
@@ -71,7 +83,7 @@ public string Qualifier {
71
83
/// </summary>
72
84
/// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns>
73
85
public override int GetHashCode ( ) {
74
- return HASHCODE_MULTIPLIER * BindingType . GetHashCode ( ) + Member . GetHashCode ( ) + qualifier . GetHashCode ( ) ;
86
+ return HASHCODE_MULTIPLIER * BindingType . GetHashCode ( ) + IsMember . GetHashCode ( ) + qualifier . GetHashCode ( ) ;
75
87
}
76
88
77
89
/// <summary>
@@ -97,57 +109,72 @@ public bool Equals(BindingKey obj) {
97
109
return true ;
98
110
} else {
99
111
return bindingType . Equals ( obj . bindingType ) &&
100
- member == obj . member &&
112
+ isMember == obj . isMember &&
101
113
qualifier . Equals ( obj . qualifier ) ;
102
114
}
103
115
}
104
116
105
117
/// <summary>
106
- /// Get the instance injector .
118
+ /// Get the implicit version of the current binding key .
107
119
/// </summary>
108
- /// <param name="keyType">Key type.</param>
109
- internal static BindingKey Get ( Type keyType ) {
110
- return Get ( keyType , null ) ;
120
+ /// <returns>The implicit.</returns>
121
+ internal BindingKey ToImplicit ( ) {
122
+ if ( IsImplicit ) {
123
+ return this ;
124
+ }
125
+
126
+ return new BindingKey (
127
+ bindingType : BindingType ,
128
+ isMember : IsMember ,
129
+ isImplicit : true ,
130
+ qualifier : Qualifier ) ;
111
131
}
112
132
113
133
/// <summary>
114
134
/// Gets a key.
115
135
/// </summary>
116
136
/// <returns>The internal.</returns>
117
- /// <param name="keyType">Key type .</param>
137
+ /// <param name="bindingType">bindingType .</param>
118
138
/// <param name="isMember">If set to <c>true</c> is member.</param>
119
- internal static BindingKey Get ( Type keyType , bool isMember ) {
120
- return new BindingKey ( keyType , isMember , null ) ;
139
+ /// <param name="qualifier">Qualifier.</param>
140
+ internal static BindingKey Get ( Type bindingType , string qualifier = null ) {
141
+ return new BindingKey (
142
+ bindingType : bindingType ,
143
+ isMember : false ,
144
+ isImplicit : false ,
145
+ qualifier : qualifier ) ;
121
146
}
122
147
123
148
/// <summary>
124
- /// Gets the internal .
149
+ /// Get the specified qualifier .
125
150
/// </summary>
126
- /// <returns>The internal.</returns>
127
- /// <param name="keyType">Key type.</param>
128
- /// <param name="isMember">If set to <c>true</c> is member.</param>
129
151
/// <param name="qualifier">Qualifier.</param>
130
- internal static BindingKey Get ( Type keyType , string qualifier ) {
131
- return new BindingKey ( keyType , false , qualifier ) ;
152
+ /// <typeparam name="BType">The 1st type parameter.</typeparam>
153
+ internal static BindingKey Get < BType > ( string qualifier = null ) where BType : class {
154
+ return Get ( typeof ( BType ) , qualifier ) ;
132
155
}
133
- }
134
-
135
- /// <summary>
136
- /// Typed binding key.
137
- /// </summary>
138
- internal class BindingKey < BType > : BindingKey where BType : class {
139
- internal static readonly BindingKey < BType > InstanceKey = new BindingKey < BType > ( false , null ) ;
140
- internal static readonly BindingKey < BType > MembersKey = new BindingKey < BType > ( true , null ) ;
141
156
142
- private BindingKey ( bool member , string qualifier ) : base ( typeof ( BType ) , member , qualifier ) { }
157
+ /// <summary>
158
+ /// Gets a key.
159
+ /// </summary>
160
+ /// <returns>The internal.</returns>
161
+ /// <param name="concreteType">Concrete type.</param>
162
+ /// <param name="isMember">If set to <c>true</c> is member.</param>
163
+ internal static BindingKey GetMember ( Type concreteType ) {
164
+ return new BindingKey (
165
+ bindingType : concreteType ,
166
+ isMember : true ,
167
+ isImplicit : false ,
168
+ qualifier : null ) ;
169
+ }
143
170
144
171
/// <summary>
145
- /// Get the instance injector .
172
+ /// Gets the member key .
146
173
/// </summary>
147
- /// <param name="keyType">Key type .</param >
148
- /// <param name="qualifier">Qualifier .</param >
149
- internal static BindingKey Get ( string qualifier ) {
150
- return new BindingKey < BType > ( false , qualifier ) ;
174
+ /// <returns>The member .</returns >
175
+ /// <typeparam name="CType">The 1st type parameter .</typeparam >
176
+ internal static BindingKey GetMember < CType > ( ) {
177
+ return GetMember ( typeof ( CType ) ) ;
151
178
}
152
179
}
153
180
}
0 commit comments