@ -33,20 +33,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -33,20 +33,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
readonly IMethod methodDefinition ;
readonly ITypeParameter [ ] specializedTypeParameters ;
readonly bool genericMethodIsSpecial ized;
readonly bool isParameter ized;
readonly TypeParameterSubstitution substitutionWithoutSpecializedTypeParameters ;
public SpecializedMethod ( IMethod methodDefinition , TypeParameterSubstitution substitution )
: base ( methodDefinition )
{
SpecializedMethod specializedMethodDefinition = methodDefinition as SpecializedMethod ;
if ( specializedMethodDefinition ! = null )
this . genericMethodIsSpecialized = specializedMethodDefinition . genericMethodIsSpecialized ;
// The base ctor might have unpacked a SpecializedMember
// (in case we are specializing an already-specialized method)
methodDefinition = ( IMethod ) base . baseMember ;
if ( substitution = = null )
throw new ArgumentNullException ( "substitution" ) ;
this . methodDefinition = methodDefinition ;
this . isParameterized = substitution . MethodTypeArguments ! = null ;
if ( methodDefinition . TypeParameters . Count > 0 ) {
// The method is generic, so we need to specialize the type parameters
// (for specializing the constraints, and also to set the correct Owner)
@ -54,7 +50,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -54,7 +50,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
for ( int i = 0 ; i < specializedTypeParameters . Length ; i + + ) {
specializedTypeParameters [ i ] = new SpecializedTypeParameter ( methodDefinition . TypeParameters [ i ] , this ) ;
}
if ( ! genericMethodIsSpecial ized) {
if ( ! isParameter ized) {
// Add substitution that replaces the base method's type parameters with our specialized version
// but do this only if the type parameters on the baseMember have not already been substituted
substitutionWithoutSpecializedTypeParameters = this . Substitution ;
@ -71,8 +67,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -71,8 +67,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
// in this case.
substitutionWithoutSpecializedTypeParameters = this . Substitution ;
}
if ( substitution ! = null & & substitution . MethodTypeArguments ! = null & & methodDefinition . TypeParameters . Count > 0 )
this . genericMethodIsSpecialized = true ;
if ( specializedTypeParameters ! = null ) {
// Set the substitution on the type parameters to the final composed substitution
foreach ( var tp in specializedTypeParameters . OfType < SpecializedTypeParameter > ( ) ) {
@ -82,13 +76,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -82,13 +76,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
/// <summary>
/// Gets the type arguments passed to this method.
/// If only the type parameters for the class were specified and the generic method
/// itself is not specialized yet, this property will return an empty list.
/// </summary>
public IList < IType > TypeArguments {
get { return genericMethodIsSpecialized ? this . Substitution . MethodTypeArguments : EmptyList < IType > . Instance ; }
get { return this . Substitution . MethodTypeArguments ? ? EmptyList < IType > . Instance ; }
}
public bool IsParameterized {
get { return isParameterized ; }
}
public IList < IUnresolvedMethod > Parts {
@ -137,8 +130,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -137,8 +130,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return methodDefinition . IsAccessor ; }
}
public IMethod ReducedFrom {
get { return null ; }
public IMethod ReducedFrom {
get { return null ; }
}
IMember accessorOwner ;
@ -149,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -149,7 +142,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if ( result ! = null ) {
return result ;
} else {
result = SpecializedMember . Create ( methodDefinition . AccessorOwner , this . Substitution ) ;
result = methodDefinition . AccessorOwner . Specialize ( this . Substitution ) ;
return LazyInit . GetOrSet ( ref accessorOwner , result ) ;
}
}
@ -161,7 +154,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -161,7 +154,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public override IMemberReference ToMemberReference ( )
{
// Pass the MethodTypeArguments to the SpecializingMemberReference only if
// the generic method itself is special ized, not if the generic method is only
// the generic method itself is parameter ized, not if the generic method is only
// specialized with class type arguments.
// This is necessary due to this part of the ToMemberReference() contract:
@ -171,7 +164,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -171,7 +164,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
// This means that if the method itself isn't specialized,
// we must not include TypeParameterReferences for the specialized type parameters
// in the resulting member reference.
if ( genericMethodIsSpecial ized) {
if ( isParameter ized) {
return new SpecializingMemberReference (
baseMember . ToMemberReference ( ) ,
ToTypeReference ( base . Substitution . ClassTypeArguments ) ,
@ -196,12 +189,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@@ -196,12 +189,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public new IMethod MemberDefinition {
get {
return ( IMethod ) base . MemberDefinition ;
}
public override IMember Specialize ( TypeParameterSubstitution newSubstitution )
{
return methodDefinition . Specialize ( TypeParameterSubstitution . Compose ( newSubstitution , substitutionWithoutSpecializedTypeParameters ) ) ;
}
IMethod IMethod . Specialize ( TypeParameterSubstitution newSubstitution )
{
return methodDefinition . Specialize ( TypeParameterSubstitution . Compose ( newSubstitution , substitutionWithoutSpecializedTypeParameters ) ) ;
}
public override string ToString ( )
{
StringBuilder b = new StringBuilder ( "[" ) ;