/// <summary> /// Where /// </summary> /// <param name="queue"></param> /// <param name="predicate"></param> /// <param name="capacity"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IQueueSource <T> Where <T>(this IQueueSource <T> queue, Func <T, Task <bool> > predicate, int?capacity = null) { AsyncQueue <T> outQueue = new AsyncQueue <T>(capacity ?? 2); Func <Task> worker = async delegate { while (true) { IOptional <T> item = await queue.Dequeue(CancellationToken.None); if (!item.HasValue) { break; } if (await predicate(item.Value)) { await outQueue.Enqueue(item.Value, CancellationToken.None); } } outQueue.WriteEof(); }; Task _dummy = Task.Run(worker); return(outQueue); }
/// <summary> /// Select /// </summary> /// <param name="queue"></param> /// <param name="func"></param> /// <param name="capacity"></param> /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <returns></returns> public static IQueueSource <U> Select <T, U>(this IQueueSource <T> queue, Func <T, Task <U> > func, int?capacity = null) { AsyncQueue <U> outQueue = new AsyncQueue <U>(capacity ?? 2); Func <Task> worker = async delegate { while (true) { IOptional <T> item = await queue.Dequeue(CancellationToken.None); if (!item.HasValue) { break; } U item2 = await func(item.Value); await outQueue.Enqueue(item2, CancellationToken.None); } outQueue.WriteEof(); }; Task.Run(worker); return(outQueue); }
private void SetVisibility() { if (string.IsNullOrWhiteSpace(PropertyBinding)) { return; } Type metadata = Owner.SyntaxNode.GetType(); PropertyInfo property = metadata.GetProperty(PropertyBinding); if (property == null) { return; } if (property.IsOptional()) { IOptional optional = (IOptional)property.GetValue(Owner.SyntaxNode); IsVisible = optional.HasValue; IsTemporallyVisible = false; ResetHideOptionFlag = false; } else { IsVisible = true; IsTemporallyVisible = false; ResetHideOptionFlag = false; } }
/// <summary> /// propertyName parameter must be of type generic list /// </summary> public ISyntaxNode Create(ISyntaxNode concept, string propertyName, Type child) { ISyntaxNode item = (ISyntaxNode)Activator.CreateInstance(child); item.Parent = concept; IList list; PropertyInfo property = concept.GetType().GetProperty(propertyName); if (property.IsOptional()) { IOptional optional = (IOptional)property.GetValue(concept); list = (IList)optional.Value; if (list == null) { Type listType = property.PropertyType.GetProperty("Value").PropertyType; list = (IList)Activator.CreateInstance(listType); optional.Value = list; } } else { list = (IList)property.GetValue(concept); if (list == null) { Type listType = property.PropertyType; list = (IList)Activator.CreateInstance(listType); property.SetValue(concept, list); } } list.Add(item); return(item); }
public void ForCharacteraandStringEmptyStringShouldReturnEmptyString() { var a = new IOptional(new Character('a')); IMatch actual = a.Match(string.Empty); Assert.Equal(string.Empty, actual.RemainingText()); }
private ISyntaxNode GetConceptFromPropertyBinding(ISyntaxNodeViewModel conceptViewModel) { if (conceptViewModel.Owner == null) { return(conceptViewModel.SyntaxNode); // it is syntax tree root node } ISyntaxNodeViewModel parentNode = conceptViewModel.Owner; string propertyBinding = conceptViewModel.PropertyBinding; ISyntaxNode parentConcept = parentNode.SyntaxNode; PropertyInfo property = parentConcept.GetPropertyInfo(propertyBinding); IOptional optional = null; if (property.IsOptional()) { optional = (IOptional)property.GetValue(parentConcept); } ISyntaxNode concept = null; if (optional == null) { concept = (ISyntaxNode)property.GetValue(parentConcept); } else if (optional.HasValue) { concept = (ISyntaxNode)optional.Value; } return(concept); }
public void ForCharacterMinusandStringMinus123ShouldReturn123() { var a = new IOptional(new Character('-')); IMatch actual = a.Match("-123"); Assert.Equal("123", actual.RemainingText()); }
public void ForCharacteraandStringbcShouldReturnbc() { var a = new IOptional(new Character('a')); IMatch actual = a.Match("bc"); Assert.Equal("bc", actual.RemainingText()); }
public void ForCharacterAAndStringAbcShouldReturnTrue() { IOptional a = new IOptional(new Character('a')); IMatch actual = a.Match(Text); Assert.True(actual.Succes()); }
/** * Creates a new Optional as a blank node in a given Model. * @param model the Model to create the OPTIONAL in * @param elements the elements of the OPTIONAL * @return a new Optional */ public static IOptional createOptional(SpinProcessor model, IElementList elements) { IOptional optional = (IOptional)model.CreateResource(SP.ClassOptional).As(typeof(OptionalImpl)); optional.AddProperty(SP.PropertyElements, elements); return(optional); }
public static ISyntaxNode CreateRepeatableConcept(Type repeatable, ISyntaxNode parent, string propertyName) { ISyntaxNode concept = (ISyntaxNode)Activator.CreateInstance(repeatable); concept.Parent = parent; IList list; PropertyInfo property = parent.GetPropertyInfo(propertyName); if (property.IsOptional()) { IOptional optional = (IOptional)property.GetValue(parent); list = (IList)optional.Value; if (list == null) { Type listType = property.PropertyType.GetProperty("Value").PropertyType; list = (IList)Activator.CreateInstance(listType); optional.Value = list; } } else { list = (IList)property.GetValue(parent); if (list == null) { Type listType = property.PropertyType; list = (IList)Activator.CreateInstance(listType); property.SetValue(parent, list); } } list.Add(concept); return(concept); }
public void RemoveOption(string propertyName) { if (string.IsNullOrWhiteSpace(propertyName)) { return; } PropertyInfo property = SyntaxNode.GetPropertyInfo(propertyName); if (!property.IsOptional()) { return; } IOptional optional = (IOptional)property.GetValue(SyntaxNode); if (!optional.HasValue) { return; } optional.HasValue = false; var nodes = this.GetNodesByPropertyName(propertyName); foreach (var node in nodes) { node.IsVisible = false; } }
public GenericModConfigMenuSetup( IModHelper helper, IManifest manifest, IOptional <IGenericModConfigMenuApi> configApiFactory, HudConfig hudConfig, ConfigManager <HudConfig> hudConfigManager, FishConfig fishConfig, ConfigManager <FishConfig> fishConfigManager, TreasureConfig treasureConfig, ConfigManager <TreasureConfig> treasureConfigManager ) { this.helper = helper ?? throw new ArgumentNullException(nameof(helper)); this.manifest = manifest ?? throw new ArgumentNullException(nameof(manifest)); this.configApi = configApiFactory ?? throw new ArgumentNullException(nameof(configApiFactory)); this.hudConfig = hudConfig ?? throw new ArgumentNullException(nameof(hudConfig)); this.hudConfigManager = hudConfigManager ?? throw new ArgumentNullException(nameof(hudConfigManager)); this.fishConfig = fishConfig ?? throw new ArgumentNullException(nameof(fishConfig)); this.fishConfigManager = fishConfigManager ?? throw new ArgumentNullException(nameof(fishConfigManager)); this.treasureConfig = treasureConfig ?? throw new ArgumentNullException(nameof(treasureConfig)); this.treasureConfigManager = treasureConfigManager ?? throw new ArgumentNullException(nameof(treasureConfigManager)); }
public void ForCharacteraandStringnullShouldReturnTrue() { var a = new IOptional(new Character('a')); IMatch actual = a.Match(null); Assert.True(actual.Succes()); }
public void ForCharacteraandStringnullShouldReturnnull() { var a = new IOptional(new Character('a')); IMatch actual = a.Match(null); Assert.Null(actual.RemainingText()); }
public void ForCharacterMinusandString123ShouldReturntrue() { var sign = new IOptional(new Character('-')); IMatch actual = sign.Match("123"); Assert.True(actual.Succes()); }
public override bool Equals(object obj) { return(obj switch { IOptional <TValue> optional => Equals(optional), TValue value => Equals(value), _ => Equals(this, obj) });
public IPosition GetInterpolatedFrame( float frame, IOptional <float[]>?defaultAxes = null, bool useLoopingInterpolation = false) => this.impl_.GetInterpolatedFrame( frame, defaultAxes, useLoopingInterpolation);
public IOptional <TReject> TryResolveAndReject(IDependencyResolver resolver, TTarget target) { IOptional <TResolvableValue> resolvedValue = TryResolve(resolver); return(resolvedValue.HasValue ? Reject(target, resolvedValue.Value) : Optional <TReject> .NoValue); }
/// <summary> /// Registration. /// </summary> /// <param name="registration"></param> /// <param name="instance"></param> public RegistrationProcess(Registration registration, object instance) { Argument.NotNull(nameof(registration), registration); Argument.NotNull(nameof(instance), instance); Registration = registration; Instance = new Optional <object>(instance); }
/// <summary> /// Constructor. /// </summary> /// <param name="name">Name.</param> /// <param name="resolution">Resolution.</param> public ParameterInjection(string name, Resolution resolution) { Argument.NotNull(nameof(name), name); Argument.NotNull(nameof(resolution), resolution); Name = name; Resolution = new Optional <Resolution>(resolution); }
public static Option<T> TryCast<T>(this IOptional option) where T : class { return option .MatchUntyped( x => x is T t ? t : default(Option<T>), () => default);
public ItemAttributes RemoveItemInHand() { AssertItemInHand(); var returnItem = this.itemInHand.GetValue(); this.itemInHand = Optional.None <ItemAttributes>("Removed item in hand to place in inventory"); Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); return(returnItem); }
/// <summary> /// Value or throw /// </summary> /// <param name="optional"></param> /// <typeparam name="T"></typeparam> /// <typeparam name="TException"></typeparam> /// <returns></returns> public static T ValueOrThrow <T, TException>(this IOptional <T, TException> optional) where TException : Exception { if (optional.HasValue) { return(optional.Value); } throw optional.Exception; }
public DialogBase() { InitializeComponent(); this.optional = this as IOptional; this.StartPosition = FormStartPosition.CenterParent; this.MinimumSize = this.Size; }
/// <summary> /// Constructor. /// </summary> /// <param name="interfaceType"></param> /// <param name="name"></param> /// <param name="injections"></param> public Resolution( Type interfaceType, string name = null, Injections injections = null) { Argument.NotNull(nameof(interfaceType), interfaceType); InterfaceType = interfaceType; Name = new Optional <string>(name); Injections = new Optional <Injections>(injections); }
public bool TryResolveAndInject(IDependencyResolver resolver, TTarget target) { IOptional <TResolvableValue> resolvedValue = TryResolve(resolver); if (!resolvedValue.HasValue) { return(false); } Inject(target, resolvedValue.Value); return(true); }
public bool TryResolve(IDependencyResolver resolver, out object value) { IOptional <TValue> resolvedValue = TryResolve(resolver); if (resolvedValue.HasValue) { value = resolvedValue.Value; return(true); } value = null; return(false); }
private void WriteOption(Utf8JsonWriter writer, DummyAssembly source, PropertyInfo info, JsonSerializerOptions options) { writer.WritePropertyName(info.Name); writer.WriteStartObject(); IOptional optional = (IOptional)info.GetValue(source); writer.WriteBoolean("HasValue", optional.HasValue); if (!optional.HasValue) { writer.WriteNull("Value"); writer.WriteEndObject(); return; } object value = optional.Value; Type propertyType = info.PropertyType.GetGenericArguments()[0]; writer.WritePropertyName("Value"); if (value == null) { JsonSerializer.Serialize(writer, value, propertyType); } else if (info.IsRepeatable()) { WriteArray(writer, (IEnumerable)value, options); } else if (value is DummyAssembly) { Write(writer, (DummyAssembly)value, options); } else if (value is Assembly) { JsonSerializer.Serialize(writer, ((Assembly)value).FullName, typeof(string)); } else if (value is Type) { JsonSerializer.Serialize(writer, ((Type)value).AssemblyQualifiedName, typeof(string)); } else { JsonSerializer.Serialize(writer, value, value.GetType()); } writer.WriteEndObject(); }
private void CancelAcquireWrite(long id) { lock (syncRoot) { IOptional <WaitingWrite> opt = waitingWrites.Cancel(id); if (opt.HasValue) { opt.Value.k.PostResult(new AcquireWriteCancelled()); if (opt.Value.ctr.HasValue) { opt.Value.ctr.Value.PostDispose(); } } } }