Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Missing Types to Intrinsic TypeDescriptor table #1936

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Common\tests\InternalUtilitiesForTests\InternalUtilitiesForTests.csproj" />
<ProjectReference Include="..\..\..\System.Windows.Forms\src\System.Windows.Forms.csproj" />
<ProjectReference Include="..\..\src\System.Windows.Forms.Design.Editors.csproj" />
<Compile Include="..\..\..\Common\tests\CommonTestHelper.cs" Link="Common\CommonTestHelper.cs" />
<Compile Include="..\..\..\Common\tests\CommonMemberDataAttribute.cs" Link="Common\CommonMemberDataAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public void CollectionEditor_Ctor_Type(Type type, Type expectedItemType)
Assert.Equal(new Type[] { expectedItemType }, editor.NewItemTypes);
}

[Fact]
public void CollectionEditor_EnsureEditor()
{
TypeDescriptor.AddEditorTable(typeof(UITypeEditor), UITypeEditor.s_intrinsicEditors);

IList list = new List<int>();
var editor = TypeDescriptor.GetEditor(typeof(IList), typeof(UITypeEditor));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for other types, for example for non-interface types?
Does this work for the instance TypeDescriptor.GetEditor(list...)

Copy link
Contributor

@weltkante weltkante Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these cases should be added to the tests, most callers won't ask for the editor on the interface type but either pass a concrete class type or an actual instance implementing the interface.

Assert.NotNull(editor);
Assert.Equal(typeof(CollectionEditor).AssemblyQualifiedName, editor.GetType().ToString());
}

[Fact]
public void CollectionEditor_Ctor_NullType()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -44,5 +44,14 @@ public void FontEditor_GetPaintValueSupported_Invoke_ReturnsFalse(ITypeDescripto
var editor = new FontEditor();
Assert.False(editor.GetPaintValueSupported(context));
}

//[Fact]
//public void EnsureEditor()
//{
// var font = new Font(FontFamily.GenericSansSerif, 3.0f);
// var editor = TypeDescriptor.GetEditor(font, font.GetType());
// Assert.NotNull(editor);
// Assert.Equal("System.Drawing.Design.FontEditor", editor.GetType().ToString());
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("System.Windows.Forms.Tests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Windows.Forms.Design.Editors.Tests, PublicKey=00000000000000000400000000000000")]

// This is needed in order to Moq internal interfaces for testing
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.IO;

namespace System.Drawing.Design
Expand All @@ -14,23 +15,30 @@ namespace System.Drawing.Design
/// </summary>
public class UITypeEditor
{
static UITypeEditor()
// Our set of intrinsic editors.
internal static Hashtable s_intrinsicEditors = new Hashtable
{
Hashtable intrinsicEditors = new Hashtable
{
// Our set of intrinsic editors.
[typeof(DateTime)] = "System.ComponentModel.Design.DateTimeEditor, " + AssemblyRef.SystemDesign,
[typeof(Array)] = "System.ComponentModel.Design.ArrayEditor, " + AssemblyRef.SystemDesign,
[typeof(IList)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
[typeof(ICollection)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
[typeof(byte[])] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
[typeof(Stream)] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
[typeof(string[])] = "System.Windows.Forms.Design.StringArrayEditor, " + AssemblyRef.SystemDesign,
[typeof(Collection<string>)] = "System.Windows.Forms.Design.StringCollectionEditor, " + AssemblyRef.SystemDesign
};
// System.ComponentModel.Design editors
[typeof(DateTime)] = "System.ComponentModel.Design.DateTimeEditor, " + AssemblyRef.SystemDesign,
[typeof(Array)] = "System.ComponentModel.Design.ArrayEditor, " + AssemblyRef.SystemDesign,
[typeof(IList)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
[typeof(ICollection)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
[typeof(byte[])] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
[typeof(Stream)] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,

// System.Windows.Forms.Design editors
[typeof(string[])] = "System.Windows.Forms.Design.StringArrayEditor, " + AssemblyRef.SystemDesign,
[typeof(Collection<string>)] = "System.Windows.Forms.Design.StringCollectionEditor, " + AssemblyRef.SystemDesign,

// System.Drawing.Design editors
[typeof(Image)] = "System.Drawing.Design.ImageEditor, " + AssemblyRef.SystemDesign,
[typeof(Font)] = "System.Drawing.Design.FontEditor, " + AssemblyRef.SystemDesign,
};

static UITypeEditor()
{
// Add our intrinsic editors to TypeDescriptor.
TypeDescriptor.AddEditorTable(typeof(UITypeEditor), intrinsicEditors);
TypeDescriptor.AddEditorTable(typeof(UITypeEditor), s_intrinsicEditors);
}

/// <summary>
Expand Down