public ValuesFunctionTemplate(ValuesFunction func) { Type = func.Type; switch (func) { case StaticValuesFunction svf: StaticValue = svf.Value; break; case PeriodicValuesFunction pvf: PeriodicOn = pvf.On; PeriodicOff = pvf.Off; PeriodicSkip = pvf.Skip; break; case RepeatingSequenceValuesFunction rsvf: foreach (var part in rsvf.Sequence) { Sequence.Add(new SequencePartTemplate { Value = part.Value, Length = part.Length }); } break; case AggregateValuesFunction avf: AggregateOperation = avf.Operation; foreach (var fn in avf.Functions) { AggregateParts.Add(new ValuesFunctionTemplate(fn)); } break; case ReferenceValuesFunction rvf: Reference = rvf.Reference; break; } }
public ValuesFunction Build() { switch (Type) { case ValuesFunctionType.Static: return(new StaticValuesFunction(StaticValue)); case ValuesFunctionType.Periodic: return(new PeriodicValuesFunction(PeriodicOn, PeriodicOff, PeriodicSkip)); case ValuesFunctionType.RepeatingSequence: return(new RepeatingSequenceValuesFunction(Sequence.Select(x => new SequencePart(x.Value, x.Length)).ToArray())); case ValuesFunctionType.Aggregate: return(new AggregateValuesFunction(AggregateOperation, AggregateParts.Select(x => x.Build()).ToArray())); case ValuesFunctionType.Reference: return(new ReferenceValuesFunction(Reference)); default: throw new Exception("Unknown type"); } }