當前位置: 首頁>>代碼示例>>C#>>正文


C# InvokeMemberBinder.GetType方法代碼示例

本文整理匯總了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();
        }
開發者ID:licensemyproject,項目名稱:Formo,代碼行數:7,代碼來源:Configuration.cs

示例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;
 }
開發者ID:HaKDMoDz,項目名稱:eStd,代碼行數:9,代碼來源:DynamicDllImport.cs

示例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;
            }
        }
開發者ID:apaka,項目名稱:octave-sharp,代碼行數:56,代碼來源:OctaveIntepreter.cs

示例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;
        }
開發者ID:davidebbo,項目名稱:ReflectionMagic,代碼行數:14,代碼來源:PrivateReflectionDynamicObjectBase.cs

示例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;
            }
開發者ID:wli3,項目名稱:Its.Log,代碼行數:58,代碼來源:TypeExtensions.cs

示例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>();
 }
開發者ID:ShaneGH,項目名稱:Dynamox,代碼行數:6,代碼來源:MockBuilder.cs

示例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();
        }
開發者ID:eugman,項目名稱:Oak,代碼行數:6,代碼來源:Mock.cs


注:本文中的System.Dynamic.InvokeMemberBinder.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。