System.Action.Invoke(T)

Here are the examples of the csharp api System.Action.Invoke(T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2067 Examples 7

19 View Source File : CollectionExtension.cs
License : MIT License
Project Creator : 3F

public static IEnumerable<T> ForEach<T>(this IEnumerable<T> items, Action<T> act)
        {
            return items?.ForEach((x, i) => act(x));
        }

19 View Source File : ObjectExtension.cs
License : MIT License
Project Creator : 3F

public static T E<T>(this T obj, Action<T> act)
        {
            act?.Invoke(obj);
            return obj;
        }

19 View Source File : ViewModelBinding.cs
License : MIT License
Project Creator : 404Lcc

public void Bind(T viewModel)
        {
            if (viewModel != null)
            {
                for (int i = 0; i < viewModelBindingList.Count; i++)
                {
                    viewModelBindingList[i](viewModel);
                }
            }
        }

19 View Source File : ViewModelBinding.cs
License : MIT License
Project Creator : 404Lcc

public void UnBind(T viewModel)
        {
            if (viewModel != null)
            {
                for (int i = 0; i < unViewModelBindingList.Count; i++)
                {
                    unViewModelBindingList[i](viewModel);
                }
            }
        }

19 View Source File : Utility.Enum.cs
License : MIT License
Project Creator : 7Bytes-Studio

public static void Foreach<T>(Action<T> foreachCallback) where T : struct, IComparable, IFormattable, IConvertible
            {
                var arr =  System.Enum.GetValues(typeof(T));
                foreach (T item in arr)
                {
                    if (null != foreachCallback)
                    {
                        foreachCallback.Invoke(item);
                    }
                }
            }

19 View Source File : Act.cs
License : MIT License
Project Creator : 8T4

public Act<T> It(Action<T> action)
        {
            action.Invoke(Value);
            return this;
        }

19 View Source File : Arrange.cs
License : MIT License
Project Creator : 8T4

public Arrange<T> Setup(Action<T> action)
        {
            action.Invoke(Value);
            return this;
        }

19 View Source File : Assert.cs
License : MIT License
Project Creator : 8T4

public replacedert<T> Expect(Action<T> action)
        {
            action.Invoke(Value);
            return this;
        }

19 View Source File : RtmpMessageStream.cs
License : MIT License
Project Creator : a1q123456

internal void RegisterMessageHandler<T>(Action<T> handler) where T: Message
        {
            var attr = typeof(T).GetCustomAttribute<RtmpMessageAttribute>();
            if (attr == null || !attr.MessageTypes.Any())
            {
                throw new InvalidOperationException("unsupported message type");
            }
            foreach (var messageType in attr.MessageTypes)
            {
                if (_messageHandlers.ContainsKey(messageType))
                {
                    throw new InvalidOperationException("message type already registered");
                }
                _messageHandlers[messageType] = m =>
                {
                    handler(m as T);
                };
            }
        }

19 View Source File : ObserveAddRemoveCollection.cs
License : MIT License
Project Creator : Abdesol

protected override void ClearItems()
		{
			if (onRemove != null) {
				foreach (T val in this)
					onRemove(val);
			}
			base.ClearItems();
		}

19 View Source File : ObserveAddRemoveCollection.cs
License : MIT License
Project Creator : Abdesol

protected override void Inserreplacedem(int index, T item)
		{
			if (onAdd != null)
				onAdd(item);
			base.Inserreplacedem(index, item);
		}

19 View Source File : ObserveAddRemoveCollection.cs
License : MIT License
Project Creator : Abdesol

protected override void RemoveItem(int index)
		{
			if (onRemove != null)
				onRemove(this[index]);
			base.RemoveItem(index);
		}

19 View Source File : ObserveAddRemoveCollection.cs
License : MIT License
Project Creator : Abdesol

protected override void Sereplacedem(int index, T item)
		{
			if (onRemove != null)
				onRemove(this[index]);
			try {
				if (onAdd != null)
					onAdd(item);
			} catch {
				// When adding the new item fails, just remove the old one
				// (we cannot keep the old item since we already successfully called onRemove for it)
				base.RemoveAt(index);
				throw;
			}
			base.Sereplacedem(index, item);
		}

19 View Source File : TaskHelpers.cs
License : MIT License
Project Creator : abdullin

public static async Task Then<T>(this Task<T> task, [NotNull] Action<T> inlineContinuation)
		{
			// Note: we use 'await' instead of ContinueWith, so that we can give the caller a nicer callstack in case of errors (instead of an AggregateExecption)

			var value = await task.ConfigureAwait(false);
			inlineContinuation(value);
		}

19 View Source File : GameObjectExtensions.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void ForEachComponent<T>(this GameObject gameObject, Action<T> action)
        {
            foreach (T i in gameObject.GetComponents<T>())
            {
                action(i);
            }
        }

19 View Source File : LazyTreeNode.cs
License : MIT License
Project Creator : Accelerider

private static async Task ForEachAsync(ILazyTreeNode<T> node, Action<T> callback, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested) return;
            if (node == null) return;

            callback?.Invoke(node.Content);
            await node.RefreshAsync();

            if (node.ChildrenCache == null) return;
            foreach (var child in node.ChildrenCache)
            {
                if (cancellationToken.IsCancellationRequested) return;
                await ForEachAsync(child, callback, cancellationToken);
            }
        }

19 View Source File : RelayCommand{T}.cs
License : MIT License
Project Creator : Accelerider

public void Execute(T parameter)
        {
            _execute?.Invoke(parameter);
        }

19 View Source File : DataContext.cs
License : MIT License
Project Creator : Accelerider

public void Export<T>(Expression<Func<T>> propertyExpression, string key = null)
        {
            key = key ?? PropertySupport.ExtractPropertyName(propertyExpression);

            if (_exportPropertyGetterDictionary.ContainsKey(key))
                throw new ArgumentException(string.Format(Resources.DataContext_ExportHasBeenExported_Exception, propertyExpression), nameof(propertyExpression));

            var getter = propertyExpression.Compile();

            _exportPropertyGetterDictionary[key] = getter;

            PropertyObserver.Observes(propertyExpression, () =>
            {
                if (!_importPropertySetterDictionary.TryGetValue(key, out var setterDelegates)) return;

                foreach (var setterDelegate in setterDelegates)
                {
                    var setter = (Action<T>)setterDelegate;
                    setter(getter());
                }
            });
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : Accelerider

public static void ForEach<T>(this IEnumerable<T> @this, Action<T> callback, bool immutable = false)
        {
            Guards.ThrowIfNull(@this, callback);

            var collection = immutable ? @this.ToArray() : @this;

            foreach (T item in collection)
            {
                callback(item);
            }
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : Accelerider

public static IEnumerable<T> Do<T>(this IEnumerable<T> @this, Action<T> callback)
        {
            Guards.ThrowIfNull(@this, callback);

            foreach (var item in @this)
            {
                callback?.Invoke(item);
                yield return item;
            }
        }

19 View Source File : Extensions.cs
License : MIT License
Project Creator : Accelerider

public static void ForEach<T>(this IEnumerable<T> @this, Action<T> callback)
        {
            foreach (var item in @this)
            {
                callback?.Invoke(item);
            }
        }

19 View Source File : LazyTreeNodeExtensions.cs
License : MIT License
Project Creator : Accelerider

private async Task FlourishAsync(ILazyTreeNode<T> seed) // TODO: Tail recursion / CPS
            {
                _action?.Invoke(seed.Content);
                if (await seed.RefreshAsync() && seed.ChildrenCache != null)
                {
                    foreach (var item in seed.ChildrenCache)
                    {
                        await FlourishAsync(item);
                    }
                }
            }

19 View Source File : ProjectFile.cs
License : MIT License
Project Creator : action-bi-toolkit

private void WriteFile<T>(Func<string, T> factory, Action<T> callback) where T : IDisposable
        {
            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path));

            Log.Verbose("Writing file: {Path}", Path);
            using (var writer = factory(Path))
            {
                callback(writer);
            }

            _root.FileWritten(Path); // keeps track of files added or updated
        }

19 View Source File : ProjectFolder.cs
License : MIT License
Project Creator : action-bi-toolkit

private void WriteFile<T>(string path, Func<string, T> factory, Action<T> callback) where T : IDisposable
        {
            var fullPath = GetFullPath(path);
            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

            if (Directory.Exists(fullPath))
            {
                Log.Verbose("Deleting directory at: {Path} as it conflicts with a new file to be created at the same location.", fullPath);
                Directory.Delete(fullPath, recursive: true);
            }

            Log.Verbose("Writing file: {Path}", fullPath);
            using (var writer = factory(fullPath))
            {
                callback(writer);
            }

            _root.FileWritten(fullPath); // keeps track of files added or updated
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : actions

public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
        {
            ArgumentUtility.CheckForNull(action, nameof(action));
            ArgumentUtility.CheckForNull(collection, nameof(collection));

            foreach (T item in collection)
            {
                action(item);
            }
        }

19 View Source File : EnumerableExtensions.cs
License : GNU General Public License v3.0
Project Creator : Acumatica

[DebuggerStepThrough]
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
		{
			source.ThrowOnNull(nameof(source));
			action.ThrowOnNull(nameof(action));

			// perf optimization. try to not use enumerator if possible
			switch (source)
			{
				case IList<T> iList:
					for (int i = 0; i < iList.Count; i++)
					{
						action(iList[i]);
					}

					return;
				default:
					foreach (var value in source)
					{
						action(value);
					}

					return;
			}
		}

19 View Source File : ObservableList.cs
License : MIT License
Project Creator : Adam4lexander

public void Insert(int index, T value) {
            m_list.Insert(index, value);
            syncToPrevList();
            ItemAdded?.Invoke(value);
            OnChanged?.Invoke();
        }

19 View Source File : ObservableList.cs
License : MIT License
Project Creator : Adam4lexander

public void RemoveAt(int index) {
            var item = m_list[index];
            m_list.RemoveAt(index);
            syncToPrevList();
            ItemRemoved?.Invoke(item);
            OnChanged?.Invoke();
        }

19 View Source File : ObservableList.cs
License : MIT License
Project Creator : Adam4lexander

public void Add(T item) {
            m_list.Add(item);
            syncToPrevList();
            ItemAdded?.Invoke(item);
            OnChanged?.Invoke();
        }

19 View Source File : ObservableList.cs
License : MIT License
Project Creator : Adam4lexander

public void Clear() {
            tempList.Clear();
            tempList.AddRange(m_list);
            m_list.Clear();
            foreach (var item in tempList) {
                ItemRemoved?.Invoke(item);
            }
            syncToPrevList();
            OnChanged?.Invoke();
            tempList.Clear();
        }

19 View Source File : ObservableList.cs
License : MIT License
Project Creator : Adam4lexander

public bool Remove(T item) {
            var isRemoved = m_list.Remove(item);
            if (isRemoved) {
                syncToPrevList();
                ItemRemoved?.Invoke(item);
                OnChanged?.Invoke();
            }
            return isRemoved;
        }

19 View Source File : IObservable.Fuse.cs
License : MIT License
Project Creator : AdamRamberg

public void OnNext(T value)
        {
            LastValue = value;
            _onNext(value);
        }

19 View Source File : ActionExtensions.cs
License : Apache License 2.0
Project Creator : adamralph

public static Func<T, Task> ToAsync<T>(this Action<T> action) => obj => Task.Run(() => action.Invoke(obj));

19 View Source File : ConfigureWritable.cs
License : MIT License
Project Creator : ADefWebserver

public void Update(Action<T> applyChanges)
        {
            var fileProvider = _environment.ContentRootFileProvider;
            var fileInfo = fileProvider.GetFileInfo(_file);
            var physicalPath = fileInfo.PhysicalPath;

            var jObject = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(physicalPath));
            var sectionObject = jObject.TryGetValue(_section, out JToken section) ?
                JsonConvert.DeserializeObject<T>(section.ToString()) : (Value ?? new T());

            applyChanges(sectionObject);

            jObject[_section] = JObject.Parse(JsonConvert.SerializeObject(sectionObject));
            File.WriteAllText(physicalPath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
        }

19 View Source File : RazorEngineCompiledTemplateT.cs
License : MIT License
Project Creator : adoconnection

public async Task<string> RunAsync(Action<T> initializer)
        {
            T instance = (T) Activator.CreateInstance(this.templateType);
            initializer(instance);

            await instance.ExecuteAsync();

            return await instance.ResultAsync();
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

public static T When<T>(this T node, bool flag, Action<T> actionToApplyWhenFlagIsTrue) where T : VisualNode
        {
            if (flag)
            {
                actionToApplyWhenFlagIsTrue(node);
            }
            return node;
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

internal override void MergeWith(VisualNode newNode)
        {
            if (newNode.GetType() == GetType())
            {
                ((VisualNode<T>)newNode)._nativeControl = this._nativeControl;
                ((VisualNode<T>)newNode)._isMounted = this._nativeControl != null;
                ((VisualNode<T>)newNode)._componentRefAction?.Invoke(NativeControl);
                OnMigrated(newNode);

                base.MergeWith(newNode);
            }
            else
            {
                this.Unmount();
            }
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

protected override void OnUnmount()
        {
            if (_nativeControl != null)
            {
                _nativeControl.PropertyChanged -= NativeControl_PropertyChanged;
                _nativeControl.PropertyChanging -= NativeControl_PropertyChanging;
                Parent?.RemoveChild(this, _nativeControl);

                if (_nativeControl is Element element)
                {
                    if (element.Parent != null)
                    {
#if DEBUG
                        //throw new InvalidOperationException();
#endif
                    }
                }

                _nativeControl = null;
                _componentRefAction?.Invoke(null);
            }

            base.OnUnmount();
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

public void AppendAnimatable<T>(object key, T animation, Action<T> action) where T : RxAnimation
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (animation is null)
            {
                throw new ArgumentNullException(nameof(animation));
            }

            if (action is null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var newAnimatableProperty = new Animatable(key, animation, new Action<RxAnimation>(target => action((T)target)));

            _animatables[key] = newAnimatableProperty;
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

protected override void OnMount()
        {
            _nativeControl = _nativeControl ?? new T();
            Parent?.AddChild(this, _nativeControl);
            _componentRefAction?.Invoke(NativeControl);

            base.OnMount();
        }

19 View Source File : Extensions.cs
License : MIT License
Project Creator : adyanth

public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
        {
            foreach (var item in enumeration)
                action(item);
        }

19 View Source File : ObjectPool.cs
License : Apache License 2.0
Project Creator : advancer68

public virtual void Return(T item)
        {
            if (m_resetFunc != null)
            {
                m_resetFunc(item);
            }
            getQue.Enqueue(item);
        }

19 View Source File : QueueSync.cs
License : Apache License 2.0
Project Creator : advancer68

public void DequeueAll(Action<T> func)
    {
        if (func == null)
        {
            return;
        }
        Switch();
        while (outQue.Count > 0)
        {
            T it = outQue.Dequeue();
            func(it);
        }
    }

19 View Source File : ResourcePool.cs
License : The Unlicense
Project Creator : aeroson

protected T CreateNewResource()
        {
            var toReturn = new T();
            if (InstanceInitializer != null)
                InstanceInitializer(toReturn);
            return toReturn;
        }

19 View Source File : RelayCommand.cs
License : MIT License
Project Creator : afxw

public void Execute(object parameter)
        {
            _execute((T)parameter);
        }

19 View Source File : CollectionEx.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public static void Foreach<T>(this IEnumerable<T> em, Action<T> action, bool keepNull = true)
        {
            if (em == null)
                return;
            if (keepNull)
            {
                foreach (var t in em.Where(p => !Equals(p, default(T))))
                {
                    action(t);
                }
            }
            else
            {
                foreach (var t in em)
                {
                    action(t);
                }
            }
        }

19 View Source File : CSVConvert.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public static int Import<T>(string csv, Action<T, string, string> setValue, Action<T> rowEnd) where T : clreplaced, new()
        {
            int cnt = 0;
            var lines = Split(csv);
            if (lines.Count <= 1)
                return 0;

            var colunms = new List<string>();
            foreach (var field in lines[0])
                colunms.Add(field.Trim().MulitReplace2("", " ", " ", "\t"));
            for (var i = 1; i < lines.Count; i++)
            {
                var tv = new T();
                var vl = lines[i];
                for (var cl = 0; cl < vl.Count; cl++)
                    setValue(tv, colunms[cl], vl[cl]);
                rowEnd(tv);
                cnt++;
            }

            return cnt;
        }

19 View Source File : TsonSerializer.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public void Write<T>(List<T> array, TsonDataType type, Action<T> write)
        {
            if (array == null || array.Count == 0)
            {
                WriteType(TsonDataType.Nil);
                return;
            }

            WriteType(TsonDataType.Array);
            WriteType(type);
            WriteLen(array.Count);
            foreach (var item in array)
                write(item);
        }

19 View Source File : TsonSerializer.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public void Write<T>(T[] array, TsonDataType type, Action<T> write)
        {
            if (array == null || array.Length == 0)
            {
                WriteType(TsonDataType.Nil);
                return;
            }

            WriteType(TsonDataType.Array);
            WriteType(type);
            WriteLen(array.Length);
            foreach (var item in array)
                write(item);
        }

19 View Source File : TsonSerializerV1.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public void Write<T>(List<T> array, TsonDataType type, Action<T> write)
        {
            if (array == null || array.Count == 0)
            {
                //WriteType(TsonFieldType.Nil);
                return;
            }

            //WriteType(TsonFieldType.Array);
            //WriteType(type);
            WriteLen(array.Count);
            foreach (var item in array)
                write(item);
        }

See More Examples