• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# System.NullReferenceException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.NullReferenceException的典型用法代码示例。如果您正苦于以下问题:C# NullReferenceException类的具体用法?C# NullReferenceException怎么用?C# NullReferenceException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NullReferenceException类属于System命名空间,在下文中一共展示了NullReferenceException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ConstructorWithMessageWorks

 public void ConstructorWithMessageWorks()
 {
     var ex = new NullReferenceException("The message");
     Assert.True((object)ex is NullReferenceException, "is NullReferenceException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "The message");
 }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:7,代码来源:NullReferenceExceptionTests.cs


示例2: TypePropertiesAreCorrect

 public void TypePropertiesAreCorrect()
 {
     Assert.AreEqual(typeof(NullReferenceException).GetClassName(), "Bridge.NullReferenceException", "Name");
     object d = new NullReferenceException();
     Assert.True(d is NullReferenceException, "is NullReferenceException");
     Assert.True(d is Exception, "is Exception");
 }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:7,代码来源:NullReferenceExceptionTests.cs


示例3: DefaultConstructorWorks

 public void DefaultConstructorWorks()
 {
     var ex = new NullReferenceException();
     Assert.True((object)ex is NullReferenceException, "is NullReferenceException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "Object is null.");
 }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:7,代码来源:NullReferenceExceptionTests.cs


示例4: RunTestsOfJUUTTestClassWithFailingClassSetUp

        public void RunTestsOfJUUTTestClassWithFailingClassSetUp()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMockWithFailingClassSetUp));
            session.Add(typeof(TestClassMockWithFailingClassSetUp).GetMethod("Bar"));

            //Testing the run of a specific testMethod
            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test report
            Report report = GetFirstMethodReportFrom(classReport.MethodReports);
            Exception raisedException = new NullReferenceException("Failing class set up.");
            Report expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(report, Is.EqualTo(expectedReport));

            //Testing the run of all tests
            MethodCallOrder = new List<string>();
            session.AddAll();
            classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test reports
            ICollection<MethodReport> reports = classReport.MethodReports;
            raisedException = new NullReferenceException("Failing class set up.");
            expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(reports.Count, Is.EqualTo(1));
            AssertEx.That(GetFirstMethodReportFrom(reports), Is.EqualTo(expectedReport));
        }
开发者ID:LennartH,项目名称:JUUT,代码行数:29,代码来源:TestSimpleTestClassRunner.cs


示例5: Test2

 public static void Test2()
 {
     var e1 = new NullReferenceException();
     var e2 = new NullReferenceException("бла бла", e1);
     var e3 = new Exception("Ураааа", e2);
     throw e3;
 }
开发者ID:arbium,项目名称:democratia2,代码行数:7,代码来源:Form1.cs


示例6: AgainstNull_WithValidLambdaExpression_DoesNotThrow

        public void AgainstNull_WithValidLambdaExpression_DoesNotThrow()
        {
            NullReferenceException ex = new NullReferenceException();

            // valid cast, does not evaluate to null
            Assert.DoesNotThrow(() => Guard.AgainstNull(() => ex as Exception));
        }
开发者ID:hermanpotgieter,项目名称:Code.Pizza,代码行数:7,代码来源:GuardTests.cs


示例7: Throw_Test

 public void Throw_Test()
 {
     var exception = new NullReferenceException();
     var expected = Observable.Throw<string>(exception);
     var actual = FactoryMethods.Throw<string>(exception);
     ReactiveAssert.AreElementsEqual(expected, actual);
 }
开发者ID:GavinOsborn,项目名称:Rx,代码行数:7,代码来源:FactoryMethodsTest.cs


示例8: Create

        public Models.Repository Create(string RepositoryName, string Description, string HomePage, bool Public)
        {
            LogProvider.LogMessage(string.Format("Repository.Create - RepositoryName : '{0}' , Description : '{1}' , HomePage : '{2}', Public : '{3}'",
                RepositoryName,
                Description,
                HomePage,
                Public));

            Authenticate();

            var url = "repos/create";

            var formValues = new NameValueCollection();
            if (string.IsNullOrEmpty(RepositoryName))
            {
                var error = new NullReferenceException("RepositoryName was null or empty");
                if (LogProvider.HandleAndReturnIfToThrowError(error))
                    throw error;
                return null;
            }
            formValues.Add("name", RepositoryName);

            if (!string.IsNullOrEmpty(Description))
                formValues.Add("description", Description);
            if (!string.IsNullOrEmpty(HomePage))
                formValues.Add("homepage", HomePage);

            formValues.Add("public", (Public ? 1 : 0).ToString());

            var result = ConsumeJsonUrlAndPostData<Models.Internal.RepositoryContainer<Models.Repository>>(url, formValues);

            return result == null ? null : result.Repository;
        }
开发者ID:rumpl,项目名称:GithubSharp,代码行数:33,代码来源:Repository.cs


示例9: ResponseIsNullForNonWebExceptions

 public void ResponseIsNullForNonWebExceptions()
 {
   NullReferenceException exception = new NullReferenceException("The thing is null");
   _builder.SetExceptionDetails(exception);
   RaygunMessage message = _builder.Build();
   Assert.IsNull(message.Details.Response);
 }
开发者ID:ArturDorochowicz,项目名称:raygun4net,代码行数:7,代码来源:RaygunMessageBuilderTests.cs


示例10: ShouldWrite

        public void ShouldWrite()
        {
            var inner1Ex = new NullReferenceException("inner1Message");
            var inner2Ex = new InvalidOperationException("inner2Message", inner1Ex);
            var outerEx = new Exception("outerMessage", inner2Ex);

            var expectedOutput = @"----------
            outerMessage
            ----------
            Debug information:
            ----------
            Exception: outerMessage
            [StackTrace:Exception]
            ----------
            inner InvalidOperationException: inner2Message
            [StackTrace:InvalidOperationException]
            ----------
            inner NullReferenceException: inner1Message
            [StackTrace:NullReferenceException]
            ----------
            ";

            Func<Exception, string> stackTraceFormatter = ex => string.Format("[StackTrace:{0}]", ex.GetType().Name);

            var actual = outerEx.ToLogString(stackTraceFormatter);

            Assert.That(expectedOutput, Is.EqualTo(actual));
        }
开发者ID:endjin,项目名称:DeployToAzure,代码行数:28,代码来源:ExceptionExtensionsTests.cs


示例11: ConstructorWithMessageAndInnerExceptionWorks

		public void ConstructorWithMessageAndInnerExceptionWorks() {
			var inner = new Exception("a");
			var ex = new NullReferenceException("The message", inner);
			Assert.IsTrue((object)ex is NullReferenceException, "is NullReferenceException");
			Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
			Assert.AreEqual(ex.Message, "The message");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:7,代码来源:NullReferenceExceptionTests.cs


示例12: SuccessPayment

        public HttpResponseMessage SuccessPayment(Guid invoiceKey, Guid paymentKey, string token, string payerId)
        {
            var invoice = _merchelloContext.Services.InvoiceService.GetByKey(invoiceKey);
            var payment = _merchelloContext.Services.PaymentService.GetByKey(paymentKey);
            if (invoice == null || payment == null || String.IsNullOrEmpty(token) || String.IsNullOrEmpty(payerId))
            {
                var ex = new NullReferenceException(string.Format("Invalid argument exception. Arguments: invoiceKey={0}, paymentKey={1}, token={2}, payerId={3}.", invoiceKey, paymentKey, token, payerId));
                LogHelper.Error<PayPalApiController>("Payment is not authorized.", ex);
                throw ex;
            }

	        var providerKeyGuid = new Guid(Constants.PayPalPaymentGatewayProviderKey);
			var paymentGatewayMethod = _merchelloContext.Gateways.Payment
				.GetPaymentGatewayMethods()
				.First(item => item.PaymentMethod.ProviderKey == providerKeyGuid);
	        //var paymentGatewayMethod = _merchelloContext.Gateways.Payment.GetPaymentGatewayMethodByKey(providerKeyGuid);

            // Authorize
            var authorizeResult = _processor.AuthorizePayment(invoice, payment, token, payerId);
	        /*
			var authorizePaymentProcArgs = new ProcessorArgumentCollection();

	        authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalTokenKey] = token;
			authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalPayerIDKey] = payerId;
			authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalPaymentKeyKey] = payment.Key.ToString();

	        var authorizeResult = paymentGatewayMethod.AuthorizeCapturePayment(invoice, payment.Amount, authorizePaymentProcArgs);
            */
            _merchelloContext.Services.GatewayProviderService.Save(payment);
            if (!authorizeResult.Payment.Success)
            {
                LogHelper.Error<PayPalApiController>("Payment is not authorized.", authorizeResult.Payment.Exception);
				_merchelloContext.Services.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, "PayPal: request capture authorization error: " + authorizeResult.Payment.Exception.Message, 0);
                return ShowError(authorizeResult.Payment.Exception.Message);
            }
			_merchelloContext.Services.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal: capture authorized", 0);

			// The basket can be empty
            var customerContext = new Merchello.Web.CustomerContext(this.UmbracoContext);
            var currentCustomer = customerContext.CurrentCustomer;
	        if (currentCustomer != null) {
				var basket = Merchello.Web.Workflow.Basket.GetBasket(currentCustomer);
				basket.Empty();
	        }

            // Capture
            var captureResult = paymentGatewayMethod.CapturePayment(invoice, payment, payment.Amount, null);
            if (!captureResult.Payment.Success)
            {
                LogHelper.Error<PayPalApiController>("Payment is not captured.", captureResult.Payment.Exception);
                return ShowError(captureResult.Payment.Exception.Message);
            }

            // redirect to Site
			var returnUrl = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.ReturnUrl);
            var response = Request.CreateResponse(HttpStatusCode.Moved);
            response.Headers.Location = new Uri(returnUrl.Replace("%INVOICE%", invoice.Key.ToString().EncryptWithMachineKey()));
            return response;
        }
开发者ID:drpeck,项目名称:Merchello,代码行数:59,代码来源:PayPalApiController.cs


示例13: ErrorPage

 public ErrorPage(Server server, Request request, Exception e) {
     if (e == null)
         e = new NullReferenceException("Error page passed a null exception");
     this.exception = e;
     this.httpException = (e is HttpException) ? (HttpException)e : new HttpException(e);
     this.server = server;
     this.request = request;
 }
开发者ID:kevtham,项目名称:twin,代码行数:8,代码来源:ErrorPage.cs


示例14: NullReferenceException_Ctor_String_Exception

        public static void NullReferenceException_Ctor_String_Exception()
        {
            Exception ex = new Exception(innerExceptionMessage);
            NullReferenceException i = new NullReferenceException(exceptionMessage, ex);

            Assert.Equal(exceptionMessage, i.Message);
            Assert.Equal(i.InnerException.Message, innerExceptionMessage);
            Assert.Equal(i.InnerException.HResult, ex.HResult);
            Assert.Equal(E_POINTER, (uint)i.HResult);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:ExceptionTests.cs


示例15: Given

 protected override void Given()
 {
     base.Given();
     _caughtExceptions = new List<Exception>();
     _config = new CircuitBreakerConfig {ExpectedExceptionListType = ExceptionListType.BlackList};
     _config.ExpectedExceptionList.Add(typeof(ArgumentNullException));
     _circuitBreaker = new CircuitBreaker(_config);
     _circuitBreaker.ToleratedOpenCircuitBreaker += (sender, args) => _toleratedOpenEventFired = true;
     _thrownException = new NullReferenceException();
 }
开发者ID:RokitSalad,项目名称:Helpful.CircuitBreaker,代码行数:10,代码来源:when_receiving_exceptions_not_in_the_blacklist_within_tolerance.cs


示例16: LogException_SHOULD_log_with_severity_Error

        public void LogException_SHOULD_log_with_severity_Error()
        {
            var dummyException = new NullReferenceException();
            var fakeWriter = new Mock<ILogWriter>();

            var sut = new Logger(fakeWriter.Object);
            sut.LogException(dummyException);

            fakeWriter.Verify(m => m.Write(Match.Create<LogEntry>(e => e.Severity == Severity.Error)));
        }
开发者ID:robert-skarzycki,项目名称:skarzycki.robert.opensource,代码行数:10,代码来源:LoggerTests.cs


示例17: Given

 protected override void Given()
 {
     base.Given();
     _config = new CircuitBreakerConfig
     {
         ExpectedExceptionListType = ExceptionListType.BlackList
     };
     _config.ExpectedExceptionList.Add(typeof(ArgumentNullException));
     _circuitBreaker = new CircuitBreaker(_config);
     _thrownException = new NullReferenceException();
 }
开发者ID:RokitSalad,项目名称:Helpful.CircuitBreaker,代码行数:11,代码来源:when_permitted_exception_pass_through_is_set_to_pass_through.cs


示例18: ReturnFalseGivenExceptionIsNotOfType

		public void ReturnFalseGivenExceptionIsNotOfType()
		{
			// Arrange
			var exception = new NullReferenceException();

			// Act
			var isOfType = exception.IsOrContainsExceptionOfType<NotImplementedException>();

			// Assert
			Assert.IsFalse(isOfType);
		}
开发者ID:KaraokeStu,项目名称:LeadPipe.Net,代码行数:11,代码来源:IsOrContainsExceptionOfTypeShould.cs


示例19: ReturnNullGivenExceptionIsNotOfType

		public void ReturnNullGivenExceptionIsNotOfType()
		{
			// Arrange
			var exception = new NullReferenceException();

			// Act
			var returnedException = exception.GetFirstExceptionOfType<NotImplementedException>();

			// Assert
			Assert.IsTrue(returnedException == null);
		}
开发者ID:KaraokeStu,项目名称:LeadPipe.Net,代码行数:11,代码来源:GetFirstExceptionOfTypeShould.cs


示例20: TypePropertiesAreCorrect

		public void TypePropertiesAreCorrect() {
			Assert.AreEqual(typeof(NullReferenceException).FullName, "ss.NullReferenceException", "Name");
			Assert.IsTrue(typeof(NullReferenceException).IsClass, "IsClass");
			Assert.AreEqual(typeof(NullReferenceException).BaseType, typeof(Exception), "BaseType");
			object d = new NullReferenceException();
			Assert.IsTrue(d is NullReferenceException, "is NullReferenceException");
			Assert.IsTrue(d is Exception, "is Exception");

			var interfaces = typeof(NullReferenceException).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 0, "Interfaces length");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:11,代码来源:NullReferenceExceptionTests.cs



注:本文中的System.NullReferenceException类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# System.Number类代码示例发布时间:2022-05-26
下一篇:
C# System.NotSupportedException类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap