Validation rule: check for inputproperties=null?

Validation rule: check for inputproperties=null?

Old forum URL:

JCardina posted on Wednesday, March 28, 2012

I've noticed in the Ebook that Rocky does not check if InputProperties=null, for example:

 public class ValidPrefix : Csla.Rules.BusinessRule
      public string Prefix { get; private set; }
      public ValidPrefix(Csla.Core.IPropertyInfo primaryProperty, string prefix)
        : base(primaryProperty)
        InputProperties = new List<Csla.Core.IPropertyInfo> { PrimaryProperty }; //<--NO CHECK IF NULL


However when trying to research something on the forums here I noticed Jonny and others consistently do this:

if (InputProperties == null)
        InputProperties = new List<IPropertyInfo>();

My question is which way should it be done?

JonnyBee replied on Wednesday, March 28, 2012


When you start to subclass rules you will prefer to use the latter one and keep a consistent programming model so that you do not destroy InputProperties from the base rule. 

If you never subclass a rule the first one will also work fine.

I am however going to change the programming model a bit for CSLA 4.5 - so that InputProperties and AffectedProperties are always treated the same and immediately get an instance. I do not fancy having to always make sure that InputProperties have an instance (no instance created  by default) and AffectedProperties always have an instance. And this fails at runtime with a NullReferenceException - not in the compiler.




JCardina replied on Wednesday, March 28, 2012

Thank you Jonny!

Copyright (c) Marimer LLC