Example #1
0
		private static string GetMessage(Type sourceType, Type destType, FailureReasonOptions failureReason, PropertyInfo destProperty)
		{
			if (sourceType == null)
				throw new ArgumentNullException("sourceType");
			if (destType == null)
				throw new ArgumentNullException("destType");

			string explanation;
			if (failureReason == FailureReasonOptions.NoParameterLessConstructor)
				explanation = "no parameter-less constructor available";
			else if (failureReason == FailureReasonOptions.UnableToMapProperty)
			{
				if (destProperty == null)
					throw new ArgumentException("destProperty may not be null if failureReason is UnableToMapProperty");
				explanation = "unable to map property \"" + destProperty.Name + "\"";
			}
			else
				throw new ArgumentOutOfRangeException("failureReason");

			return string.Format(
				"Unable to map type {0} to type {1} by property-setting, {2}",
				sourceType,
				destType,
				explanation
			);
		}
			public ConstructorOptionFailureDetails(ConstructorInfo constructor, FailureReasonOptions failureReason, ParameterInfo constructorArgumentWhereApplicable)
			{
				if (constructor == null)
					throw new ArgumentNullException("constructor");
				if (!Enum.IsDefined(typeof(FailureReasonOptions), failureReason))
					throw new ArgumentOutOfRangeException("failureReason");
				if ((failureReason == FailureReasonOptions.UnableToMapConstructorArgument) && (constructorArgumentWhereApplicable == null))
					throw new ArgumentException("constructorArgumentWhereApplicable must not be null if failureReason is UnableToMapConstructorArgument");
				if ((failureReason != FailureReasonOptions.UnableToMapConstructorArgument) && (constructorArgumentWhereApplicable != null))
					throw new ArgumentException("constructorArgumentWhereApplicable must be null if failureReason is anything other than UnableToMapConstructorArgument");

				Constructor = constructor;
				FailureReason = failureReason;
				ConstructorArgumentWhereApplicable = constructorArgumentWhereApplicable;
			}
Example #3
0
		public ByPropertyMappingFailureException(Type sourceType, Type destType, FailureReasonOptions failureReason, PropertyInfo destProperty)
			: base(GetMessage(sourceType, destType, failureReason, destProperty), sourceType, destType)
		{
			if (failureReason == FailureReasonOptions.NoParameterLessConstructor)
			{
				if (destProperty != null)
					throw new ArgumentException("destProperty must be null if failureReason is NoParameterLessConstructor");
			}
			else if (failureReason == FailureReasonOptions.UnableToMapProperty)
			{
				if (destProperty == null)
					throw new ArgumentException("destProperty must not be be null if failureReason is UnableToMapProperty");
			}
			else
				throw new ArgumentOutOfRangeException("failureReason");

			FailureReason = failureReason;
			DestProperty = destProperty;
		}