public void InitDefault() { this.Message = new InArgument <string>( new StringExpression() { Elements = { StringLiteral.CreateArgument("The rule is violated.") } }); this.Type = ValidationType.Error; this.Pipe = new InArgument <object>((Activity <object>) new VisualBasicValue <object>(PipeRuleSignature.PipeArgument.Name)); this.Results = new InArgument <ValidationRuleResult>( new VisualBasicValue <ValidationRuleResult>(PipeRuleSignature.ResultArgument.Name)); }
private void ElementCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Only handle the event when single item is appended and it is not the first. if (e.NewItems != null && e.OldItems == null && e.NewItems.Count == 1 && e.NewStartingIndex > 0) { ModelItemCollection elements = ModelItem.Properties["Elements"].Collection; //NOXLATE // The insert position is always at the end when users add new item by clicking on hyperlike "<add text...>" // If the insert position is not the end, it must be 'Replace' operation. It is because ModelItemCollection // does not support 'Replace' operation, the operation is achieved by combination of 'remove' and 'add'. // Therefore you will receive an 'add' event when users are replacing an item. That is not the case we need to handle. if (e.NewStartingIndex == elements.Count - 1) { bool shouldAddSpacer = true; // Add space by default. int previousItemIndex = e.NewStartingIndex - 1; object previousValue = elements[previousItemIndex].GetCurrentValue(); string previousString = GetLiteralString(previousValue); if (previousString != null) { // If the previous item does not end with space, we should add a space. shouldAddSpacer = shouldAddSpacer && !previousString.EndsWith(Space); //NOXLATE } ModelItem modelItem = e.NewItems[0] as ModelItem; if (modelItem != null) { object theValue = modelItem.GetCurrentValue(); string theString = GetLiteralString(theValue); if (theString != null) { // If the newly-added string does start with space, we should add a space. shouldAddSpacer = shouldAddSpacer && !theString.StartsWith(Space); } } if (shouldAddSpacer) //NOXLATE { elements.Insert(e.NewStartingIndex, StringLiteral.CreateArgument(Space)); //NOXLATE } } } }
private bool TryGetDefaultValue(out object defaultValue) { defaultValue = null; ModelProperty property = GetModelProperty(); if (null == property) { return(false); } Type argumentType; if (property.IsCollection) { // Get element type of collection argumentType = property.PropertyType.GetGenericArguments().First <Type>(); } else { argumentType = property.PropertyType; } Type outputType = null; if (argumentType == typeof(InArgument <>)) { outputType = argumentType.GetGenericArguments().First <Type>(); } else if (argumentType.IsGenericType) { if (argumentType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(true); // Nullable<T>'s default value is null. } else { outputType = argumentType.GetGenericArguments().Last <Type>(); } } else if (argumentType == typeof(InArgument)) { // If argument type is InArgument, it means all InArgument<?> are accepted. defaultValue = StringLiteral.CreateArgument("null"); //NOXLATE return(true); } else if (argumentType.IsEnum) { var validValues = argumentType.GetEnumValues(); defaultValue = validValues.GetValue(0); // Enum type's default value is the first item. return(true); } if (outputType != null && outputType.IsValueType) { MethodInfo method = this.GetType().GetMethod("CreateNewValue", BindingFlags.NonPublic | BindingFlags.Instance); // NOXLATE MethodInfo generic = method.MakeGenericMethod(outputType); defaultValue = generic.Invoke(this, null); return(true); } return(false); }
private InArgument CreateNewValueString(string value) { return(StringLiteral.CreateArgument(value)); }