本文整理汇总了C#中System.Dynamic.InvokeMemberBinder类的典型用法代码示例。如果您正苦于以下问题:C# InvokeMemberBinder类的具体用法?C# InvokeMemberBinder怎么用?C# InvokeMemberBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvokeMemberBinder类属于System.Dynamic命名空间,在下文中一共展示了InvokeMemberBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDelegate
public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
{
if (dataStrategy is SimpleTransaction) return null;
if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
{
ArgumentHelper.CheckFindArgs(args, binder);
if (args.Length == 1 && args[0].IsAnonymous()) return null;
}
var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "FindBy", "find_by");
if (criteriaDictionary == null) return null;
var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
try
{
var adapter = dataStrategy.GetAdapter();
var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
return a =>
{
var data = func(a);
return (data != null && data.Count > 0)
? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
: null;
};
}
catch (NotImplementedException)
{
return null;
}
}
示例2: CreateCriteriaDictionary
internal static IEnumerable<KeyValuePair<string, object>> CreateCriteriaDictionary(InvokeMemberBinder binder, IList<object> args, params string[] exactNames)
{
IDictionary<string, object> criteriaDictionary = null;
if (exactNames.Contains(binder.Name))
{
if (binder.CallInfo.ArgumentNames != null && binder.CallInfo.ArgumentNames.Count > 0)
{
criteriaDictionary = binder.NamedArgumentsToDictionary(args);
}
else if (args.Count == 1)
{
if (ReferenceEquals(args[0], null)) throw new ArgumentException("FindBy does not accept unnamed null argument.");
criteriaDictionary = args[0].ObjectToDictionary();
}
}
else
{
criteriaDictionary = MethodNameParser.ParseFromBinder(binder, args);
}
if (criteriaDictionary == null || criteriaDictionary.Count == 0)
{
throw new ArgumentException(binder.Name + " requires an equal number of column names and values to filter data by.");
}
return criteriaDictionary;
}
示例3: TryInvokeMember
public bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var adapterMethods = _adapter.GetType().GetMethods().Where(m => m.Name == binder.Name).ToList();
foreach (var method in adapterMethods)
{
var parameters = method.GetParameters().ToArray();
if (parameters.Any(p => p.RawDefaultValue != DBNull.Value) && binder.CallInfo.ArgumentNames.Any(s => !string.IsNullOrWhiteSpace(s)))
{
if (TryInvokeMemberWithNamedParameters(binder, args, out result, method, parameters))
{
return true;
}
}
else
{
if (AreCompatible(parameters, args))
{
result = method.Invoke(_adapter, args);
return true;
}
}
}
result = null;
return false;
}
示例4: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var msg = new Message(binder, args);
Apply(msg);
result = null;
return true;
}
示例5: TryInvokeMember
/// <summary>
/// This builds a query with the passed in named arguments - shopify.Products(collection_id:121212)
/// </summary>
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var name = binder.Name.ToLower() + ".json";
var url = _baseUrl + name;
//params?
var info = binder.CallInfo;
var looper = 0;
if (info.ArgumentNames.Count > 0) {
for (int i = 0; i < args.Length; i++) {
var argName = info.ArgumentNames[i].ToLower();
var val = args[i];
//the ID is a singular call
//with a special format
if (argName == "id") {
url = url.Replace(".json", "/" + val + ".json");
} else {
if (looper == 0)
url += "?";
else
url += "&";
url += string.Format("{0}={1}", argName, val);
}
looper++;
}
}
var json = Send(url);
result = JsonHelper.Decode(json);
return true;
}
示例6: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var name = binder.Name;
result = GetUrl(name, args);
return true;
}
示例7: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var functionName = binder.Name;
try
{
// convert arguments to Parameter
var parameters = new Parameter[args.Length];
for (int i = 0; i < args.Length; i++)
{
parameters[i] = new Parameter(args[i]);
}
Function.SetEntRef(_entRef);
result = Function.Call(functionName, typeof(object), parameters);
return true;
}
catch (Exception ex)
{
Log.Error(ex);
result = null;
return false;
}
}
示例8: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
if(Members.Contains(binder.Name))
return base.TryInvokeMember(binder, args, out result);
result = Evaluate(ConstructInvokeStatement(binder, args));
return true;
}
示例9: Execute
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
{
var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
return new SimpleQuery(dataStrategy.Adapter, table.GetQualifiedName()).Where(criteria);
//var data = dataStrategy.Find(table.GetQualifiedName(), criteria);
//return CreateSimpleResultSet(table, dataStrategy, data);
}
示例10: CreateDelegate
public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
{
if (dataStrategy is SimpleTransaction) return null;
var criteriaDictionary = CreateCriteriaDictionary(binder, args);
if (criteriaDictionary == null) return null;
var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
try
{
var adapter = dataStrategy.GetAdapter();
var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
return a =>
{
var data = func(a);
return (data != null && data.Count > 0)
? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
: null;
};
}
catch (NotImplementedException)
{
return null;
}
}
示例11: TryInvokeMember
// i.e. Error("I had an error.")
// i.e. Error(exception)
// i.e. Error("You can't do that.", exception)
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
result = null;
Log log;
if (_logs.TryGetValue(binder.Name, out log)) {
try {
if (args.Length == 1) {
if (args[0] is string) {
log.Write(args[0] as string);
return true;
}
else if (args[0] is Exception) {
log.Write(args[0] as Exception);
return true;
}
}
else if (args.Length == 2) {
if (args[0] is string && args[1] is Exception) {
log.Write(args[0] as string, args[1] as Exception);
return true;
}
}
return false;
}
catch {
return false;
}
}
return base.TryInvokeMember(binder, args, out result);
}
示例12: CreateDelegate
public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
{
if (dataStrategy is SimpleTransaction) return null;
if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
{
if (args.Length == 0) throw new ArgumentException("FindBy requires arguments.");
if (args.Length == 1)
{
if (ReferenceEquals(args[0], null)) throw new ArgumentException("FindBy does not accept unnamed null argument.");
if (args[0].GetType().Namespace == null) return null;
}
}
var criteriaDictionary = CreateCriteriaDictionary(binder, args);
if (criteriaDictionary == null) return null;
var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
try
{
var adapter = dataStrategy.GetAdapter();
var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
return a =>
{
var data = func(a);
return (data != null && data.Count > 0)
? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
: null;
};
}
catch (NotImplementedException)
{
return null;
}
}
示例13: TryInvokeMember
public override bool TryInvokeMember(
InvokeMemberBinder binder, object[] args, out object result)
{
if (cities.FindCity(binder.Name) != null) result = cities.FindCity(binder.Name);
else result = "The city <" + binder.Name + "> does not exist!";
return true;
}
示例14: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
string routename = binder.Name;
var stems = routename.Split('_');
if (stems.Last() == "h")
{
routename = routename.Remove(binder.Name.Length - 2);
result = GetAnchorTag("http", routename, args);
}
else if (stems.Last() == "s")
{
routename = routename.Remove(binder.Name.Length - 2);
result = GetAnchorTag("https", routename, args);
}
else
{
result = GetAnchorTag(routename, args);
}
return true;
}
示例15: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Speak(binder.Name);
result = true;
return true;
}