// ------------------------------------------------------------------------------
// <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;

//## Custom using statements
//##

// ReSharper disable once CheckNamespace
namespace Xbim.Ifc4x3.PropertyResource
{
	public partial class @IfcPropertyReferenceValue : IIfcPropertyReferenceValue
	{

		[CrossSchemaAttribute(typeof(IIfcPropertyReferenceValue), 3)]
		Ifc4.MeasureResource.IfcText? IIfcPropertyReferenceValue.UsageName 
		{ 
			get
			{
				if (!UsageName.HasValue) return null;
				return new Ifc4.MeasureResource.IfcText(UsageName.Value);
			} 
			set
			{
				UsageName = value.HasValue ? 
					new MeasureResource.IfcText(value.Value) :  
					 new MeasureResource.IfcText?() ;
				
			}
		}

		private  IIfcObjectReferenceSelect _propertyReference4;


		[CrossSchemaAttribute(typeof(IIfcPropertyReferenceValue), 4)]
		IIfcObjectReferenceSelect IIfcPropertyReferenceValue.PropertyReference 
		{ 
			get
			{
				if (_propertyReference4 != null) return _propertyReference4;
				if (PropertyReference == null) return null;
				var ifcaddress = PropertyReference as ActorResource.IfcAddress;
				if (ifcaddress != null) 
					return ifcaddress;
				var ifcappliedvalue = PropertyReference as CostResource.IfcAppliedValue;
				if (ifcappliedvalue != null) 
					return ifcappliedvalue;
				var ifcexternalreference = PropertyReference as ExternalReferenceResource.IfcExternalReference;
				if (ifcexternalreference != null) 
					return ifcexternalreference;
				var ifcmaterialdefinition = PropertyReference as MaterialResource.IfcMaterialDefinition;
				if (ifcmaterialdefinition != null) 
					return ifcmaterialdefinition;
				var ifcorganization = PropertyReference as ActorResource.IfcOrganization;
				if (ifcorganization != null) 
					return ifcorganization;
				var ifcperson = PropertyReference as ActorResource.IfcPerson;
				if (ifcperson != null) 
					return ifcperson;
				var ifcpersonandorganization = PropertyReference as ActorResource.IfcPersonAndOrganization;
				if (ifcpersonandorganization != null) 
					return ifcpersonandorganization;
				var ifctable = PropertyReference as UtilityResource.IfcTable;
				if (ifctable != null) 
					return ifctable;
				var ifctimeseries = PropertyReference as DateTimeResource.IfcTimeSeries;
				if (ifctimeseries != null) 
					return ifctimeseries;
				return null;
			} 
			set
			{
				if (value == null)
				{
					PropertyReference = null;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}	
				var ifcaddress = value as ActorResource.IfcAddress;
				if (ifcaddress != null) 
				{
					PropertyReference = ifcaddress;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcappliedvalue = value as CostResource.IfcAppliedValue;
				if (ifcappliedvalue != null) 
				{
					PropertyReference = ifcappliedvalue;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcexternalreference = value as ExternalReferenceResource.IfcExternalReference;
				if (ifcexternalreference != null) 
				{
					PropertyReference = ifcexternalreference;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcmaterialdefinition = value as MaterialResource.IfcMaterialDefinition;
				if (ifcmaterialdefinition != null) 
				{
					PropertyReference = ifcmaterialdefinition;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcorganization = value as ActorResource.IfcOrganization;
				if (ifcorganization != null) 
				{
					PropertyReference = ifcorganization;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcperson = value as ActorResource.IfcPerson;
				if (ifcperson != null) 
				{
					PropertyReference = ifcperson;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifcpersonandorganization = value as ActorResource.IfcPersonAndOrganization;
				if (ifcpersonandorganization != null) 
				{
					PropertyReference = ifcpersonandorganization;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifctable = value as UtilityResource.IfcTable;
				if (ifctable != null) 
				{
					PropertyReference = ifctable;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				var ifctimeseries = value as DateTimeResource.IfcTimeSeries;
				if (ifctimeseries != null) 
				{
					PropertyReference = ifctimeseries;
					if (_propertyReference4 != null)
						SetValue(v => _propertyReference4 = v, _propertyReference4, null, "PropertyReference", -4);
					return;
				}
				
			}
		}
	//## Custom code
	//##
	}
}