public ResolvedTraitSet ReplaceTraitParameterValue(ResolveOptions resOpt, string toTrait, string paramName, dynamic valueWhen, dynamic valueNew) { ResolvedTraitSet traitSetResult = this as ResolvedTraitSet; for (int i = 0; i < traitSetResult.Set.Count; i++) { ResolvedTrait rt = traitSetResult.Set[i]; if (rt?.Trait.IsDerivedFrom(toTrait, resOpt) == true) { if (rt.ParameterValues != null) { ParameterCollection pc = rt.ParameterValues.PC; List <dynamic> av = rt.ParameterValues.Values; int idx = pc.FetchParameterIndex(paramName); if (idx >= 0 && Equals(av[idx], valueWhen)) { // copy the set and make a deep copy of the trait being set traitSetResult = this.ShallowCopyWithException(rt.Trait); // assume these are all still true for this copy rt = traitSetResult.Set[i]; av = rt.ParameterValues.Values; av[idx] = ParameterValue.FetchReplacementValue(resOpt, av[idx], valueNew, true); break; } } } } return(traitSetResult); }
public void SetParameterValue(ResolveOptions resOpt, string paramName, dynamic value) { int paramIndex = this.PC.FetchParameterIndex(paramName); this.Values[paramIndex] = ParameterValue.FetchReplacementValue(resOpt, this.Values[paramIndex], value, true); this.WasSet[paramIndex] = true; }
public void SetParameterValueFromArgument(CdmTraitDefinition trait, CdmArgumentDefinition arg) { ResolvedTrait resTrait = this.Get(trait); if (resTrait?.ParameterValues != null) { List <dynamic> av = resTrait.ParameterValues.Values; dynamic newVal = arg.Value; // get the value index from the parameter collection given the parameter that this argument is setting int iParam = resTrait.ParameterValues.IndexOf(arg.GetParameterDef()); av[iParam] = ParameterValue.FetchReplacementValue(this.ResOpt, av[iParam], newVal, true); resTrait.ParameterValues.WasSet[iParam] = true; } }
public ResolvedTraitSet Merge(ResolvedTrait toMerge, bool copyOnWrite) { ResolvedTraitSet traitSetResult = this; var trait = toMerge.Trait; List <dynamic> av = null; List <bool> wasSet = null; if (toMerge.ParameterValues != null) { av = toMerge.ParameterValues.Values; wasSet = toMerge.ParameterValues.WasSet; } if (this.HasElevated != true) { this.HasElevated = trait.Elevated; } if (traitSetResult.LookupByTrait.ContainsKey(trait)) { ResolvedTrait rtOld = traitSetResult.LookupByTrait[trait]; List <dynamic> avOld = null; if (rtOld.ParameterValues != null) { avOld = rtOld.ParameterValues.Values; } if (av != null && avOld != null) { // the new values take precedence for (int i = 0; i < av.Count; i++) { if (avOld[i]?.GetType() == typeof(JValue)) { avOld[i] = (string)avOld[i]; } try { if (av[i] != avOld[i]) { if (copyOnWrite) { traitSetResult = traitSetResult.ShallowCopyWithException(trait); rtOld = traitSetResult.LookupByTrait[trait]; avOld = rtOld.ParameterValues.Values; copyOnWrite = false; } avOld[i] = ParameterValue.FetchReplacementValue(this.ResOpt, avOld[i], av[i], wasSet[i]); } } catch { } } } } else { if (copyOnWrite) { traitSetResult = traitSetResult.ShallowCopy(); } toMerge = toMerge.Copy(); traitSetResult.Set.Add(toMerge); traitSetResult.LookupByTrait.Add(trait, toMerge); } return(traitSetResult); }
public void SetValue(ResolveOptions resOpt, dynamic newValue) { this.Value = ParameterValue.FetchReplacementValue(resOpt, this.Value, newValue, true); }