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
19
Source : CollectionExtension.cs
with MIT License
from 3F
with MIT License
from 3F
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> items, Action<T> act)
{
return items?.ForEach((x, i) => act(x));
}
19
Source : ObjectExtension.cs
with MIT License
from 3F
with MIT License
from 3F
public static T E<T>(this T obj, Action<T> act)
{
act?.Invoke(obj);
return obj;
}
19
Source : ViewModelBinding.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public void Bind(T viewModel)
{
if (viewModel != null)
{
for (int i = 0; i < viewModelBindingList.Count; i++)
{
viewModelBindingList[i](viewModel);
}
}
}
19
Source : ViewModelBinding.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public void UnBind(T viewModel)
{
if (viewModel != null)
{
for (int i = 0; i < unViewModelBindingList.Count; i++)
{
unViewModelBindingList[i](viewModel);
}
}
}
19
Source : Utility.Enum.cs
with MIT License
from 7Bytes-Studio
with MIT License
from 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
Source : Act.cs
with MIT License
from 8T4
with MIT License
from 8T4
public Act<T> It(Action<T> action)
{
action.Invoke(Value);
return this;
}
19
Source : Arrange.cs
with MIT License
from 8T4
with MIT License
from 8T4
public Arrange<T> Setup(Action<T> action)
{
action.Invoke(Value);
return this;
}
19
Source : Assert.cs
with MIT License
from 8T4
with MIT License
from 8T4
public replacedert<T> Expect(Action<T> action)
{
action.Invoke(Value);
return this;
}
19
Source : RtmpMessageStream.cs
with MIT License
from a1q123456
with MIT License
from 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
Source : ObserveAddRemoveCollection.cs
with MIT License
from Abdesol
with MIT License
from Abdesol
protected override void ClearItems()
{
if (onRemove != null) {
foreach (T val in this)
onRemove(val);
}
base.ClearItems();
}
19
Source : ObserveAddRemoveCollection.cs
with MIT License
from Abdesol
with MIT License
from Abdesol
protected override void Inserreplacedem(int index, T item)
{
if (onAdd != null)
onAdd(item);
base.Inserreplacedem(index, item);
}
19
Source : ObserveAddRemoveCollection.cs
with MIT License
from Abdesol
with MIT License
from Abdesol
protected override void RemoveItem(int index)
{
if (onRemove != null)
onRemove(this[index]);
base.RemoveItem(index);
}
19
Source : ObserveAddRemoveCollection.cs
with MIT License
from Abdesol
with MIT License
from 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
Source : TaskHelpers.cs
with MIT License
from abdullin
with MIT License
from 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
Source : GameObjectExtensions.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public static void ForEachComponent<T>(this GameObject gameObject, Action<T> action)
{
foreach (T i in gameObject.GetComponents<T>())
{
action(i);
}
}
19
Source : LazyTreeNode.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : RelayCommand{T}.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public void Execute(T parameter)
{
_execute?.Invoke(parameter);
}
19
Source : DataContext.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : EnumerableExtensions.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : EnumerableExtensions.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : Extensions.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public static void ForEach<T>(this IEnumerable<T> @this, Action<T> callback)
{
foreach (var item in @this)
{
callback?.Invoke(item);
}
}
19
Source : LazyTreeNodeExtensions.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : ProjectFile.cs
with MIT License
from action-bi-toolkit
with MIT License
from 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
Source : ProjectFolder.cs
with MIT License
from action-bi-toolkit
with MIT License
from 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
Source : EnumerableExtensions.cs
with MIT License
from actions
with MIT License
from 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
Source : EnumerableExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from 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
Source : ObservableList.cs
with MIT License
from Adam4lexander
with MIT License
from Adam4lexander
public void Insert(int index, T value) {
m_list.Insert(index, value);
syncToPrevList();
ItemAdded?.Invoke(value);
OnChanged?.Invoke();
}
19
Source : ObservableList.cs
with MIT License
from Adam4lexander
with MIT License
from Adam4lexander
public void RemoveAt(int index) {
var item = m_list[index];
m_list.RemoveAt(index);
syncToPrevList();
ItemRemoved?.Invoke(item);
OnChanged?.Invoke();
}
19
Source : ObservableList.cs
with MIT License
from Adam4lexander
with MIT License
from Adam4lexander
public void Add(T item) {
m_list.Add(item);
syncToPrevList();
ItemAdded?.Invoke(item);
OnChanged?.Invoke();
}
19
Source : ObservableList.cs
with MIT License
from Adam4lexander
with MIT License
from 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
Source : ObservableList.cs
with MIT License
from Adam4lexander
with MIT License
from Adam4lexander
public bool Remove(T item) {
var isRemoved = m_list.Remove(item);
if (isRemoved) {
syncToPrevList();
ItemRemoved?.Invoke(item);
OnChanged?.Invoke();
}
return isRemoved;
}
19
Source : IObservable.Fuse.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public void OnNext(T value)
{
LastValue = value;
_onNext(value);
}
19
Source : ActionExtensions.cs
with Apache License 2.0
from adamralph
with Apache License 2.0
from adamralph
public static Func<T, Task> ToAsync<T>(this Action<T> action) => obj => Task.Run(() => action.Invoke(obj));
19
Source : ConfigureWritable.cs
with MIT License
from ADefWebserver
with MIT License
from 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
Source : RazorEngineCompiledTemplateT.cs
with MIT License
from adoconnection
with MIT License
from 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
Source : VisualNode.cs
with MIT License
from adospace
with MIT License
from adospace
public static T When<T>(this T node, bool flag, Action<T> actionToApplyWhenFlagIsTrue) where T : VisualNode
{
if (flag)
{
actionToApplyWhenFlagIsTrue(node);
}
return node;
}
19
Source : VisualNode.cs
with MIT License
from adospace
with MIT License
from 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
Source : VisualNode.cs
with MIT License
from adospace
with MIT License
from 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
Source : VisualNode.cs
with MIT License
from adospace
with MIT License
from 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
Source : VisualNode.cs
with MIT License
from adospace
with MIT License
from adospace
protected override void OnMount()
{
_nativeControl = _nativeControl ?? new T();
Parent?.AddChild(this, _nativeControl);
_componentRefAction?.Invoke(NativeControl);
base.OnMount();
}
19
Source : Extensions.cs
with MIT License
from adyanth
with MIT License
from adyanth
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
{
foreach (var item in enumeration)
action(item);
}
19
Source : ObjectPool.cs
with Apache License 2.0
from advancer68
with Apache License 2.0
from advancer68
public virtual void Return(T item)
{
if (m_resetFunc != null)
{
m_resetFunc(item);
}
getQue.Enqueue(item);
}
19
Source : QueueSync.cs
with Apache License 2.0
from advancer68
with Apache License 2.0
from advancer68
public void DequeueAll(Action<T> func)
{
if (func == null)
{
return;
}
Switch();
while (outQue.Count > 0)
{
T it = outQue.Dequeue();
func(it);
}
}
19
Source : ResourcePool.cs
with The Unlicense
from aeroson
with The Unlicense
from aeroson
protected T CreateNewResource()
{
var toReturn = new T();
if (InstanceInitializer != null)
InstanceInitializer(toReturn);
return toReturn;
}
19
Source : RelayCommand.cs
with MIT License
from afxw
with MIT License
from afxw
public void Execute(object parameter)
{
_execute((T)parameter);
}
19
Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from 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
Source : CSVConvert.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from 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
Source : TsonSerializer.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from 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
Source : TsonSerializer.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from 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
Source : TsonSerializerV1.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from 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