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.
18 using System
.Collections
;
21 /// Collection of <see cref="ConstructorCandidate"/>
26 public class ConstructorCandidateCollection
: ReadOnlyCollectionBase
28 private bool hasAmbiguousFewerArgumentsCandidate
;
29 private ConstructorCandidate fewerArgumentsCandidate
;
32 /// Adds the specified candidate.
34 /// <param name="candidate">The candidate.</param>
35 public void Add(ConstructorCandidate candidate
)
37 if (fewerArgumentsCandidate
== null)
39 fewerArgumentsCandidate
= candidate
;
40 hasAmbiguousFewerArgumentsCandidate
= false;
44 int constructorParamCount
= candidate
.Constructor
.GetParameters().Length
;
45 int fewerArgumentsCount
= fewerArgumentsCandidate
.Constructor
.GetParameters().Length
;
47 if (constructorParamCount
< fewerArgumentsCount
)
49 fewerArgumentsCandidate
= candidate
;
51 else if (constructorParamCount
== fewerArgumentsCount
)
53 hasAmbiguousFewerArgumentsCandidate
= true;
57 InnerList
.Add(candidate
);
61 /// Gets the fewer arguments candidate.
63 /// <value>The fewer arguments candidate.</value>
64 public ConstructorCandidate FewerArgumentsCandidate
66 get { return fewerArgumentsCandidate; }
69 public bool HasAmbiguousFewerArgumentsCandidate
71 get { return hasAmbiguousFewerArgumentsCandidate; }
75 /// Clears this instance.