当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentException.ToString方法代码示例

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


在下文中一共展示了ArgumentException.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Verify_Log_ExceptionOverload

        public void Verify_Log_ExceptionOverload()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            string theTestMessage = string.Format(TEST_MESSAGE, random.Next(10000)); // a message with a unique-enough number in it, so we can identify it when we look for entries we have written
            Exception theException = new ArgumentException(theTestMessage);

            Logging.LogClient = EventLogMockFactory.GetEventLogMock().Instance;  // inject the mock event log into the logging class

            Logging.Log(ADMINISTRATIVE_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(ADMINISTRATIVE_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.Log(OPERATIONAL_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(OPERATIONAL_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.Log(ANALYTIC_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(ANALYTIC_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.Log(DEBUG_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(DEBUG_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.Log(APIUSAGE_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(APIUSAGE_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.Log(MAX_EVENT_ID, EventLogEntryType.Warning, EVENT_SOURCE_NAME, theException);
            CheckNewLogEntry(MAX_EVENT_ID, EVENT_SOURCE_NAME, theException.ToString());

            Logging.LogClient = null;  // reset the test injection
        }
开发者ID:barbarossia,项目名称:CWF,代码行数:28,代码来源:LoggingTest.cs

示例2: CreateEntityWithPropertiesShouldGenerateValidEntity

		public void CreateEntityWithPropertiesShouldGenerateValidEntity()
		{
			var timestamp = new DateTimeOffset(2014, 12, 01, 18, 42, 20, 666, TimeSpan.FromHours(2));
			var exception = new ArgumentException("Some exceptional exception happened");
			var level = LogEventLevel.Information;
			var messageTemplate = "Template {Temp} {Prop}";
			var template = new MessageTemplateParser().Parse(messageTemplate);
			var properties = new List<LogEventProperty> {
				new LogEventProperty("Temp", new ScalarValue("Temporary")),
				new LogEventProperty("Prop", new ScalarValue("Property"))
			};
			var additionalRowKeyPostfix = "Some postfix";

			var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);

			var entity = AzureTableStorageEntityFactory.CreateEntityWithProperties(logEvent, null, additionalRowKeyPostfix);

			// Partition key
			var expectedPartitionKey = "0" + new DateTime(logEvent.Timestamp.Year, logEvent.Timestamp.Month, logEvent.Timestamp.Day, logEvent.Timestamp.Hour, logEvent.Timestamp.Minute, 0).Ticks;
			Assert.AreEqual(expectedPartitionKey, entity.PartitionKey);

			// Row Key
			var expectedRowKeyWithoutGuid = "Information|Template {Temp} {Prop}|Some postfix|";
			var rowKeyWithoutGuid = entity.RowKey.Substring(0, expectedRowKeyWithoutGuid.Length);
			var rowKeyGuid = entity.RowKey.Substring(expectedRowKeyWithoutGuid.Length);

			Assert.AreEqual(expectedRowKeyWithoutGuid, rowKeyWithoutGuid);
			Assert.DoesNotThrow(() => Guid.Parse(rowKeyGuid));
			Assert.AreEqual(Guid.Parse(rowKeyGuid).ToString(), rowKeyGuid);

			// Timestamp
			Assert.AreEqual(logEvent.Timestamp, entity.Timestamp);

			// Properties
			Assert.AreEqual(6, entity.Properties.Count);

			Assert.AreEqual(new EntityProperty(messageTemplate), entity.Properties["MessageTemplate"]);
			Assert.AreEqual(new EntityProperty("Information"), entity.Properties["Level"]);
			Assert.AreEqual(new EntityProperty("Template \"Temporary\" \"Property\""), entity.Properties["RenderedMessage"]);
			Assert.AreEqual(new EntityProperty(exception.ToString()), entity.Properties["Exception"]);
			Assert.AreEqual(new EntityProperty("Temporary"), entity.Properties["Temp"]);
			Assert.AreEqual(new EntityProperty("Property"), entity.Properties["Prop"]);
		}
开发者ID:Sensarg22,项目名称:serilog-sinks-azuretablestorage,代码行数:43,代码来源:AzureTableStorageEntityFactoryTests.cs

示例3: ConvertCurrency

 public decimal ConvertCurrency(CurrencyType currencyHave,
     decimal currencyHaveAmount, CurrencyType currencyWant)
 {
     if (IsCurrencySupported(currencyHave) == false)
     {
         ArgumentException ex =
             new ArgumentException("Unsupported currency type", "currencyHave");
         Debug.WriteLine("***ERROR*** BreakingThroughToDotNetExample1.CurrencyConverter.ConvertCurrency Error: " + ex.ToString());
         throw ex;
     }
     else if(IsCurrencySupported(currencyWant) == false)
     {
         ArgumentException ex =
             new ArgumentException("Unsupported currency type", "currencyWant");
         Debug.WriteLine("***ERROR*** BreakingThroughToDotNetExample1.CurrencyConverter.ConvertCurrency Error: " + ex.ToString());
         throw ex;
     }
     else
     {
         decimal currencyWantAmount =
             currencyHaveAmount / GetCurrentExchangeRateAgainstUSD(currencyHave);
         currencyWantAmount *= GetCurrentExchangeRateAgainstUSD(currencyWant);
         return currencyWantAmount;
     }
 }
开发者ID:pvoelker,项目名称:BreakingThroughToDotNet,代码行数:25,代码来源:CurrencyConverter.cs

示例4: Add

        public GameTask Add(GameTask gameTask)
        {
            bool taskMatureTimeUnique = false;
            uint attempts = 0;

            while (taskMatureTimeUnique == false) {
                ArgumentException aex = new ArgumentException();

                if (this.Queue.ContainsKey(gameTask.MatureTime.Ticks)) {
                    taskMatureTimeUnique = false;
                } else {
                    taskMatureTimeUnique = true;

                    try {
                        Queue.Add(gameTask.MatureTime.Ticks, gameTask);
                    } catch (ArgumentException aexNew) {
                        MessageBox.Show("Failed to add task with key: '" + gameTask.MatureTime.Ticks + "'.");
                        aex = aexNew;
                    }
                }

                if (taskMatureTimeUnique == false) {
                    gameTask = gameTask.AddTicks(1);
                }

                attempts += 1;

                if (attempts > 500) {
                    MessageBox.Show("GameTaskQueue::Add(): Error adding task: " + aex.ToString());
                }
            }

            return gameTask;
        }
开发者ID:c0gent,项目名称:NeverClicker,代码行数:34,代码来源:TaskQueue.cs


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