1) The [Default ...] attribute has no effect. In V7 there was an indication when a user changed from the default value. To date I have never seen that work in V8, including in cases like this one where a default value is clearly specified. I believe I have reported this in the past, but I am bringing it up again because this trivial code sample shows the problem.
2) More seriously, the [TypeConverter ...] has no effect. I ran it with Visual Studio and put breakpoints on the type converter's 4 functions and none of them ever got called. As a result, this property gets displayed as a check box. Because of the type converter, it is supposed to be displayed as one of two strings -- "Enable" or "Disable". This works in Version 7, but has never worked in Version 8. I believe I have reported this one in the past, too, but I am bringing it up again because this trivial code sample shows the problem.
If anyone sees a problem with the code, by all means let me know.
Thanks,
EV
// ////////////////////////////////////////////////////////////////////////////////// // // This test program illustrates two bugs in NinjaTader Version 8 // 1) The [DefaultValue ...] attribute has not effect // 2) The [TypeConverter ...] attribute has no effect // * Debugger breakpoints show the type converter is never even called // // ////////////////////////////////////////////////////////////////////////////////// using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class AATypeConverterTest : Indicator { // /////////////////////////////////////////////////////////////////////////////////////////////////// // Boolean property that should be displayed in the Indicators dialog as a string private bool enableTickerData = true; [DefaultValue(typeof(bool), "true")] [TypeConverter(typeof(EnableDisableConverter))] [Browsable(true)] // Do show in the indicator property dialog [Display(Order = 0, Name = "Test", Description = "Test an Enable/disable property")] public bool EnableTickerData { get { return enableTickerData; } set { enableTickerData = value; } } // /////////////////////////////////////////////////////////////////////////////////////////////////// // Type converter for bool values to ("On" or "Off") or else ("Yes" and "No") class EnableDisableConverter : BooleanConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return (destinationType == typeof(string)) ? true : base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { return (bool)value ? "Enable" : "Disable"; } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return true; } // "false" makes the string non-editable public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { return (string)value == "Enable"; } } } }
Comment