corientdev / imagelistview

Automatically exported from code.google.com/p/imagelistview
1 stars 0 forks source link

Please make internal items public to allow custom renderers #166

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
(I'm using the NuGet package)

Trying to write my own renderer, I started by copying the source of the 
TilesRenderer class.

This does not compile, because the following members/types are internal instead 
of protected or public:

 - internal string Manina.Windows.Forms.ImageListViewItem.GetSubItemText(ColumnType type)
 - internal Image Manina.Windows.Forms.ImageListViewItem.GetCachedImage(CachedImageType imageType)
 - internal enum Manina.Windows.Forms.CachedImageType

Please make a change to allow these members/types to be accessible from outside 
the ImageListView assembly.

Original issue reported on code.google.com by uwe.k...@gmail.com on 6 Nov 2013 at 8:18

GoogleCodeExporter commented 9 years ago
To have a workaround I've created the following extension methods/type for the 
missing  methods and types:

------------------------------------
namespace MyNamespace
{
    using System;
    using System.Drawing;
    using System.Reflection;
    using Manina.Windows.Forms;

    public static class ImageListViewItemExtensions
    {
        public static Image GetCachedImage(this ImageListViewItem item, CachedImageType imageType)
        {
            var enumType = item.GetType().Assembly.GetType(@"Manina.Windows.Forms.CachedImageType");
            var realType = Enum.ToObject(enumType, (int) imageType);

            return
                item.GetType().InvokeMember(
                    @"GetCachedImage",
                    BindingFlags.Public | BindingFlags.NonPublic |
                    BindingFlags.Instance | BindingFlags.InvokeMethod,
                    null,
                    item,
                    new[] {realType}) as Image;
        }

        public static string GetSubItemText(this ImageListViewItem item, ColumnType type)
        {
            return
                item.GetType().InvokeMember(
                    @"GetSubItemText",
                    BindingFlags.Public | BindingFlags.NonPublic |
                    BindingFlags.Instance | BindingFlags.InvokeMethod,
                    null,
                    item,
                    new object[] {type}) as string;
        }
    }

    public enum CachedImageType
    {
        Thumbnail,
        SmallIcon,
        LargeIcon,
    }
}
------------------------------------

Maybe this helps someone to get started with the same issue.

Original comment by uwe.k...@gmail.com on 6 Nov 2013 at 8:54

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r703.

Original comment by oozcitak on 25 Aug 2014 at 4:03