public void Combine(VariableRegistry otherRegistry, bool removeMissing = false) { //Below doesn't work for added variables Dictionary <string, VariableRegistryItem> vars = new Dictionary <string, VariableRegistryItem>(); foreach (var variable in otherRegistry._variables) { if (removeMissing) { VariableRegistryItem local = _variables.ContainsKey(variable.Key) ? _variables[variable.Key] : null; if (local != null) { local.Merge(variable.Value); } else { local = variable.Value; } vars.Add(variable.Key, local); } else { Register(variable.Key, variable.Value); } } if (removeMissing) { _variables = vars; } }
public void Register(string name, VariableRegistryItem varItem) { if (!_variables.ContainsKey(name)) { _variables.Add(name, varItem); } else { _variables[name].Merge(varItem); } }
internal void Merge(VariableRegistryItem variableRegistryItem) { this.Default = variableRegistryItem.Default; this.Title = variableRegistryItem.Title; this.Remark = variableRegistryItem.Remark; this.Min = variableRegistryItem.Min; this.Max = variableRegistryItem.Max; if (this.Value == null || variableRegistryItem.Default.GetType() != this.Value.GetType()) { this.Value = variableRegistryItem.Default; } }
internal void Merge(VariableRegistryItem variableRegistryItem) { this.Default = variableRegistryItem.Default; this.Title = variableRegistryItem.Title; this.Remark = variableRegistryItem.Remark; this.Min = variableRegistryItem.Min; this.Max = variableRegistryItem.Max; Type typ = this.Value.GetType(); Type defaultType = variableRegistryItem.Default.GetType(); if (!defaultType.Equals(typ) && this.Value.GetType().Equals(typeof(long)) && TypeUtils.IsNumericType(defaultType)) { this.Value = Convert.ChangeType(this.Value, defaultType); } else if (this.Value == null && !defaultType.Equals(typ)) { this.Value = variableRegistryItem.Default; } }