Here are the examples of the csharp api System.Func.Invoke(T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3802 Examples
19
Source : Helpers.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
public static IReadOnlyList<TRes> Combine<T,TRes>(T arg, IReadOnlyList<T> rest, Func<T, TRes> mapper)
{
if (rest.Count < 1)
{
return new[] { mapper(arg) };
}
var result = new TRes[rest.Count + 1];
result[0] = mapper(arg);
for (int i = 0; i < rest.Count; i++)
{
result[i + 1] = mapper(rest[i]);
}
return result;
}
19
Source : Helpers.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
public static IReadOnlyList<TRes> Combine<TRes,T>(IReadOnlyList<TRes> arg1, T arg2, T[] rest, Func<T, TRes> mapper)
{
if (arg1.Count < 1)
{
return Combine(arg2, rest, mapper);
}
var result = new TRes[arg1.Count +1 +rest.Length];
for (int i = 0; i < arg1.Count; i++)
{
result[i] = arg1[i];
}
result[arg1.Count] = mapper(arg2);
for (int i = 0; i < rest.Length; i++)
{
result[arg1.Count + 1+ i] = mapper(rest[i]);
}
return result;
}
19
Source : Helpers.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
public static IReadOnlyList<TRes> SelectToReadOnlyList<T, TRes>(this IReadOnlyList<T> source, Func<T, TRes> mapper)
{
source.replacedertNotNull($"\"{nameof(source)}\" cannot be null");
mapper.replacedertNotNull($"\"{nameof(mapper)}\" cannot be null");
TRes[] result = new TRes[source.Count];
for (int i = 0; i < source.Count; i++)
{
result[i] = mapper(source[i]);
}
return result;
}
19
Source : Helpers.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
public static IReadOnlyList<TRes> SelectToReadOnlyList<T, TRes>(this IReadOnlyList<T> source, Predicate<T> predicate, Func<T, TRes> mapper)
{
source.replacedertNotNull($"\"{nameof(source)}\" cannot be null");
mapper.replacedertNotNull($"\"{nameof(mapper)}\" cannot be null");
predicate.replacedertNotNull($"\"{nameof(predicate)}\" cannot be null");
int count = 0;
for (int i = 0; i < source.Count; i++)
{
if (predicate(source[i]))
{
count++;
}
}
TRes[] result = new TRes[count];
if (count > 0)
{
int resultIndex = 0;
for (int i = 0; i < source.Count; i++)
{
if (predicate(source[i]))
{
if (resultIndex >= result.Length)
{
throw new SqExpressException("The predicate function should be idempotent",
new IndexOutOfRangeException());
}
result[resultIndex] = mapper(source[i]);
resultIndex++;
}
}
if (resultIndex != result.Length)
{
throw new SqExpressException("The predicate function should be idempotent");
}
}
return result;
}
19
Source : Ext.cs
with GNU General Public License v3.0
from 1330-Studios
with GNU General Public License v3.0
from 1330-Studios
public static Il2CppReferenceArray<T> Remove<T>(this Il2CppReferenceArray<T> reference, Func<T, bool> predicate) where T : Model {
List<T> bases = new List<T>();
foreach (var tmp in reference)
if (!predicate(tmp))
bases.Add(tmp);
return new(bases.ToArray());
}
19
Source : Ext.cs
with GNU General Public License v3.0
from 1330-Studios
with GNU General Public License v3.0
from 1330-Studios
public static Il2CppSystem.Collections.Generic.IEnumerable<C> SelectI<T, R, C>(this IEnumerable<T> enumerable, Func<T, R> predicate) where R : Model where C : Model {
var bases = new Il2CppSystem.Collections.Generic.List<C>();
var enumerator = enumerable.GetEnumerator();
while (enumerator.MoveNext())
bases.Add(predicate(enumerator.Current).Cast<C>());
return bases.Cast<Il2CppSystem.Collections.Generic.IEnumerable<C>>();
}
19
Source : MainWindow_Model.cs
with MIT License
from 1217950746
with MIT License
from 1217950746
public async void Execute(object parameter)
{
await _asyncExecute((T)parameter);
}
19
Source : Ext.cs
with GNU General Public License v3.0
from 1330-Studios
with GNU General Public License v3.0
from 1330-Studios
public static Il2CppReferenceArray<T> Remove<T>(this Il2CppReferenceArray<T> reference, Func<T, bool> predicate) where T : Il2CppObjectBase {
List<T> bases = new List<T>();
foreach (var tmp in reference)
if (!predicate(tmp))
bases.Add(tmp);
return new(bases.ToArray());
}
19
Source : CommandNode.cs
with Apache License 2.0
from 1448376744
with Apache License 2.0
from 1448376744
private string ResolveIfNode<T>(IfNode node, T parameter)
{
if (node.Delegate == null)
{
lock (this)
{
var context = new ExpressionActivator();
var result = context.Create<T>(node.Test);
node.Delegate = result.Func;
}
}
var func = node.Delegate as Func<T, bool>;
if (func(parameter))
{
return ResolveTextNode(new TextNode { Value = node.Value });
}
return string.Empty;
}
19
Source : VerifyHelper.cs
with MIT License
from 1996v
with MIT License
from 1996v
public static void Throws<T>(Action testCode, Func<T, bool> ex) where T : Exception
{
try
{
testCode();
}
catch (T t)
{
if (ex(t) == false)
throw new Exception("Different exception information", t);
return;
}
catch
{
throw;
}
throw new Exception("No exception");
}
19
Source : QuickAndDirtyCache.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
public async Task<T> TryGetFromCache<T>(
string key,
Func<Task<T>> renewObjectFunc,
Func<T, Task<bool>> isCachedObjectValidFunc)
{
if (_cacheDictionary.TryGetValue(key, out var cachedObj))
{
var obj = (T) cachedObj;
if (await isCachedObjectValidFunc(obj))
{
return obj;
}
}
var newObj = await renewObjectFunc();
await CacheObject(newObj, key);
return newObj;
}
19
Source : Serializer.cs
with MIT License
from 2881099
with MIT License
from 2881099
public static Dictionary<string, string> Serialize(T obj)
{
if (typeof(ISerializable).IsreplacedignableFrom(typeof(T)))
return _serializer.Value(obj);
else
return _propertySerializer.Value(obj);
}
19
Source : EnumerableExtensions.cs
with MIT License
from 3DBear
with MIT License
from 3DBear
public static IEnumerable<T> TakeUntilIncluding<T>(this IEnumerable<T> list, Func<T, bool> predicate)
{
foreach (T el in list)
{
yield return el;
if (predicate(el))
yield break;
}
}
19
Source : Maybe.cs
with Apache License 2.0
from 42skillz
with Apache License 2.0
from 42skillz
public Maybe<TResult> Select<TResult>(Func<T, TResult> selector)
{
if (selector == null)
throw new ArgumentNullException(nameof(selector));
if (this.HasItem)
return new Maybe<TResult>(selector(this.Item));
else
return new Maybe<TResult>();
}
19
Source : Maybe.cs
with Apache License 2.0
from 42skillz
with Apache License 2.0
from 42skillz
public Maybe<TResult> Select<TResult>(Func<T, TResult> selector)
{
if (selector == null)
throw new ArgumentNullException(nameof(selector));
if (this.HasItem)
return new Maybe<TResult>(selector(this.Item));
else
return new Maybe<TResult>();
}
19
Source : Utils.cs
with MIT License
from 71
with MIT License
from 71
internal static U[] Select<T, U>(this IReadOnlyList<T> list, Func<T, U> selector)
{
U[] result = new U[list.Count];
for (int i = 0; i < result.Length; i++)
{
result[i] = selector(list[i]);
}
return result;
}
19
Source : ListExtends.cs
with MIT License
from a3geek
with MIT License
from a3geek
public static bool IsContains<T>(this List<T> list, Func<T, bool> func)
{
for(var i = 0; i < list.Count; i++)
{
if(func(list[i]) == true)
{
return true;
}
}
return false;
}
19
Source : ListBox.cs
with Apache License 2.0
from AantCoder
with Apache License 2.0
from AantCoder
public virtual void Drow()
{
if (DataSource == null) return;
if (LineHeight == 0) LineHeight = TextHeight;
ScrollPosition = GUI.BeginScrollView(
Area
, ScrollPosition
, new Rect(0, 0, Area.width - WidthScrollLine, DataSource.Count * LineHeight));
var rect = new Rect(0, 0, Area.width - WidthScrollLine, LineHeight);
for (int i = 0; i < DataSource.Count; i++)
{
//светлый фон каждой второй строки
if (OddLineHighlight && i % 2 == 1)
{
Widgets.DrawAltRect(rect);
}
//отрисовка строки
DrowLine(i, DataSource[i], rect);
//выделенная строка
if (ShowSelected && i == SelectedIndex)
{
Widgets.DrawHighlightSelected(rect);
//Widgets.DrawHighlight(rect);
}
//подсветка строки под курсором
if (!OddLineHighlight && Mouse.IsOver(rect))
{
Widgets.DrawHighlight(rect);
}
//всплывающая подсказка
if (Tooltip != null)
{
var tt = Tooltip(DataSource[i]);
if (!string.IsNullOrEmpty(tt))
{
TooltipHandler.TipRegion(rect, tt);
}
}
//событие нажатия на строку
if (Widgets.ButtonInvisible(rect))
{
SelectedIndex = i;
if (OnClick != null) OnClick(i, DataSource[i]);
}
rect.y += LineHeight;
}
GUI.EndScrollView();
}
19
Source : KeyValueEncoders.cs
with MIT License
from abdullin
with MIT License
from abdullin
public Slice EncodeKey(T value)
{
return m_encoder(value);
}
19
Source : KeyValueEncoders.cs
with MIT License
from abdullin
with MIT License
from abdullin
public Slice EncodeValue(T value)
{
return m_encoder(value);
}
19
Source : CompressingTreeList.cs
with MIT License
from Abdesol
with MIT License
from Abdesol
public void TransformRange(int index, int length, Func<T, T> converter)
{
if (root == null)
return;
int endIndex = index + length;
int pos = index;
while (pos < endIndex) {
int endPos = Math.Min(endIndex, GetEndOfRun(pos));
T oldValue = this[pos];
T newValue = converter(oldValue);
SetRange(pos, endPos - pos, newValue);
pos = endPos;
}
}
19
Source : CompressingTreeList.cs
with MIT License
from Abdesol
with MIT License
from Abdesol
public void Transform(Func<T, T> converter)
{
if (root == null)
return;
Node prevNode = null;
for (Node n = root.LeftMost; n != null; n = n.Successor) {
n.value = converter(n.value);
if (prevNode != null && comparisonFunc(prevNode.value, n.value)) {
n.count += prevNode.count;
UpdateAugmentedData(n);
RemoveNode(prevNode);
}
prevNode = n;
}
CheckProperties();
}
19
Source : TaskHelpers.cs
with MIT License
from abdullin
with MIT License
from abdullin
public static async Task<R> Then<T, R>(this Task<T> task, [NotNull] Func<T, R> 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);
return inlineContinuation(value);
}
19
Source : FdbConverters.cs
with MIT License
from abdullin
with MIT License
from abdullin
public R Convert(T value)
{
return this.Converter(value);
}
19
Source : FdbConverters.cs
with MIT License
from abdullin
with MIT License
from abdullin
public object ConvertBoxed(object value)
{
return (object)this.Converter(Idenreplacedy<T>.FromObject(value));
}
19
Source : ServiceId.cs
with MIT License
from abdullin
with MIT License
from abdullin
public bool Equals(T x, T y) {
return _selector(x).Equals(_selector(y));
}
19
Source : ServiceId.cs
with MIT License
from abdullin
with MIT License
from abdullin
public int GetHashCode(T obj) {
return _selector(obj).GetHashCode();
}
19
Source : MovingAverage.cs
with MIT License
from ABTSoftware
with MIT License
from ABTSoftware
public static IEnumerable<double> MovingAverage<T>(this IEnumerable<T> inputStream, Func<T, double> selector, int period)
{
var ma = new MovingAverage(period);
foreach (var item in inputStream)
{
ma.Push(selector(item));
yield return ma.Current;
}
}
19
Source : LazyTreeNode.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public virtual async Task<bool> RefreshAsync()
{
if (_isRefreshing) return false;
_isRefreshing = true;
if (ChildrenProvider == null) return AbortRefresh();
var enumerable = await ChildrenProvider(Content);
if (enumerable == null) return AbortRefresh();
var collection = enumerable.ToList();
if (!collection.Any()) return AbortRefresh();
var children = collection.Select(GenerateLazyTreeNode).ToList();
children.ForEach(item => item.Parent = this);
SetChildrenCache(children.AsReadOnly());
_isRefreshing = false;
return true;
}
19
Source : RelayCommandAsync{T}.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public bool CanExecute(T parameter) => _canExecute?.Invoke(parameter) ?? true;
19
Source : RelayCommandAsync{T}.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public async Task Execute(T parameter)
{
IsExecuting = true;
var invoke = _execute?.Invoke(parameter);
if (invoke != null) await invoke;
IsExecuting = false;
}
19
Source : FileDownloaderBuilder.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
public IDownloaderBuilder Configure<T>(Func<T, IRemotePathProvider> remotePathProviderInterceptor) where T : IRemotePathProvider
{
Guards.ThrowIfNull(remotePathProviderInterceptor);
_remotePathProviderInterceptor = _remotePathProviderInterceptor
.Then(item => remotePathProviderInterceptor((T)item));
return this;
}
19
Source : UriExtensions.cs
with MIT License
from actions
with MIT License
from actions
public static void AddMultiple<T>(this IList<KeyValuePair<String, String>> collection, String key, IEnumerable<T> values, Func<T, String> convert)
{
ArgumentUtility.CheckForNull(collection, "collection");
ArgumentUtility.CheckStringForNullOrEmpty(key, "name");
if (convert == null) convert = (val) => val.ToString();
if (values != null && values.Any())
{
StringBuilder newValue = new StringBuilder();
KeyValuePair<String, String> matchingKvp = collection.FirstOrDefault(kvp => kvp.Key.Equals(key));
if (matchingKvp.Key == key)
{
collection.Remove(matchingKvp);
newValue.Append(matchingKvp.Value);
}
foreach (var value in values)
{
if (newValue.Length > 0)
{
newValue.Append(",");
}
newValue.Append(convert(value));
}
collection.Add(new KeyValuePair<String, String>(key, newValue.ToString()));
}
}
19
Source : UriExtensions.cs
with MIT License
from actions
with MIT License
from actions
public static void AddMultiple<T>(this NameValueCollection collection, String name, IEnumerable<T> values, Func<T, String> convert)
{
ArgumentUtility.CheckForNull(collection, "collection");
ArgumentUtility.CheckStringForNullOrEmpty(name, "name");
if (convert == null) convert = (val) => val.ToString();
if (values != null)
{
foreach (var value in values)
{
collection.Add(name, convert(value));
}
}
}
19
Source : EnumerableExtraExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from Acumatica
public static T? FirstOrNullable<T>(this IEnumerable<T> source, Func<T, bool> predicate)
where T : struct
{
source.ThrowOnNull(nameof(source));
return source.Cast<T?>().FirstOrDefault(v => predicate(v.Value));
}
19
Source : RabbitMqEventBusProvider.cs
with MIT License
from ad313
with MIT License
from ad313
public void RpcServer<T>(string key, Func<T, Task<RpcResult>> handler)
{
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));
if (handler == null)
throw new ArgumentNullException(nameof(handler));
_logger.LogWarning($"{DateTime.Now} RabbitMQ RpcServer 启动 " +
$"[{key}] " +
$"......");
var channel = _rabbitMqClientProvider.Channel;
channel.QueueDeclare(queue: _config.GetRpcServerQueueKey(key), durable: false, exclusive: false, autoDelete: true, arguments: null);
//channel.BasicQos(0, 1, false);
var consumer = new EventingBasicConsumer(channel);
channel.BasicConsume(queue: _config.GetRpcServerQueueKey(key), autoAck: false, consumer: consumer);
consumer.Received += async (model, ea) =>
{
var props = ea.BasicProperties;
var replyProps = channel.CreateBasicProperties();
replyProps.CorrelationId = props.CorrelationId;
RpcResult response = null;
try
{
_logger.LogDebug($"{DateTime.Now}:RpcServer [{key}] 收到消息: {Encoding.Default.GetString(ea.Body.ToArray())}");
response = await handler.Invoke(_serializerProvider.Deserialize<T>(ea.Body.ToArray()));
}
catch (Exception e)
{
_logger.LogError(e, $"{DateTime.Now} RabbitMQ RpcServer [{key}] 执行异常 {e.Message} ");
response = new RpcResult($"RpcServer [{key}] 执行异常", e);
}
finally
{
channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: _serializerProvider.SerializeBytes(response));
channel.BasicAck(ea.DeliveryTag, false);
}
};
}
19
Source : TypeDefinitionConstructor.cs
with GNU General Public License v3.0
from Adam-Wilkinson
with GNU General Public License v3.0
from Adam-Wilkinson
public bool TryConstrainValue(object inputValue, out object outputValue)
{
if (CanAcceptValue(inputValue))
{
outputValue = _constraint((T)inputValue);
return true;
}
outputValue = default;
return false;
}
19
Source : ValueConstraint.cs
with GNU General Public License v3.0
from Adam-Wilkinson
with GNU General Public License v3.0
from Adam-Wilkinson
public void AddToEndOfChain(IValueConstraint<T> constraint)
{
if (constraint is null)
{
return;
}
Func<T, T> PreviousTotal = constraint.TotalFunc;
TotalFunc = (x) => MyFunc(PreviousTotal(x));;
}
19
Source : IList.Every.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static bool Every<T>(List<T> list, Func<T, bool> func)
{
for (int i = 0; list != null && i < list.Count; ++i)
{
if (!func(list[i])) return false;
}
return true;
}
19
Source : IList.First.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static T First<T>(IList<T> list, Func<T, bool> condition)
{
for (int i = 0; list != null && i < list.Count; ++i)
{
if (condition(list[i])) return list[i];
}
return default(T);
}
19
Source : IList.ForEach.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static void ForEach<T, V, P1>(IList<T> list, Func<T, V> selector, Action<V, P1> action, P1 param1)
{
for (int i = 0; list != null && i < list.Count; ++i)
{
action(selector(list[i]), param1);
}
}
19
Source : IList.ForEach.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static void ForEach<T, V, P1, P2>(IList<T> list, Func<T, V> selector, Action<V, P1, P2> action, P1 param1, P2 param2)
{
for (int i = 0; list != null && i < list.Count; ++i)
{
action(selector(list[i]), param1, param2);
}
}
19
Source : IList.ForEach.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static void ForEach<T, V, P1, P2, P3>(IList<T> list, Func<T, V> selector, Action<V, P1, P2, P3> action, P1 param1, P2 param2, P3 param3)
{
for (int i = 0; list != null && i < list.Count; ++i)
{
action(selector(list[i]), param1, param2, param3);
}
}
19
Source : IList.Pipe.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static Func<T, T> Pipe<T>(IList<Func<T, T>> list)
{
// OPEN POINT: Is it possible to make Reduce more flexible and use it here instead of this custom implementation
return x =>
{
T acreplacedulator = x;
for (int i = 0; list != null && i < list.Count; ++i)
{
acreplacedulator = list[i](acreplacedulator);
}
return acreplacedulator;
};
}
19
Source : IList.Reduce.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static R Reduce<R, T>(IList<T> list, Func<R, R, R> reducer, Func<T, R> getValue, R initialValue, Func<T, bool> skip = null)
{
R acreplacedulator = initialValue;
for (int i = 0; list != null && i < list.Count; ++i)
{
if (skip != null && skip(list[i]))
{
continue;
}
acreplacedulator = reducer(acreplacedulator, getValue(list[i]));
}
return acreplacedulator;
}
19
Source : IList.Reduce.cs
with MIT License
from AdamRamberg
with MIT License
from AdamRamberg
public static R Reduce<R, T, P1>(IList<T> list, Func<R, R, P1, R> reducer, Func<T, R> getValue, R initialValue, P1 reducerParam1, Func<T, bool> skip = null)
{
R acreplacedulator = initialValue;
for (int i = 0; list != null && i < list.Count; ++i)
{
if (skip != null && skip(list[i]))
{
continue;
}
acreplacedulator = reducer(acreplacedulator, getValue(list[i]), reducerParam1);
}
return acreplacedulator;
}
19
Source : Serializer.cs
with MIT License
from ADeltaX
with MIT License
from ADeltaX
public static byte[] FromArray<T>(T[] data, int sizeOfPrimitiveType, Func<T, byte[]> arr, DateTimeOffset? timestamp = null)
{
byte[] array = new byte[data.Length * sizeOfPrimitiveType];
for (int i = 0; i < data.Length; i++)
{
var res = arr(data[i]);
Array.Copy(res, 0, array, sizeOfPrimitiveType * i, sizeOfPrimitiveType);
}
return array.AppendTimestamp(timestamp);
}
19
Source : Utilities.cs
with MIT License
from ADeltaX
with MIT License
from ADeltaX
public static U[] Map<T, U>(ICollection<T> source, Func<T, U> func)
{
U[] result = new U[source.Count];
int i = 0;
foreach (T sVal in source)
{
result[i++] = func(sVal);
}
return result;
}
19
Source : Utilities.cs
with MIT License
from ADeltaX
with MIT License
from ADeltaX
public static U[] Map<T, U>(IEnumerable<T> source, Func<T, U> func)
{
List<U> result = new List<U>();
foreach (T sVal in source)
{
result.Add(func(sVal));
}
return result.ToArray();
}
19
Source : Utilities.cs
with MIT License
from ADeltaX
with MIT License
from ADeltaX
public static C Filter<C, T>(ICollection<T> source, Func<T, bool> predicate) where C : ICollection<T>, new()
{
C result = new C();
foreach (T val in source)
{
if (predicate(val))
{
result.Add(val);
}
}
return result;
}
See More Examples