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"/>
24 public class ConstructorCandidateCollection
: ReadOnlyCollectionBase
26 private bool hasAmbiguousFewerArgumentsCandidate
;
27 private ConstructorCandidate fewerArgumentsCandidate
;
30 /// Adds the specified candidate.
32 /// <param name="candidate">The candidate.</param>
33 public void Add(ConstructorCandidate candidate
)
35 if (fewerArgumentsCandidate
== null)
37 fewerArgumentsCandidate
= candidate
;
38 hasAmbiguousFewerArgumentsCandidate
= false;
42 int constructorParamCount
= candidate
.Constructor
.GetParameters().Length
;
43 int fewerArgumentsCount
= fewerArgumentsCandidate
.Constructor
.GetParameters().Length
;
45 if (constructorParamCount
< fewerArgumentsCount
)
47 fewerArgumentsCandidate
= candidate
;
49 else if (constructorParamCount
== fewerArgumentsCount
)
51 hasAmbiguousFewerArgumentsCandidate
= true;
55 InnerList
.Add(candidate
);
59 /// Gets the fewer arguments candidate.
61 /// <value>The fewer arguments candidate.</value>
62 public ConstructorCandidate FewerArgumentsCandidate
64 get { return fewerArgumentsCandidate; }
67 public bool HasAmbiguousFewerArgumentsCandidate
69 get { return hasAmbiguousFewerArgumentsCandidate; }
73 /// Clears this instance.