Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the exception being thrown while converting (assigning value) (i.e. when <a href="http://msdn.microsoft.com/en-us/library/zb260h9b.aspx" rel="nofollow">TypeConverter.ConvertFrom()</a> is called) to a property in the property grid (for example, InvalidCastException), then you can catch in the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx" rel="nofollow">TypeConverter</a> for that property.</p> <pre><code>class MyTypeConverter : TypeConverter { public override bool ConvertFrom(ITypeDescriptorContext context, Type sourceType) { try { return base.ConvertFrom(context, sourceType); } catch(Exception e) { // Process the exception (for example, Log(e)) or Debug.Assert() throw; } } } // Using the TypeConverter in your class class MyClass { [ReadOnly(false)] [PropertyOrder(1)] [DisplayName("Property 1")] [TypeConverter(typeof(MyTypeConverter))] public int Property1 { get; set; } } </code></pre> <p>You can also override other methods of the base <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx" rel="nofollow">TypeConverter</a> class accordingly.</p> <p>Going by the example, that you have added, it looks like you want the to deduce the reason why the communication with the device has failed (port not open, etc.). Then why not set a property or flag (for example, <code>Error</code> or <code>CommunicationError</code>) in the <code>Device</code> class that tells whether the specific error has occurred.</p> <p>Then in the <code>TypeConverter</code> check for this property before accessing other properties, if in error then simply return from the <code>ConvertFrom()</code> without calling the <code>base</code> implementation. If the error is recoverable, which in your case appears to be a communication error, then allow the user to retry, rather than throwing an exception.</p> <p>In addition, if you are mapping the device parameters directly onto the class and you have a property that you use in the property grid but do not want it to be written on the device, then mark it with a custom attribute (say boolean <code>DeviceWritable</code>). In the communication layer (where you actually write the values to the device), check for this custom attribute, if it is set as <code>true</code> then write to the device otherwise do not write to the device. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload