本文整理匯總了C#中System.Dynamic.InvokeMemberBinder.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# InvokeMemberBinder.GetType方法的具體用法?C# InvokeMemberBinder.GetType怎麽用?C# InvokeMemberBinder.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Dynamic.InvokeMemberBinder
的用法示例。
在下文中一共展示了InvokeMemberBinder.GetType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetGenericType
private static Type GetGenericType(InvokeMemberBinder binder)
{
var csharpBinder = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
var typeArgs = (csharpBinder.GetProperty("TypeArguments").GetValue(binder, null) as IList<Type>);
return typeArgs.FirstOrDefault();
}
示例2: GetMethodReturnType
private Type GetMethodReturnType(InvokeMemberBinder binder)
{
IList<Type> types = binder.GetType().GetField("m_typeArguments", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(binder) as IList<Type>;
if ((types != null) && (types.Count > 0))
{
return types[0];
}
return null;
}
示例3: TryInvokeMember
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
int nargout = 1;
var args1 = args;
if (binder.CallInfo.ArgumentNames.Count != 0 &&
binder.CallInfo.ArgumentNames[binder.CallInfo.ArgumentNames.Count - 1].Equals("nargout",
StringComparison.Ordinal))
{
try
{
nargout = (int) args[args.Length - 1];
}
catch (InvalidCastException)
{
throw new ArgumentException("Type of nargout argument must be Int32", "nargout");
}
args1 = new object[args.Length - 1];
Array.Copy(args, 0, args1, 0, args1.Length);
}
else
{
if (_bInfo == null)
{
_bInfo = binder.GetType().GetInterface(
"Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder")
.GetProperty("ResultDiscarded");
}
if ((bool) _bInfo.GetValue(binder, null))
{
nargout = 0;
}
}
var status = OctaveCore.Octave.Feval(binder.Name, args1, nargout, out result);
switch (status)
{
case OctaveCore.Octave.FevalStatus.OK:
return true;
case OctaveCore.Octave.FevalStatus.Error:
throw new OctaveRuntimeException(OctaveCore.Octave.GetLastError());
case OctaveCore.Octave.FevalStatus.BadArgument:
throw new ArgumentException("Unsupported argument type", "args");
case OctaveCore.Octave.FevalStatus.BadReturn:
throw new ArgumentException("Unsupported return type", "ret");
case OctaveCore.Octave.FevalStatus.BadAlloc:
throw new OutOfMemoryException("Octave failed to allocate the required memory");
case OctaveCore.Octave.FevalStatus.Interupted:
throw new OctaveRuntimeException("Octave interpreter was interrupted");
default:
return false;
}
}
示例4: TryInvokeMember
// Called when a method is called
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
for (int i = 0; i < args.Length; i++)
args[i] = Unwrap(args[i]);
var csharpBinder = binder.GetType().GetTypeInfo().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
var typeArgs = (csharpBinder.GetTypeInfo().GetProperty("TypeArguments").GetValue(binder, null) as IList<Type>);
result = InvokeMethodOnType(TargetType, Instance, binder.Name, args, typeArgs);
// Wrap the sub object if necessary. This allows nested anonymous objects to work.
result = result.AsDynamic();
return true;
}
示例5: TryInvokeMember
/// <summary>
/// Provides the implementation for operations that invoke a member. Classes derived from the
/// <see
/// cref="T:System.Dynamic.DynamicObject" />
/// class can override this method to specify dynamic behavior for operations such as calling a method.
/// </summary>
/// <returns>
/// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)
/// </returns>
/// <param name="binder">
/// Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the
/// <see
/// cref="T:System.Dynamic.DynamicObject" />
/// class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
/// </param>
/// <param name="args">
/// The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="args" /> is equal to 100.
/// </param>
/// <param name="result">The result of the member invocation.</param>
public override bool TryInvokeMember(
InvokeMemberBinder binder,
object[] args,
out object result)
{
var method = targetType.GetMethod(binder.Name,
BindingFlags.FlattenHierarchy |
BindingFlags.Public |
BindingFlags.Static);
if (method == null)
{
result = null;
return false;
}
if (binder.CallInfo.ArgumentNames.Any() &&
binder.CallInfo.ArgumentNames.First() == "of")
{
var type = args.First() as Type;
if (type != null)
{
method = method.MakeGenericMethod(new[] { type });
args = args.Skip(1).ToArray();
}
}
else
{
var csharpBinder = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
var genericArguments = (csharpBinder.GetProperty("TypeArguments").GetValue(binder, null) as IEnumerable<Type>);
if (genericArguments != null && genericArguments.Any())
{
method = method.MakeGenericMethod(genericArguments.ToArray());
}
}
result = method.Invoke(null, args);
return true;
}
示例6: GenericArguments
static IList<Type> GenericArguments(InvokeMemberBinder binder)
{
//TOOD: http://stackoverflow.com/questions/5492373/get-generic-type-of-call-to-method-in-dynamic-object
var csharpBinder = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
return csharpBinder.GetProperty("TypeArguments").GetValue(binder, null) as IList<Type> ?? new List<Type>();
}
示例7: TypeArguments
private Type[] TypeArguments(InvokeMemberBinder binder)
{
var csharpBinder = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
return (csharpBinder.GetProperty("TypeArguments").GetValue(binder, null) as IList<Type>).ToArray();
}