Here are the examples of the csharp api System.Func.Invoke(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
919 Examples
19
Source : FieldInfoHelper.cs
with zlib License
from 0x0ade
with zlib License
from 0x0ade
public override object GetValue(object obj)
=> _OnGetValue?.Invoke(obj);
19
Source : Reader.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
public void SetCtx(object ctx)
{
this._ctx = ctx;
if (this._ctx != null)
{
this._child?.SetCtx(this._ctx);
if (this._extractor != null)
{
this.SetResult(this._extractor(this._ctx));
}
}
}
19
Source : BssoFieldMarshalTest.cs
with MIT License
from 1996v
with MIT License
from 1996v
[Theory]
[MemberData(nameof(ReadBlankTestData))]
public void ReadByIgnoringBlankCharactersTest(object val, Func<object, bool> test)
{
var obj = new byte[3000];
var buf = BssomSerializer.Serialize(obj);
var bsfw = new BssomFieldMarshaller(buf);
bsfw.TryWrite(BssomFieldOffsetInfo.Zero, val).IsTrue();
test(BssomSerializer.Deserialize(buf, 0, out int readSize, val.GetType())).IsTrue();
bsfw.TryWrite(BssomFieldOffsetInfo.Zero, val).IsTrue();
test(BssomSerializer.Deserialize(buf, 0, out readSize, val.GetType())).IsTrue();
}
19
Source : TransactionsAdapter.cs
with MIT License
from 2881099
with MIT License
from 2881099
public object[] Exec()
{
if (_redisSocket == null) return new object[0];
try
{
var ret = SelfCall("EXEC") as object[];
var retparsed = new object[ret.Length];
for (var a = 0; a < ret.Length; a++)
{
retparsed[a] = _commands[a].Parse(ret[a]);
#if isasync
_commands[a].TrySetResult(retparsed[a], null); //tryset Async
#endif
}
return retparsed;
}
finally
{
TryReset();
}
}
19
Source : CommandPacket.cs
with MIT License
from 2881099
with MIT License
from 2881099
public CommandPacket InputKv(object[] keyValues, bool iskey, Func<object, object> serialize)
{
if (keyValues == null || keyValues.Length == 0) return this;
if (keyValues.Length % 2 != 0) throw new ArgumentException($"Array {nameof(keyValues)} length is not even");
for (var a = 0;a < keyValues.Length; a += 2)
{
if (iskey) InputKey(keyValues[a].ToInvariantCultureToString());
else InputRaw(keyValues[a]);
InputRaw((serialize?.Invoke(keyValues[a + 1]) ?? keyValues[a + 1]));
}
return this;
}
19
Source : CommandPacket.cs
with MIT License
from 2881099
with MIT License
from 2881099
public CommandPacket InputKv<T>(Dictionary<string, T> keyValues, bool iskey, Func<object, object> serialize)
{
foreach (var kv in keyValues)
{
if (iskey) InputKey(kv.Key);
else InputRaw(kv.Key);
InputRaw(serialize?.Invoke(kv.Value) ?? kv.Value);
}
return this;
}
19
Source : CometaryExtensions.With.cs
with MIT License
from 71
with MIT License
from 71
internal static T Clone<T>(this T obj) where T : clreplaced
{
return (T)CloneCore.Value(obj);
}
19
Source : Event.ExecuteEvents.partial.cs
with MIT License
from 7Bytes-Studio
with MIT License
from 7Bytes-Studio
public static IEventHandler[] GetEventHandler(object root)
{
if (null!= s_GetEventHandlersCallback)
{
return s_GetEventHandlersCallback.Invoke(root);
}
return root is IEventHandler ? new IEventHandler[] { root as IEventHandler } : null;
}
19
Source : DelegateCommand.cs
with MIT License
from 944095635
with MIT License
from 944095635
public bool CanExecute(object parameter)
{
if (canExecuteFunc == null)
{
return true;
}
return canExecuteFunc(parameter);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool IsKeyIdEmpty(object enreplacedy, ColumnAttribute pkColumn)
{
return IsKeyFieldEmpty(pkColumn.GetAction(enreplacedy), pkColumn.replacedle);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool IsKeyIdEmpty(object enreplacedy)
{
if (Columns.Where(p=>p.Value.IsPrimaryKey).Count()==0)
return true;
bool result = false;
foreach (ColumnAttribute c in Columns.Where(p => p.Value.IsPrimaryKey).Select(a=>a.Value))
{
result = IsKeyFieldEmpty(c.GetAction(enreplacedy), c.replacedle);
if (result)
break;
}
return result;
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool IsIdenreplacedyKeyIdEmpty(object enreplacedy)
{
if (Columns.Where(p => p.Value.IsPrimaryKey && p.Value.PrimaryKeyInfo.IsIdenreplacedy).Count() == 0)
return true;
ColumnAttribute pkIdenreplacedyCol = Columns.Where(p => p.Value.IsPrimaryKey && p.Value.PrimaryKeyInfo.IsIdenreplacedy).Select(p=>p.Value).FirstOrDefault();
return IsKeyFieldEmpty(pkIdenreplacedyCol.GetAction(enreplacedy), pkIdenreplacedyCol.replacedle);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool IsCreatedByEmpty(object enreplacedy)
{
return NoCreatedBy ? false : IsKeyFieldEmpty(Columns[Config.CREATEDBY_COLUMN.Name].GetAction(enreplacedy), "Created By");
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool IsUpdatedByEmpty(object enreplacedy)
{
return NoUpdatedBy ? false : IsKeyFieldEmpty(Columns[Config.UPDATEDBY_COLUMN.Name].GetAction(enreplacedy), "Updated By");
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal object GetKeyId(object enreplacedy)
{
return PkColumn.GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal object GetKeyId(object enreplacedy, ColumnAttribute pkColumn)
{
return pkColumn.GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal object GetCreatedBy(object enreplacedy)
{
return Columns[Config.CreatedByColumnName].GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal DateTime? GetCreatedOn(object enreplacedy)
{
return (DateTime?)Columns[Config.CreatedOnColumnName].GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal object GetUpdatedBy(object enreplacedy)
{
return Columns[Config.UpdatedByColumnName].GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal DateTime? GetUpdatedOn(object enreplacedy)
{
return (DateTime?)Columns[Config.UpdatedOnColumnName].GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal int? GetVersionNo(object enreplacedy)
{
return (int?)Columns[Config.VersionNoColumnName].GetAction(enreplacedy);
}
19
Source : Attributes.cs
with Apache License 2.0
from aadreja
with Apache License 2.0
from aadreja
internal bool? GetIsActive(object enreplacedy)
{
return (bool?)Columns[Config.IsActiveColumnName].GetAction(enreplacedy);
}
19
Source : FdbConverters.cs
with MIT License
from abdullin
with MIT License
from abdullin
public static T Unbox<T>(object value)
{
return Idenreplacedy<T>.FromObject(value);
}
19
Source : FdbConverters.cs
with MIT License
from abdullin
with MIT License
from abdullin
public object ConvertBoxed(object value)
{
return FromObject(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 : Helpers.cs
with MIT License
from ad313
with MIT License
from ad313
public static Dictionary<string, object> ToDictionary(object obj)
{
var type = obj.GetType();
if (!DictionaryCache.TryGetValue(type, out Func<object, Dictionary<string, object>> getter))
{
getter = CreateDictionaryGenerator(type);
DictionaryCache.TryAdd(type, getter);
}
return getter(obj);
}
19
Source : JsonCondition.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public Condition ToCondition(Func<object, object> deserialize)
{
var condition = new Condition
{
Aggregate = this.Aggregate,
Attribute = this.Attribute,
Alias = this.Alias,
Column = this.Column,
EnreplacedyName = this.EnreplacedyName,
Extensions = this.Extensions,
Operator = this.Operator,
UiHidden = this.UiHidden,
UiName = this.UiName,
UiType = this.UiType,
Value = deserialize(this.Value),
Values = this.Values != null ? this.Values.Select(deserialize).ToList() : null
};
return condition;
}
19
Source : SerializationHelper.cs
with MIT License
from AElfProject
with MIT License
from AElfProject
public static byte[] Serialize(object value)
{
if (value == null)
{
return null;
}
var type = value.GetType();
var primitiveSerializer = GetPrimitiveSerializer(type);
if (primitiveSerializer != null)
{
return primitiveSerializer(value);
}
if (type == typeof(string))
{
return Encoding.UTF8.GetBytes((string) value);
}
if (type.IsEnum)
{
return Serialize((int) value);
}
if (typeof(IMessage).IsreplacedignableFrom(type))
{
var v = (IMessage) value;
return v.ToByteArray();
}
throw new InvalidOperationException($"Invalid type {type}.");
}
19
Source : IDataExtendChecker.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
internal static bool PrepareAddnew<T>(T data)
{
foreach (var creaters in Checker)
{
var target = creaters.Value.Convert(data);
if (target == null)
continue;
foreach (var creater in creaters.Value.Dictionary.Values)
{
var checker = creater();
if (!checker.PrepareAddnew(target))
return false;
}
}
return true;
}
19
Source : IDataExtendChecker.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
internal static bool PrepareUpdate<T>(T data)
{
foreach (var creaters in Checker)
{
var target = creaters.Value.Convert(data);
if (target == null)
continue;
foreach (var creater in creaters.Value.Dictionary.Values)
{
var checker = creater();
if (!checker.PrepareUpdate(target))
return false;
}
}
return true;
}
19
Source : RedisHelper.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static T CacheShell<T>(string key, int timeoutSeconds, Func<T> getData, Func<T, string> serialize = null, Func<string, T> deserialize = null) =>
Instance.CacheShell(key, timeoutSeconds, getData, serialize ?? new Func<T, string>(value => Serialize(value)), deserialize ?? new Func<string, T>(data => (T) Deserialize(data, typeof(T))));
19
Source : RedisHelper.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static T CacheShell<T>(string key, string field, int timeoutSeconds, Func<T> getData, Func<(T, long), string> serialize = null, Func<string, (T, long)> deserialize = null) =>
Instance.CacheShell(key, field, timeoutSeconds, getData, serialize ?? new Func<(T, long), string>(value => Serialize(value)), deserialize ?? new Func<string, (T, long)>(data => ((T, long)) Deserialize(data, typeof((T, long)))));
19
Source : RedisHelper.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static T[] CacheShell<T>(string key, string[] fields, int timeoutSeconds, Func<string[], (string, T)[]> getData, Func<(T, long), string> serialize = null, Func<string, (T, long)> deserialize = null) =>
Instance.CacheShell(key, fields, timeoutSeconds, getData, serialize ?? new Func<(T, long), string>(value => Serialize(value)), deserialize ?? new Func<string, (T, long)>(data => ((T, long))Deserialize(data, typeof((T, long)))));
19
Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static List<TTarget> ToList<TTarget>(this IEnumerable em, Func<object, TTarget> action, bool keepNull = true)
{
var results = new List<TTarget>();
if (em == null)
{
return results;
}
if (keepNull)
{
foreach (var t in em)
{
if (!Equals(t, null))
results.Add(action(t));
}
}
else
{
foreach (var t in em)
{
results.Add(action(t));
}
}
return results;
}
19
Source : CSRedisClientPipe.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public object[] EndPipe() {
var ret = new object[Parsers.Count];
foreach (var conn in Conns) {
object[] tmp = null;
try {
tmp = conn.Value.conn.Client.EndPipe();
} catch (Exception ex) {
conn.Value.conn.Pool.RequirePing(ex);
throw ex;
} finally {
conn.Value.conn.Pool.ReleaseConnection(conn.Value.conn);
}
for (var a = 0; a < tmp.Length; a++) {
var retIdx = conn.Value.indexes[a];
ret[retIdx] = tmp[a];
}
}
for (var b = 0; b < ret.Length; b++) {
var parse = Parsers.Dequeue();
if (parse != null) ret[b] = parse(ret[b]);
}
Conns.Clear();
return ret;
}
19
Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static IEnumerable<T> Select2<T>(this IEnumerable source, Func<object, T> convert)
{
if (source == null)
{
return new List<T>();
}
if (source is List<T> enreplacedyList)
{
return enreplacedyList;
}
var list = new List<T>();
foreach (var t in source)
{
list.Add(convert(t));
}
return list;
}
19
Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static string ListToString(this IEnumerable em, Func<object, string> fmt, string sp = ",", string head = null, string food = null)
{
if (em == null)
{
return null;
}
var sb = new StringBuilder();
if (head != null)
{
sb.Append(head);
}
var first = true;
foreach (var v in em)
{
if (v == null)
{
continue;
}
if (v is string && string.IsNullOrWhiteSpace(v as string))
{
continue;
}
if (first)
{
first = false;
}
else
{
sb.Append(sp);
}
sb.Append(fmt(v));
}
if (first)
return null;
if (food != null)
{
sb.Append(food);
}
return sb.ToString();
}
19
Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public static List<TTarget> Foreach<TTarget, TSource>(this IEnumerable<TSource> em, Func<object, TTarget> action, bool keepNull = true)
{
var results = new List<TTarget>();
if (em == null)
{
return results;
}
if (keepNull)
{
foreach (var t in em.Where(p => !Equals(p, default(TSource))))
{
results.Add(action(t));
}
}
else
{
foreach (var t in em)
{
results.Add(action(t));
}
}
return results;
}
19
Source : TreeItemBase.cs
with Mozilla Public License 2.0
from agebullhu
with Mozilla Public License 2.0
from agebullhu
public TreeItem CreateChild(object value)
{
var item = CreateChildFunc(value);
var extend = value as IExtendDependencyObjects;
extend?.Dependency.Annex(item);
return item;
}
19
Source : BaseCommand.cs
with MIT License
from aishang2015
with MIT License
from aishang2015
public bool CanExecute(object parameter)
{
if (_canExecute == null) return true;
return _canExecute(parameter);
}
19
Source : DefaultContractResolver.cs
with MIT License
from akaskela
with MIT License
from akaskela
private void SetIsSpecifiedActions(JsonProperty property, MemberInfo member, bool allowNonPublicAccess)
{
MemberInfo specifiedMember = member.DeclaringType.GetProperty(member.Name + JsonTypeReflector.SpecifiedPostfix);
if (specifiedMember == null)
{
specifiedMember = member.DeclaringType.GetField(member.Name + JsonTypeReflector.SpecifiedPostfix);
}
if (specifiedMember == null || ReflectionUtils.GetMemberUnderlyingType(specifiedMember) != typeof(bool))
{
return;
}
Func<object, object> specifiedPropertyGet = JsonTypeReflector.ReflectionDelegateFactory.CreateGet<object>(specifiedMember);
property.GetIsSpecified = o => (bool)specifiedPropertyGet(o);
if (ReflectionUtils.CanSetMemberValue(specifiedMember, allowNonPublicAccess, false))
{
property.SetIsSpecified = JsonTypeReflector.ReflectionDelegateFactory.CreateSet<object>(specifiedMember);
}
}
19
Source : DefaultContractResolver.cs
with MIT License
from akaskela
with MIT License
from akaskela
private static void SetExtensionDataDelegates(JsonObjectContract contract, MemberInfo member)
{
JsonExtensionDataAttribute extensionDataAttribute = ReflectionUtils.GetAttribute<JsonExtensionDataAttribute>(member);
if (extensionDataAttribute == null)
{
return;
}
Type t = ReflectionUtils.GetMemberUnderlyingType(member);
Type dictionaryType;
ReflectionUtils.ImplementsGenericDefinition(t, typeof(IDictionary<,>), out dictionaryType);
Type keyType = dictionaryType.GetGenericArguments()[0];
Type valueType = dictionaryType.GetGenericArguments()[1];
Type createdType;
// change type to a clreplaced if it is the base interface so it can be instantiated if needed
if (ReflectionUtils.IsGenericDefinition(t, typeof(IDictionary<,>)))
{
createdType = typeof(Dictionary<,>).MakeGenericType(keyType, valueType);
}
else
{
createdType = t;
}
Func<object, object> getExtensionDataDictionary = JsonTypeReflector.ReflectionDelegateFactory.CreateGet<object>(member);
if (extensionDataAttribute.ReadData)
{
Action<object, object> setExtensionDataDictionary = (ReflectionUtils.CanSetMemberValue(member, true, false))
? JsonTypeReflector.ReflectionDelegateFactory.CreateSet<object>(member)
: null;
Func<object> createExtensionDataDictionary = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(createdType);
MethodInfo addMethod = t.GetMethod("Add", new[] { keyType, valueType });
MethodCall<object, object> setExtensionDataDictionaryValue = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(addMethod);
ExtensionDataSetter extensionDataSetter = (o, key, value) =>
{
object dictionary = getExtensionDataDictionary(o);
if (dictionary == null)
{
if (setExtensionDataDictionary == null)
{
throw new JsonSerializationException("Cannot set value onto extension data member '{0}'. The extension data collection is null and it cannot be set.".FormatWith(CultureInfo.InvariantCulture, member.Name));
}
dictionary = createExtensionDataDictionary();
setExtensionDataDictionary(o, dictionary);
}
setExtensionDataDictionaryValue(dictionary, key, value);
};
contract.ExtensionDataSetter = extensionDataSetter;
}
if (extensionDataAttribute.WriteData)
{
Type enumerableWrapper = typeof(EnumerableDictionaryWrapper<,>).MakeGenericType(keyType, valueType);
ConstructorInfo constructors = enumerableWrapper.GetConstructors().First();
ObjectConstructor<object> createEnumerableWrapper = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(constructors);
ExtensionDataGetter extensionDataGetter = o =>
{
object dictionary = getExtensionDataDictionary(o);
if (dictionary == null)
{
return null;
}
return (IEnumerable<KeyValuePair<object, object>>)createEnumerableWrapper(dictionary);
};
contract.ExtensionDataGetter = extensionDataGetter;
}
contract.ExtensionDataValueType = valueType;
}
19
Source : ReflectionObject.cs
with MIT License
from akaskela
with MIT License
from akaskela
public object GetValue(object target, string member)
{
Func<object, object> getter = Members[member].Getter;
return getter(target);
}
19
Source : DynamicValueProvider.cs
with MIT License
from akaskela
with MIT License
from akaskela
public object GetValue(object target)
{
try
{
if (_getter == null)
{
_getter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(_memberInfo);
}
return _getter(target);
}
catch (Exception ex)
{
throw new JsonSerializationException("Error getting value from '{0}' on '{1}'.".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex);
}
}
19
Source : ExpressionValueProvider.cs
with MIT License
from akaskela
with MIT License
from akaskela
public object GetValue(object target)
{
try
{
if (_getter == null)
{
_getter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(_memberInfo);
}
return _getter(target);
}
catch (Exception ex)
{
throw new JsonSerializationException("Error getting value from '{0}' on '{1}'.".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex);
}
}
19
Source : ConvertUtils.cs
with MIT License
from akaskela
with MIT License
from akaskela
private static object EnsureTypereplacedignable(object value, Type initialType, Type targetType)
{
Type valueType = (value != null) ? value.GetType() : null;
if (value != null)
{
if (targetType.IsreplacedignableFrom(valueType))
{
return value;
}
Func<object, object> castConverter = CastConverters.Get(new TypeConvertKey(valueType, targetType));
if (castConverter != null)
{
return castConverter(value);
}
}
else
{
if (ReflectionUtils.IsNullable(targetType))
{
return null;
}
}
throw new ArgumentException("Could not cast or convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, (initialType != null) ? initialType.ToString() : "{null}", targetType));
}
19
Source : Uncapsulator.cs
with MIT License
from albahari
with MIT License
from albahari
public object GetValue (object instance)
{
if (_fastGetter == null)
{
if (MemberInfo is FieldInfo fi && fi.IsStatic)
return fi.GetValue (null);
// In .NET Framework, we get a TypeAccessException when trying to access this via Reflection.Emit
else if (MemberInfo is PropertyInfo pi && ((pi.GetMethod?.IsStatic ?? true) || IsDotNetFramework && pi.DeclaringType.IsInterface))
return pi.GetValue (instance, null);
else
// Optimize the common case of getting a field or property.
_fastGetter = MemberInfo is FieldInfo fi2
? TypeUtil.GenDynamicField (fi2)
: TypeUtil.GenDynamicProp ((PropertyInfo)MemberInfo);
}
return _fastGetter (instance);
}
19
Source : FieldAccessor.cs
with MIT License
from albyho
with MIT License
from albyho
public object GetValue(object instance)
{
return _getter(instance);
}
19
Source : PropertyAccessor.cs
with MIT License
from albyho
with MIT License
from albyho
public object GetValue(object o)
{
if (_getter == null)
{
throw new NotSupportedException("Get method is not defined for this property.");
}
return _getter(o);
}
19
Source : TypeAdapter.cs
with MIT License
from alelievr
with MIT License
from alelievr
public static object Convert(object from, Type targetType)
{
if (!adaptersLoaded)
LoadAllAdapters();
Func<object, object> convertionFunction;
if (adapters.TryGetValue((from.GetType(), targetType), out convertionFunction))
return convertionFunction?.Invoke(from);
return null;
}
See More Examples