MyXConverterStrat.cs 'NinjaTrader.NinjaScript.Strategies.MyXConverterSt rat.GetProperties(System.Component Model.ITypeDescriptorContext, object, System.Attribute[])': not all code paths return a value CS0161 9206 49
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
I checked this prior answer
ref. https://forum.ninjatrader.com/forum/ninjatrader-7/general-development/67251-error-cs0161-not-all-code-paths-return-a-value
which doesn't seem to pinpoint the issue since
the public bool MyX() method does return false outside the if statement.
Ref. https://forum.ninjatrader.com/forum/...44#post1315244
namespace NinjaTrader.NinjaScript.[B]Strategies[/B]
{
[TypeConverter("NinjaTrader.NinjaScript.Strategies.MyXConverter")]
public class MyXConverterStrat : [B]Strategy[/B]
{
public bool MyX()
{
if(Cond0())
{
return true;
}
return false;
}
}
}
#region ConverterStuff
public class MyXConverter: StrategyBaseConverter
{
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
{
MyXConverterStrat strategy = component as MyXConverterStrat; // need the same name as the Class name
PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
? base.GetProperties(context, component, attrs)
: TypeDescriptor.GetProperties(component, attrs);
if (strategy == null || propertyDescriptorCollection == null)
return propertyDescriptorCollection;
PropertyDescriptor UpSoundFile = propertyDescriptorCollection["UpSoundFile"];
// remove removable properties first
propertyDescriptorCollection.Remove(UpSoundFile);
// Add back in if...
if (strategy.MyX())
{
propertyDescriptorCollection.Add(UpSoundFile);
}
return propertyDescriptorCollection;
}
// Important: This must return true otherwise the type convetor will not be called
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{ return true; }
}
#endregion
}
extra source:

Comment