Use GetScopeType() since ScopeType always returns null if it's a generic var

This commit is contained in:
de4dot 2014-03-24 07:43:31 +01:00
parent 68a8f27031
commit 60cff6c4a4
2 changed files with 25 additions and 2 deletions

View File

@ -1520,6 +1520,29 @@ namespace de4dot.code.renamer {
return null;
}
internal static ITypeDefOrRef GetScopeType(TypeSig typeSig) {
if (typeSig == null)
return null;
var scopeType = typeSig.ScopeType;
if (scopeType != null)
return scopeType;
for (int i = 0; i < 100; i++) {
var nls = typeSig as NonLeafSig;
if (nls == null)
break;
typeSig = nls.Next;
}
switch (typeSig.GetElementType()) {
case ElementType.MVar:
case ElementType.Var:
return new TypeSpecUser(typeSig);
default:
return null;
}
}
string GetNewPropertyNamePrefix(MethodNameGroup group) {
const string defaultVal = "Prop_";
@ -1527,7 +1550,7 @@ namespace de4dot.code.renamer {
if (propType == null)
return defaultVal;
var elementType = propType.ScopeType.ToTypeSig(false).RemovePinnedAndModifiers();
var elementType = GetScopeType(propType).ToTypeSig(false).RemovePinnedAndModifiers();
if (propType is GenericInstSig || elementType is GenericSig)
return defaultVal;

View File

@ -44,7 +44,7 @@ namespace de4dot.code.renamer {
string prefix = GetPrefix(typeRef);
var elementType = typeRef.ScopeType;
var elementType = Renamer.GetScopeType(typeRef);
if (elementType == null && IsFnPtrSig(typeRef))
return fnPtrNameCreator.Create();
if (IsGenericParam(elementType))