diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs index 93d416acaf..fd6442122a 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs @@ -40,17 +40,20 @@ namespace SharpRefactoring.Gui protected override string GenerateCode(LanguageProperties language, IClass currentClass) { - var line = editor.Document.GetLineForOffset(anchor.Offset); + IDocumentLine line = editor.Document.GetLineForOffset(anchor.Offset); string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset); - var filtered = parameterList.Where(p => p.IsSelected).OrderBy(p => p.Index).ToList(); + List filtered = parameterList + .Where(p => p.IsSelected) + .OrderBy(p => p.Index) + .ToList(); BlockStatement block = new BlockStatement(); foreach (PropertyOrFieldWrapper w in filtered) { if (w.AddCheckForNull) { - if (w.Type.IsReferenceType == true) + if (w.Type.IsReferenceType == true || PropertyOrFieldWrapper.IsGenericReferenceType(w.Type)) block.AddChild( new IfElseStatement( new BinaryOperatorExpression(new IdentifierExpression(w.ParameterName), BinaryOperatorType.Equality, new PrimitiveExpression(null)), diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs index 8e2cdfa228..a9d0f23b05 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs @@ -58,11 +58,21 @@ namespace SharpRefactoring.Gui public bool IsNullable { get { - return member.ReturnType.IsReferenceType == true || - member.ReturnType.IsConstructedReturnType && member.ReturnType.Name == "Nullable"; + return member.ReturnType.IsReferenceType == true + || member.ReturnType.IsConstructedReturnType && member.ReturnType.Name == "Nullable" + || IsGenericReferenceType(member.ReturnType); } } + public static bool IsGenericReferenceType(IReturnType type) + { + if (type == null || !type.IsGenericReturnType) + return false; + ITypeParameter param = type.CastToGenericReturnType().TypeParameter; + return param.HasReferenceTypeConstraint + || param.Constraints.Any(constr => constr.IsReferenceType == true); + } + public bool HasRange { get { return IsTypeWithRange(member.ReturnType) ||