Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit ddd2ff1

Browse files
committed
Fix NullReferenceException in InsertCtorDialog.CreateCtorParams().
1 parent 4e45d98 commit ddd2ff1

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertCtorDialog.xaml.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ protected override void Initialize()
6363

6464
var typeResolveContext = refactoringContext.GetTypeResolveContext();
6565
if (typeResolveContext == null) {
66+
parameterList = EmptyList<PropertyOrFieldWrapper>.Instance;
6667
return;
6768
}
6869
var resolvedCurrent = typeResolveContext.CurrentTypeDefinition;
70+
if (resolvedCurrent == null) {
71+
parameterList = EmptyList<PropertyOrFieldWrapper>.Instance;
72+
return;
73+
}
6974

7075
parameterList = CreateCtorParams(resolvedCurrent).ToList();
7176
this.varList.ItemsSource = parameterList;
@@ -74,23 +79,17 @@ protected override void Initialize()
7479
Visibility = System.Windows.Visibility.Visible;
7580
}
7681

77-
IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(IType sourceType)
82+
IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(ITypeDefinition sourceType)
7883
{
7984
int i = 0;
8085

81-
foreach (var f in sourceType.GetFields().Where(field => !field.IsConst
82-
&& field.IsStatic == sourceType.GetDefinition().IsStatic
83-
&& field.DeclaringType.FullName == sourceType.FullName
84-
&& field.ReturnType != null)) {
86+
foreach (var f in sourceType.Fields.Where(f => !f.IsStatic)) {
8587
yield return new PropertyOrFieldWrapper(f) { Index = i };
8688
i++;
8789
}
8890

89-
foreach (var p in sourceType.GetProperties().Where(prop => prop.CanSet && !prop.IsIndexer
90-
&& prop.IsAutoImplemented()
91-
&& prop.IsStatic == sourceType.GetDefinition().IsStatic
92-
&& prop.DeclaringType.FullName == sourceType.FullName
93-
&& prop.ReturnType != null)) {
91+
foreach (var p in sourceType.Properties.Where(prop => !prop.IsStatic && prop.CanSet
92+
&& !prop.IsIndexer && prop.IsAutoImplemented())) {
9493
yield return new PropertyOrFieldWrapper(p) { Index = i };
9594
i++;
9695
}

0 commit comments

Comments
 (0)