public override IEnumerator ReceivePayload(VisualPayload payload) { foreach (var entry in ArrayTarget.GetEntries(payload.Data)) { var numberOfInts = NumberOfInts.GetValue(entry); var outMutable = new List <MutableObject>(); for (int i = 0; i < numberOfInts; i++) { outMutable.Add(new MutableObject() { { "Index", i } }); } ArrayTarget.SetValue(outMutable, entry); } var iterator = Router.TransmitAll(payload); while (iterator.MoveNext()) { yield return(null); } }
public override ITarget Fetch(Type type) { if (!type.IsArray) { throw new ArgumentException($"This target container only supports array types - {type} is not an array type"); } var result = base.Fetch(type); if (result != null && !result.UseFallback) { return(result); } // check the array rank - if it's greater than 1, then we can't do anything if (type.GetArrayRank() != 1) { throw new ArgumentException($"Arrays of rank 2 cannot be injected automatically - {type} has a rank of {type.GetArrayRank()}"); } // TODO: see also EnumerableTargetContainer's Fetch method // TODO: look at subclassing a version of this which 'knows' about the // overriding container so that we can get rid of the forking here. if (Root is OverridingTargetContainer overridingContainer) { // if the result = overridingContainer.Parent.Fetch(type); if (!(result is ArrayTarget) && !(result?.UseFallback ?? true)) { return(result); } } return(ArrayTarget.Create(type)); }
public void SetValueOnArray() { var accessor = ReflectionHelper.GetAccessor <ArrayTarget[]>(x => x[1]); var original = new ArrayTarget(); var replacement = new ArrayTarget(); var target = new[] { new ArrayTarget(), original }; accessor.SetValue(target, replacement); target[1].ShouldNotBe(original); target[1].ShouldBe(replacement); }
public void SetValueOnArray() { var accessor = ReflectionHelper.GetAccessor<ArrayTarget[]>(x => x[1]); var original = new ArrayTarget(); var replacement = new ArrayTarget(); var target = new[] {new ArrayTarget(), original }; accessor.SetValue(target, replacement); target[1].ShouldNotBe(original); target[1].ShouldBe(replacement); }
protected override void OnProcessOutputSchema(MutableObject newSchema) { foreach (var entry in ArrayTarget.GetEntries(newSchema)) { var numberOfInts = 1; var outMutable = new List <MutableObject>(); for (int i = 0; i < numberOfInts; i++) { outMutable.Add(new MutableObject() { { "Index", i } }); } ArrayTarget.SetValue(outMutable, entry); } base.OnProcessOutputSchema(newSchema); }