Ejemplo n.º 1
0
        private static void DemandNotNullInternal([AssertionCondition(AssertionConditionType.IS_NOT_NULL)] object value, string message, object owner, int skipStackFrames, string uniqueId)
        {
            if (value != null)
            {
                return;
            }

            string propertyName;
            var    methodBase = new StackFrame(skipStackFrames + 1).GetMethod();

            if (methodBase.IsSpecialName && (methodBase.Name.StartsWith("Get_") || methodBase.Name.StartsWith("Get_")))
            {
                propertyName = methodBase.Name.Substring(4);
            }
            else
            {
                propertyName = methodBase.Name;
            }

            throw new InvalidOperationException(
                      (message == null ? "Value cannot be null!": DebugUtil.Indent2(message)) +
                      (owner == null ? "":DebugUtil.P("Declaring Type: ", () => (owner is Type?((Type)owner).FullName:owner.GetType().FullName))) +
                      (propertyName == null ? "":DebugUtil.P("Property Name", propertyName)) +
                      (uniqueId == null ? "":DebugUtil.P("UniqueID", uniqueId))
                      );
        }
Ejemplo n.º 2
0
 public static void DemandWrite([AssertionCondition(AssertionConditionType.IS_TRUE)] bool canWrite, string message, object owner, string propertyName, string uniqueId)
 {
     if (!canWrite)
     {
         throw new InvalidOperationException(
                   (message == null ? "Property is wite protected!": DebugUtil.Indent2(message)) +
                   (owner == null ? "":"\r\n\t" + "Declaring Type: " + (owner is Type?((Type)owner).FullName:owner.GetType().FullName)) +
                   (propertyName == null ? "":"\r\n\t" + "Property Name: " + propertyName) +
                   (uniqueId == null ? "":"\r\n\t" + "UniqueID: " + uniqueId)
                   );
     }
 }
Ejemplo n.º 3
0
 public static void DemandNotNull([AssertionCondition(AssertionConditionType.IS_NOT_NULL)] object value, string message, object owner, string propertyName, string uniqueId)
 {
     if (value == null)
     {
         throw new InvalidOperationException(
                   (message == null ? "Value must not be null!": DebugUtil.Indent2(message)) +
                   (owner == null ? "":DebugUtil.P("Declaring Type", () => (owner is Type?((Type)owner).FullName:owner.GetType().FullName))) +
                   (propertyName == null ? "":DebugUtil.P("Property Name", propertyName)) +
                   (uniqueId == null ? "":DebugUtil.P("UniqueID", uniqueId))
                   );
     }
 }
Ejemplo n.º 4
0
 public static void DemandWriteOnce([AssertionCondition(AssertionConditionType.IS_TRUE)] bool canWrite, string message, object owner, string propertyName, string uniqueId)
 {
     //NOTE: do not change default parameter values!
     if (!canWrite)
     {
         throw new InvalidOperationException(
                   (message == null ? "Property already initialized!": DebugUtil.Indent2(message)) +
                   DebugUtil.P(owner != null, "Declaring Type", DebugUtil.FormatTypeName(owner)) +
                   DebugUtil.P(propertyName != null, "Property Name", propertyName) +
                   DebugUtil.P(uniqueId != null, "UniqueID", uniqueId)
                   );
     }
 }