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


C# IScope.Error方法代码示例

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


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

示例1: FireErrors

 public static void FireErrors(IScope t)
 {
     t.Error("ErrA");
     using (var scope = t.Create("Nested"))
     {
         scope.Error("ErrB");
     }
     t.Error("ErrC");
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:9,代码来源:ScopeTestHelper.cs

示例2: ProgramRules

 public static void ProgramRules(Program program, IScope scope)
 {
     // custom logic
     if (!program.Active) scope.Error("Program must be active");
     // passing member validation down to the next ruleset
     // (note, that we have multiple rulesets here)
     scope.Validate(program.Name, "Name", NameRules, SanitationRules);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:8,代码来源:BusinessRules.cs

示例3: Ncca_Is_Used_Properly

        static void Ncca_Is_Used_Properly(Codebase codebase, IScope scope, int maxInstructions)
        {
            var methods = codebase.Methods
                .Where(m => m.HasBody && m.Body.Instructions.Count > maxInstructions)
                .Where(m => m.Has<NoCodeCoverageAttribute>() ||
                    m.DeclaringType.Has<NoCodeCoverageAttribute>());

            foreach (var method in methods)
            {
                scope.Error("Method is too complex to be marked with NCCA: {0}", method);
            }
        }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:12,代码来源:MaintainabilityRules.cs

示例4: Immutable_Types_Should_Be_Immutable

        /// <summary>
        /// Ensures that classes marked with <see cref="ImmutableAttribute"/> have only
        /// readonly fields
        /// </summary>
        /// <param name="codebase">The codebase to run against.</param>
        /// <param name="scope">The scope to report to.</param>
        public static void Immutable_Types_Should_Be_Immutable(Codebase codebase, IScope scope)
        {
            var decorated = codebase.Types
                .Where(t => t.Has<ImmutableAttribute>());

            var failing = decorated
                .Where(t => t.GetAllFields(codebase)
                    .Count(f => !f.IsInitOnly && !f.IsStatic) > 0);

            foreach (var definition in failing)
            {
                scope.Error("Type should be immutable: {0}", definition);
            }
        }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:20,代码来源:MaintainabilityRules.cs

示例5: ProgramsRules

 public static void ProgramsRules(Program[] programs, IScope scope)
 {
     // Validating items of a collection
     if (programs.Length > 2500)
     {
         scope.Error("Only 2500 programs are allowed");
     }
     else
     {
         // every item will be validated (or only till the first exception hits,
         // that's for the scope to decide
         scope.ValidateInScope(programs, ProgramRules);
     }
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:14,代码来源:BusinessRules.cs

示例6: TestSimpleEquality

		static bool TestSimpleEquality(IScope scope, object expected, object actual)
		{
			var result = expected.Equals(actual);
			if (!result)
			{
				scope.Error("Object equality failed. Expected '{0}' was '{1}'.", expected, actual);
			}
			return result;
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:9,代码来源:TestModelEqualityBuilder.cs

示例7: TestGenericEquality

		static bool TestGenericEquality(IScope scope, MethodInfo info, object expected, object actual)
		{
			var o = info.Invoke(expected, new[] {actual});
			var result = Convert.ToBoolean(o);
			if (!result)
			{
				scope.Error("Expected IEquatable<T> '{0}' was '{1}'.", expected, actual);
			}
			return result;
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:10,代码来源:TestModelEqualityBuilder.cs

示例8: TestCollectionEquality

		bool TestCollectionEquality(IScope scope, IEnumerable expected, IEnumerable actual, int count1, int count2)
		{
			if (count1 != count2)
			{
				scope.Error("Expected ICollection count {0} was {1}", count1, count2);
				return false;
			}

			if (count1 == 0)
			{
				return true;
			}

			var e1 = expected.GetEnumerator();
			var e2 = actual.GetEnumerator();

			bool equals = true;

			for (int i = 0; i < count1; i++)
			{
				e1.MoveNext();
				e2.MoveNext();

				using (var child = scope.Create("[" + i + "]"))
				{
					bool result;
					if (TryReferenceCheck(child, e1.Current, e2.Current, out result))
					{
						equals |= result;
					}
					else
					{
						var t1 = e1.Current.GetType();
						var t2 = e2.Current.GetType();

						if (t1 != t2)
						{
							scope.Error("Expected '{0}' was '{1}'", t1, t2);
							equals = false;
						}
						else
						{
							var tester = _provider.GetEqualityTester(t1);

							if (!tester(child, t1, e1.Current, e2.Current))
							{
								equals = false;
							}
						}
					}
				}
			}
			return equals;
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:54,代码来源:TestModelEqualityBuilder.cs

示例9: TryReferenceCheck

		static bool TryReferenceCheck(IScope scope, object expected, object actual, out bool result)
		{
			var expectedIsNull = ReferenceEquals(expected, null);
			var actualIsNull = ReferenceEquals(actual, null);
			if (expectedIsNull && actualIsNull)
			{
				result = true;
				return true;
			}

			if (expectedIsNull || actualIsNull)
			{
				var expectedString = expectedIsNull ? "<null>" : expected.GetType().Name;
				var actualString = actualIsNull ? "<null>" : actual.GetType().Name;

				result = false;
				scope.Error("Expected {0} was {1}", expectedString, actualString);
				return true;
			}
			result = false;
			return false;
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:22,代码来源:TestModelEqualityBuilder.cs

示例10: SqlCompatible

 /// <summary>
 /// Verifies that it is ok to send this date directly into the MS SQL DB
 /// </summary>
 /// <param name="dateTime">The dateTime to validate.</param>
 /// <param name="scope">validation scope</param>
 public static void SqlCompatible(DateTime dateTime, IScope scope)
 {
     if (dateTime < SqlMinDateTime)
         scope.Error("Date must be greater than \'{0}\'.", SqlMinDateTime);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:10,代码来源:DateIs.cs

示例11: Valid

 /// <summary>
 /// Checks if the specified double is valid.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="scope">The scope.</param>
 public static void Valid(double value, IScope scope)
 {
     if (Double.IsNaN(value) || Double.IsInfinity(value))
         scope.Error("Double should represent a valid value.");
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:10,代码来源:DoubleIs.cs

示例12: ValidServerConnection

		/// <summary>
		/// Determines whether the string is valid server connection (with optional port)
		/// </summary>
		/// <param name="host">The host name to validate.</param>
		/// <param name="scope">The validation scope.</param>
		public static void ValidServerConnection(string host, IScope scope)
		{
			if (!ServerConnectionRegex.IsMatch(host))
				scope.Error("String should be a valid host name.");
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:10,代码来源:StringIs.cs

示例13: ValidEmail

		/// <summary>
		/// Determines whether the string is valid email address
		/// </summary>
		/// <param name="email">string to validate</param>
		/// <param name="scope">validation scope.</param>
		public static void ValidEmail(string email, IScope scope)
		{
			if (!EmailRegex.IsMatch(email))
				scope.Error("String should be a valid email address.");
		}
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:10,代码来源:StringIs.cs

示例14: SanitationRules

 public static void SanitationRules(string value, IScope scope)
 {
     if (value.Contains("-")) scope.Error("Can not contain '-'");
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:4,代码来源:BusinessRules.cs

示例15: NameRules

 // actual rules.
 // we assume that good citizenship is enforced (no need to check for nulls)
 public static void NameRules(string value, IScope scope)
 {
     // rules are plain .NET code
     if (value.Length == 0) scope.Error("String can not be empty");
     if (value.Length > 2500) scope.Error("Length must be less than 2500");
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:8,代码来源:BusinessRules.cs


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