Browse Source

Fixed null reference exception when generating code in the Python forms designer for a non-IComponent object's AddRange method.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4579 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
42988ba59a
  1. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  2. 77
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAddRangeForNonComponentTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

6
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs

@ -507,7 +507,7 @@ namespace ICSharpCode.PythonBinding @@ -507,7 +507,7 @@ namespace ICSharpCode.PythonBinding
MethodInfo addRangeMethod = GetAddRangeSerializationMethod(collectionProperty);
if (addRangeMethod != null) {
Type arrayElementType = GetArrayParameterType(addRangeMethod);
AppendSystemArray(codeBuilder, component.Site.Name, propertyDescriptor.Name + "." + addRangeMethod.Name, arrayElementType.FullName, GetSitedComponentsAndNonComponents(collectionProperty));
AppendSystemArray(codeBuilder, propertyOwnerName, propertyDescriptor.Name + "." + addRangeMethod.Name, arrayElementType.FullName, GetSitedComponentsAndNonComponents(collectionProperty));
} else {
MethodInfo addMethod = GetAddSerializationMethod(collectionProperty);
ParameterInfo[] parameters = addMethod.GetParameters();
@ -712,10 +712,10 @@ namespace ICSharpCode.PythonBinding @@ -712,10 +712,10 @@ namespace ICSharpCode.PythonBinding
get { return parent; }
}
public static void AppendSystemArray(PythonCodeBuilder codeBuilder, string componentName, string methodName, string typeName, ICollection components)
public static void AppendSystemArray(PythonCodeBuilder codeBuilder, string propertyName, string methodName, string typeName, ICollection components)
{
if (components.Count > 0) {
codeBuilder.AppendIndented("self._" + componentName + "." + methodName + "(");
codeBuilder.AppendIndented(propertyName + "." + methodName + "(");
AppendSystemArray(codeBuilder, typeName, components);
codeBuilder.Append(")");
codeBuilder.AppendLine();

77
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAddRangeForNonComponentTestFixture.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
class NonComponentToolbar
{
NonComponentToolbarToolsCollection tools = new NonComponentToolbarToolsCollection();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NonComponentToolbarToolsCollection Tools {
get { return tools; }
}
}
class NonComponentToolbarToolsCollection : CollectionBase
{
public void Add(string s)
{
InnerList.Add(s);
}
public void AddRange(string[] strings)
{
InnerList.AddRange(strings);
}
}
/// <summary>
/// Tests that we can generate python code for a property which is not an IComponent and one of
/// its properties is a collection that needs its content generated as code.
///
/// class Toolbar : IDisposable
/// {
/// [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
/// public ToolsCollection Tools { get; }
/// }
///
/// class ToolsCollection : CollectionBase
/// {
/// }
/// </summary>
[TestFixture]
public class GenerateAddRangeForNonComponentTestFixture
{
[Test]
public void GenerateAddRangeCode()
{
NonComponentToolbar toolbar = new NonComponentToolbar();
toolbar.Tools.Add("One");
PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(toolbar).Find("Tools", true);
PythonCodeBuilder codeBuilder = new PythonCodeBuilder();
codeBuilder.IndentString = " ";
PythonDesignerComponent.AppendMethodCallWithArrayParameter(codeBuilder, "self.ReportViewer.Toolbar", toolbar, propertyDescriptor, false);
string expectedCode = "self.ReportViewer.Toolbar.Tools.AddRange(System.Array[System.String](\r\n" +
" [\"One\"]))\r\n";
Assert.AreEqual(expectedCode, codeBuilder.ToString(), codeBuilder.ToString());
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -178,6 +178,7 @@ @@ -178,6 +178,7 @@
<Compile Include="Designer\FormBaseClassCreatedOnLoadTestFixture.cs" />
<Compile Include="Designer\GenerateAcceptButtonFormTestFixture.cs" />
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
<Compile Include="Designer\GenerateAddRangeForNonComponentTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
<Compile Include="Designer\GenerateBackgroundWorkerTestFixture.cs" />

Loading…
Cancel
Save