Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitCompositePrimaryKey C# (CSharp) Méthode

VisitCompositePrimaryKey() public méthode

Visits the composite primary key.
Validate that the composite key type is implementing GetHashCode() and Equals(), is mark serializable. Validate that the compose key is compose of two or more columns
public VisitCompositePrimaryKey ( CompositeKeyModel model ) : void
model CompositeKeyModel The model.
Résultat void
		public override void VisitCompositePrimaryKey(CompositeKeyModel model)
		{
			BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;

			Type compositeKeyClassType = model.Property.PropertyType;

			MethodInfo eq = null;
			MethodInfo hc = null;

			new List<MethodInfo>(compositeKeyClassType.GetMethods(flags)).ForEach(delegate(MethodInfo method)
					{
						if (method.Name.Equals("Equals"))
						{
							ParameterInfo[] parameters = method.GetParameters();

							if ((parameters.Length == 1) && (parameters[0].ParameterType == typeof(object)))
							{
								eq = method;
							}
						}
						else if (method.Name.Equals("GetHashCode"))
						{
							ParameterInfo[] parameters = method.GetParameters();

							if (parameters.Length == 0)
							{
								hc = method;
							}
						}
					});

			if (eq == null || hc == null)
			{
				throw new ActiveRecordException(String.Format("To use type '{0}' as a composite id, " +
				                                              "you must implement Equals and GetHashCode.",
				                                              model.Property.PropertyType.Name));
			}

			if (compositeKeyClassType.IsSerializable == false)
			{
				throw new ActiveRecordException(String.Format("To use type '{0}' as a composite id " +
				                                              "it must be marked as Serializable.", model.Property.PropertyType.Name));
			}

			int keyPropAttrCount = 0;

			PropertyInfo[] compositeKeyProps = compositeKeyClassType.GetProperties();

			foreach(PropertyInfo keyProp in compositeKeyProps)
			{
				if (keyProp.GetCustomAttributes(typeof(KeyPropertyAttribute), false).Length > 0)
				{
					keyPropAttrCount++;
				}
			}

			if (keyPropAttrCount < 2)
			{
				throw new ActiveRecordException(String.Format("To use type '{0}' as a composite " +
				                                              "id it must have two or more properties marked with the [KeyProperty] attribute.",
				                                              model.Property.PropertyType.Name));
			}
		}