public StringSubstitutor(IHasLookup repo = null) { if (repo != null) { ReferenceDataRepository = repo; } }
/// <summary> /// Given a expression like ${var:xxxx}, sees if the data structure named xxxx is in the reference data repository /// </summary> /// <param name="reference">The name of the reference data</param> /// <param name="repo">The repository to search through</param> /// <returns>The object that is in the repo</returns> public object Resolve(string reference, IHasLookup repo) { // The reference can be ${var:USStates} Regex regex = new Regex(@"^\${var:(?<varname>\w+)}$"); var match = regex.Match(reference); if (match.Success) { string varname = match.Groups["varname"].Value; // Get the collection from the reference data repo return(repo?.Get(varname)); } return(null); }
protected override void InitializeData(FormTemplateFieldDefinition fieldDef, object data = null, IHasLookup referenceDataRepo = null) { this.GroupName = this.GetProp <string>("groupname") ?? IdGenerators.FieldId(); this.EndingFieldName = this.GetProp <string>("end"); this.FieldInstanceSuffix = this.GetProp <string>("suffix") ?? "${index}"; this.ContinueLoopValue = this.GetProp("continuevalue") ?? true; base.InitializeData(fieldDef, data, referenceDataRepo); }
protected override void InitializeData(FormTemplateFieldDefinition fieldDef, object data = null, IHasLookup referenceDataRepo = null) { base.InitializeData(fieldDef, data, referenceDataRepo); if (data != null) { return; } if (fieldDef.Items != null && fieldDef.Items.Count > 0) { this.CopyCollection(this.Items, fieldDef.Items); return; } if (string.IsNullOrEmpty(fieldDef.Reference)) { return; } // Get the collection from the reference data repo IReferenceDataResolver referenceDataResolver = new ReferenceDataResolver(); object collection = referenceDataResolver.Resolve(fieldDef.Reference, referenceDataRepo); this.CopyCollection(this.Items, collection); }