// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool Xbim.CodeGeneration 
//  
//     Changes to this file may cause incorrect behaviour and will be lost if
//     the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------

using Xbim.Ifc4.Interfaces;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;

// ReSharper disable once CheckNamespace
namespace Xbim.Ifc2x3.Kernel
{
	public partial class @IfcRelDefinesByProperties : IIfcRelDefinesByProperties
	{

		[CrossSchemaAttribute(typeof(IIfcRelDefinesByProperties), 5)]
		IItemSet<IIfcObjectDefinition> IIfcRelDefinesByProperties.RelatedObjects 
		{ 
			get
			{
			
				return _relatedObjectsIfc4 ?? (_relatedObjectsIfc4 = new Common.Collections.ExtendedItemSet<IfcObject, IIfcObjectDefinition>(
                    RelatedObjects, 
                    new ItemSet<IIfcObjectDefinition>(this, 0, -5), 
					RelatedObjectsToIfc4, 
                    RelatedObjectsToIfc2X3));
			} 
		}

		//private field to hold any extended data
		private IItemSet<IIfcObjectDefinition> _relatedObjectsIfc4;
		//transformation function to convert/cast IFC2x3 data to appear as IFC4
		private static IIfcObjectDefinition RelatedObjectsToIfc4 (IfcObject member)
		{
			return member;
		}

		//transformation function to convert/cast IFC4 data to appear as IFC2x3 if possible
		private static IfcObject RelatedObjectsToIfc2X3 (IIfcObjectDefinition member){
			return member as IfcObject;
		}

		private  IIfcPropertySetDefinitionSelect _relatingPropertyDefinition4;


		[CrossSchemaAttribute(typeof(IIfcRelDefinesByProperties), 6)]
		IIfcPropertySetDefinitionSelect IIfcRelDefinesByProperties.RelatingPropertyDefinition 
		{ 
			get
			{
				return  _relatingPropertyDefinition4 ?? RelatingPropertyDefinition;
			} 
			set
			{
				if (value == null)
				{
					RelatingPropertyDefinition = null;
					if (_relatingPropertyDefinition4 != null)
						SetValue(v => _relatingPropertyDefinition4 = v, _relatingPropertyDefinition4, null, "RelatingPropertyDefinition", -6);
					return;
				}
				
				var val = value as IfcPropertySetDefinition;
				if (val != null)
				{
					RelatingPropertyDefinition = val;
					if (_relatingPropertyDefinition4 != null)
						SetValue(v => _relatingPropertyDefinition4 = v, _relatingPropertyDefinition4, null, "RelatingPropertyDefinition", -6);
					return;
				} 

				if(RelatingPropertyDefinition != null)
					RelatingPropertyDefinition = null;
				SetValue(v => _relatingPropertyDefinition4 = v, _relatingPropertyDefinition4, value, "RelatingPropertyDefinition", -6);
				
			}
		}
	//## Custom code
	//##
	}
}