Enum Converter in AutoCAD

Enum Converter in AutoCAD

BrentBurgess1980
Collaborator Collaborator
962 Views
1 Reply
Message 1 of 2

Enum Converter in AutoCAD

BrentBurgess1980
Collaborator
Collaborator

Hi All,

 

I have an enum that I am binding to a combobox. The issue I am having is that it works in a WPF App

enum Description WPF App.JPG

But not in AutoCAD

enum Description AutoCAD.JPG

My enum...

    [TypeConverter(typeof(EnumDescriptionTypeConverter))]
    public enum ApplyTo
        {
        [Description("Entire Drawing")]
        EntireDrawing,
        [Description("Current Selection")]
        CurrentSelection,
        }

The Converter

    public class EnumDescriptionTypeConverter : Autodesk.AutoCAD.DatabaseServices.EnumConverter
        {
        public EnumDescriptionTypeConverter(Type type)
            : base(type)
            {
            }
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
            {
            if (destinationType == typeof(string))
                {
                if (value != null)
                    {
                    FieldInfo fi = value.GetType().GetField(value.ToString());
                    if (fi != null)
                        {
                        var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                        return ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
                        }
                    }

                return string.Empty;
                }

            return base.ConvertTo(context, culture, value, destinationType);
            }
        }

I have tried the EnumConverter from System.ComponentModel.EnumConverter

 

and the xaml code

   <Window.Resources>
        <ObjectDataProvider x:Key="applyTo" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="dbf:ApplyTo"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
<ComboBox Name="cboApplyTo" Grid.Row="1" Grid.Column="1" Margin="3" ItemsSource="{Binding Source={StaticResource applyTo}}"/>

This seems strange that it would work in the WPF app, but not AutoCAD.

 

Any ideas would be appreciated.

 

Cheers,

 

Brent

 

0 Likes
Accepted solutions (1)
963 Views
1 Reply
Reply (1)
Message 2 of 2

Virupaksha_aithal
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I am able to reproduce the issue. I have updated AutoCAD engineering team about this behavior.

 

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes