/// <summary> /// Initializes the given <paramref name="column"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="column">The <see cref="PropertyColumn"/> which to initialze.</param> /// <param name="properties">The properties.</param> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> protected static void Initialize(IMansionContext context, PropertyColumn column, IPropertyBag properties) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (column == null) throw new ArgumentNullException("column"); if (properties == null) throw new ArgumentNullException("properties"); // get the allow null flag column.AllowNullValue = properties.Get(context, "allowNullValue", false); // check if there is an expression string expressionString; if (properties.TryGet(context, "expression", out expressionString)) { var expressionService = context.Nucleus.ResolveSingle<IExpressionScriptService>(); column.HasExpression = true; column.Expression = expressionService.Parse(context, new LiteralResource(expressionString)); } // get the default value string defaultValue; if (properties.TryGet(context, "defaultValue", out defaultValue)) { var expressionService = context.Nucleus.ResolveSingle<IExpressionScriptService>(); var defaultValueExpression = expressionService.Parse(context, new LiteralResource(defaultValue)); column.DefaultValue = defaultValueExpression.Execute<object>(context); column.HasDefaultValue = true; } }
/// <summary> /// Creates a <see cref="DateTimePropertyColumn"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="propertyName">The name of the property.</param> /// <param name="columnName">The name of the column.</param> /// <param name="properties">The properties of the column.</param> /// <returns>Returns the created column.</returns> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public static PropertyColumn CreatePropertyColumn(IMansionContext context, string propertyName, string columnName, IPropertyBag properties) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (string.IsNullOrEmpty(propertyName)) throw new ArgumentNullException("propertyName"); if (string.IsNullOrEmpty(columnName)) throw new ArgumentNullException("columnName"); if (properties == null) throw new ArgumentNullException("properties"); // create the column var column = new PropertyColumn(propertyName, columnName); // init the column from the properties Initialize(context, column, properties); // return the created column return column; }