當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。