diff Source/Mapping/Association.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Mapping/Association.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,52 @@
+using System;
+
+using JNotNull = JetBrains.Annotations.NotNullAttribute;
+
+namespace BLToolkit.Mapping
+{
+	using Common;
+	using Reflection;
+
+	public class Association
+	{
+		public Association(
+			[JNotNull] MemberAccessor memberAccessor,
+			[JNotNull] string[]       thisKey,
+			[JNotNull] string[]       otherKey,
+			           string         storage,
+			           bool           canBeNull)
+		{
+			if (memberAccessor == null) throw new ArgumentNullException("memberAccessor");
+			if (thisKey        == null) throw new ArgumentNullException("thisKey");
+			if (otherKey       == null) throw new ArgumentNullException("otherKey");
+
+			if (thisKey.Length == 0)
+				throw new ArgumentOutOfRangeException(
+					"thisKey",
+					string.Format("Association '{0}.{1}' does not define keys.", memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
+
+			if (thisKey.Length != otherKey.Length)
+				throw new ArgumentException(
+					string.Format(
+						"Association '{0}.{1}' has different number of keys for parent and child objects.",
+						memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
+
+			MemberAccessor = memberAccessor;
+			ThisKey        = thisKey;
+			OtherKey       = otherKey;
+			Storage        = storage;
+			CanBeNull      = canBeNull;
+		}
+
+		public MemberAccessor MemberAccessor { get; set; }
+		public string[]       ThisKey        { get; set; }
+		public string[]       OtherKey       { get; set; }
+		public string         Storage        { get; set; }
+		public bool           CanBeNull      { get; set; }
+
+		public static string[] ParseKeys(string keys)
+		{
+			return keys == null ? Array<string>.Empty : keys.Replace(" ", "").Split(',');
+		}
+	}
+}