Skip to content
This repository
Browse code

Fix NullReferenceException in InsertCtorDialog.CreateCtorParams().

commit ddd2ff1855b90932faa1d3a40952dac3249c129f 1 parent 4e45d98
Daniel Grunwald dgrunwald authored
19 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertCtorDialog.xaml.cs
@@ -63,9 +63,14 @@ protected override void Initialize()
63 63
64 64 var typeResolveContext = refactoringContext.GetTypeResolveContext();
65 65 if (typeResolveContext == null) {
  66 + parameterList = EmptyList<PropertyOrFieldWrapper>.Instance;
66 67 return;
67 68 }
68 69 var resolvedCurrent = typeResolveContext.CurrentTypeDefinition;
  70 + if (resolvedCurrent == null) {
  71 + parameterList = EmptyList<PropertyOrFieldWrapper>.Instance;
  72 + return;
  73 + }
69 74
70 75 parameterList = CreateCtorParams(resolvedCurrent).ToList();
71 76 this.varList.ItemsSource = parameterList;
@@ -74,23 +79,17 @@ protected override void Initialize()
74 79 Visibility = System.Windows.Visibility.Visible;
75 80 }
76 81
77   - IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(IType sourceType)
  82 + IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(ITypeDefinition sourceType)
78 83 {
79 84 int i = 0;
80 85
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)) {
85 87 yield return new PropertyOrFieldWrapper(f) { Index = i };
86 88 i++;
87 89 }
88 90
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())) {
94 93 yield return new PropertyOrFieldWrapper(p) { Index = i };
95 94 i++;
96 95 }

Git Notes

build

Build 5.0.0.4543 on master successful

0 comments on commit ddd2ff1

Please sign in to comment.
Something went wrong with that request. Please try again.