Browse Source

add support for generic type parameters to InsertCtor

pull/1/head
Siegfried Pammer 16 years ago
parent
commit
ddf1d11037
  1. 9
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs
  2. 14
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs

9
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs

@ -40,17 +40,20 @@ namespace SharpRefactoring.Gui @@ -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<PropertyOrFieldWrapper> 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)),

14
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/PropertyOrFieldWrapper.cs

@ -58,11 +58,21 @@ namespace SharpRefactoring.Gui @@ -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) ||

Loading…
Cancel
Save