⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockinterfacehandler.cs

📁 C#编写的网络爬虫程序 效率很高 很好用!
💻 CS
字号:
using System;
using System.Collections;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Reflection;

namespace NUnit.Mocks
{
	/// <summary>
	/// Summary description for MockInterfaceHandler.
	/// </summary>
	public class MockInterfaceHandler : RealProxy
	{
		private ICallHandler callHandler;

		public MockInterfaceHandler( Type type, ICallHandler callHandler ) : base( type ) 
		{ 
			this.callHandler = callHandler;
		}

		public override IMessage Invoke( IMessage msg )
		{
			IMethodCallMessage call = (IMethodCallMessage)msg;
			IMethodReturnMessage result = null; 

			if ( call != null )
			{
				try
				{
					object ret = callHandler.Call( call.MethodName, call.Args );

					if ( ret == null )
					{
						MethodInfo info = call.MethodBase as MethodInfo;
						Type returnType = info.ReturnType;

						if( returnType == typeof( System.Boolean ) ) ret = false; 

						if( returnType == typeof( System.Byte    ) ) ret = (System.Byte)0;
						if( returnType == typeof( System.SByte   ) ) ret = (System.SByte)0;
						if( returnType == typeof( System.Decimal ) ) ret = (System.Decimal)0;
						if( returnType == typeof( System.Double  ) ) ret = (System.Double)0;
						if( returnType == typeof( System.Single  ) ) ret = (System.Single)0;
						if( returnType == typeof( System.Int32   ) ) ret = (System.Int32)0;
						if( returnType == typeof( System.UInt32  ) ) ret = (System.UInt32)0;
						if( returnType == typeof( System.Int64   ) ) ret = (System.Int64)0;
						if( returnType == typeof( System.UInt64  ) ) ret = (System.UInt64)0;
						if( returnType == typeof( System.Int16   ) ) ret = (System.Int16)0;
						if( returnType == typeof( System.UInt16  ) ) ret = (System.UInt16)0;

						if( returnType == typeof( System.Char	 ) ) ret = '?';
					}

					result = new ReturnMessage( ret, null, 0, null, call );
				} 
				catch( Exception e )
				{
					result = new ReturnMessage( e, call );
				}
			}

			return result;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -