text:
using NMF.Collections.Generic;
using NMF.Collections.ObjectModel;
using NMF.Expressions;
using NMF.Expressions.Linq;
using NMF.Models;
using NMF.Models.Collections;
using NMF.Models.Expressions;
using NMF.Models.Meta;
using NMF.Models.Repository;
using NMF.Serialization;
using NMF.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using TTC2017.SmartGrids.CIM.IEC61968.Common;
using TTC2017.SmartGrids.CIM.IEC61968.Metering;
using TTC2017.SmartGrids.CIM.IEC61968.PaymentMetering;
using TTC2017.SmartGrids.CIM.IEC61968.Work;
using TTC2017.SmartGrids.CIM.IEC61970.Core;
using TTC2017.SmartGrids.CIM.IEC61970.Informative.InfCustomers;
using TTC2017.SmartGrids.CIM.IEC61970.Informative.InfERPSupport;
using TTC2017.SmartGrids.CIM.IEC61970.Informative.InfOperations;
using TTC2017.SmartGrids.CIM.IEC61970.Informative.InfPaymentMetering;

namespace TTC2017.SmartGrids.CIM.IEC61968.Customers
{

    /// <summary>
    /// The default implementation of the CustomerAgreement class
    /// </summary>
    [XmlNamespaceAttribute("http://iec.ch/TC57/2009/CIM-schema-cim14#Customers")]
    [XmlNamespacePrefixAttribute("cimCustomers")]
    [ModelRepresentationClassAttribute("http://iec.ch/TC57/2009/CIM-schema-cim14#//IEC61968/Customers/CustomerAgreement")]
    [DebuggerDisplayAttribute("CustomerAgreement {UUID}")]
    public partial class CustomerAgreement : Agreement, ICustomerAgreement, IModelElement
    {

        /// <summary>
        /// The backing field for the BillingCycle property
        /// </summary>
        private string _billingCycle;

        private static Lazy<ITypedElement> _billingCycleAttribute = new Lazy<ITypedElement>(RetrieveBillingCycleAttribute);

        /// <summary>
        /// The backing field for the LoadMgmt property
        /// </summary>
        private string _loadMgmt;

        private static Lazy<ITypedElement> _loadMgmtAttribute = new Lazy<ITypedElement>(RetrieveLoadMgmtAttribute);

        /// <summary>
        /// The backing field for the BudgetBill property
        /// </summary>
        private string _budgetBill;

        private static Lazy<ITypedElement> _budgetBillAttribute = new Lazy<ITypedElement>(RetrieveBudgetBillAttribute);

        private static Lazy<ITypedElement> _serviceSupplierReference = new Lazy<ITypedElement>(RetrieveServiceSupplierReference);

        /// <summary>
        /// The backing field for the ServiceSupplier property
        /// </summary>
        private IServiceSupplier _serviceSupplier;

        private static Lazy<ITypedElement> _standardIndustryCodeReference = new Lazy<ITypedElement>(RetrieveStandardIndustryCodeReference);

        /// <summary>
        /// The backing field for the StandardIndustryCode property
        /// </summary>
        private IStandardIndustryCode _standardIndustryCode;

        private static Lazy<ITypedElement> _serviceDeliveryPointsReference = new Lazy<ITypedElement>(RetrieveServiceDeliveryPointsReference);

        /// <summary>
        /// The backing field for the ServiceDeliveryPoints property
        /// </summary>
        private CustomerAgreementServiceDeliveryPointsCollection _serviceDeliveryPoints;

        private static Lazy<ITypedElement> _meterReadingsReference = new Lazy<ITypedElement>(RetrieveMeterReadingsReference);

        /// <summary>
        /// The backing field for the MeterReadings property
        /// </summary>
        private CustomerAgreementMeterReadingsCollection _meterReadings;

        private static Lazy<ITypedElement> _serviceLocationsReference = new Lazy<ITypedElement>(RetrieveServiceLocationsReference);

        /// <summary>
        /// The backing field for the ServiceLocations property
        /// </summary>
        private CustomerAgreementServiceLocationsCollection _serviceLocations;

        private static Lazy<ITypedElement> _pricingStructuresReference = new Lazy<ITypedElement>(RetrievePricingStructuresReference);

        /// <summary>
        /// The backing field for the PricingStructures property
        /// </summary>
        private CustomerAgreementPricingStructuresCollection _pricingStructures;

        private static Lazy<ITypedElement> _auxiliaryAgreementsReference = new Lazy<ITypedElement>(RetrieveAuxiliaryAgreementsReference);

        /// <summary>
        /// The backing field for the AuxiliaryAgreements property
        /// </summary>
        private CustomerAgreementAuxiliaryAgreementsCollection _auxiliaryAgreements;

        private static Lazy<ITypedElement> _endDeviceControlsReference = new Lazy<ITypedElement>(RetrieveEndDeviceControlsReference);

        /// <summary>
        /// The backing field for the EndDeviceControls property
        /// </summary>
        private CustomerAgreementEndDeviceControlsCollection _endDeviceControls;

        private static Lazy<ITypedElement> _customerReference = new Lazy<ITypedElement>(RetrieveCustomerReference);

        /// <summary>
        /// The backing field for the Customer property
        /// </summary>
        private ICustomer _customer;

        private static Lazy<ITypedElement> _serviceCategoryReference = new Lazy<ITypedElement>(RetrieveServiceCategoryReference);

        /// <summary>
        /// The backing field for the ServiceCategory property
        /// </summary>
        private IServiceCategory _serviceCategory;

        private static Lazy<ITypedElement> _customerAccountReference = new Lazy<ITypedElement>(RetrieveCustomerAccountReference);

        /// <summary>
        /// The backing field for the CustomerAccount property
        /// </summary>
        private ICustomerAccount _customerAccount;

        private static Lazy<ITypedElement> _demandResponseProgramReference = new Lazy<ITypedElement>(RetrieveDemandResponseProgramReference);

        /// <summary>
        /// The backing field for the DemandResponseProgram property
        /// </summary>
        private IDemandResponseProgram _demandResponseProgram;

        private static Lazy<ITypedElement> _equipmentsReference = new Lazy<ITypedElement>(RetrieveEquipmentsReference);

        /// <summary>
        /// The backing field for the Equipments property
        /// </summary>
        private CustomerAgreementEquipmentsCollection _equipments;

        private static IClass _classInstance;

        public CustomerAgreement()
        {
            this._serviceDeliveryPoints = new CustomerAgreementServiceDeliveryPointsCollection(this);
            this._serviceDeliveryPoints.CollectionChanging += this.ServiceDeliveryPointsCollectionChanging;
            this._serviceDeliveryPoints.CollectionChanged += this.ServiceDeliveryPointsCollectionChanged;
            this._meterReadings = new CustomerAgreementMeterReadingsCollection(this);
            this._meterReadings.CollectionChanging += this.MeterReadingsCollectionChanging;
            this._meterReadings.CollectionChanged += this.MeterReadingsCollectionChanged;
            this._serviceLocations = new CustomerAgreementServiceLocationsCollection(this);
            this._serviceLocations.CollectionChanging += this.ServiceLocationsCollectionChanging;
            this._serviceLocations.CollectionChanged += this.ServiceLocationsCollectionChanged;
            this._pricingStructures = new CustomerAgreementPricingStructuresCollection(this);
            this._pricingStructures.CollectionChanging += this.PricingStructuresCollectionChanging;
            this._pricingStructures.CollectionChanged += this.PricingStructuresCollectionChanged;
            this._auxiliaryAgreements = new CustomerAgreementAuxiliaryAgreementsCollection(this);
            this._auxiliaryAgreements.CollectionChanging += this.AuxiliaryAgreementsCollectionChanging;
            this._auxiliaryAgreements.CollectionChanged += this.AuxiliaryAgreementsCollectionChanged;
            this._endDeviceControls = new CustomerAgreementEndDeviceControlsCollection(this);
            this._endDeviceControls.CollectionChanging += this.EndDeviceControlsCollectionChanging;
            this._endDeviceControls.CollectionChanged += this.EndDeviceControlsCollectionChanged;
            this._equipments = new CustomerAgreementEquipmentsCollection(this);
            this._equipments.CollectionChanging += this.EquipmentsCollectionChanging;
            this._equipments.CollectionChanged += this.EquipmentsCollectionChanged;
        }

        /// <summary>
        /// The billingCycle property
        /// </summary>
        [XmlElementNameAttribute("billingCycle")]
        [XmlAttributeAttribute(true)]
        public virtual string BillingCycle
        {
            get
            {
                return this._billingCycle;
            }
            set
            {
                if ((this._billingCycle != value))
                {
                    string old = this._billingCycle;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnBillingCycleChanging(e);
                    this.OnPropertyChanging("BillingCycle", e, _billingCycleAttribute);
                    this._billingCycle = value;
                    this.OnBillingCycleChanged(e);
                    this.OnPropertyChanged("BillingCycle", e, _billingCycleAttribute);
                }
            }
        }

        /// <summary>
        /// The loadMgmt property
        /// </summary>
        [XmlElementNameAttribute("loadMgmt")]
        [XmlAttributeAttribute(true)]
        public virtual string LoadMgmt
        {
            get
            {
                return this._loadMgmt;
            }
            set
            {
                if ((this._loadMgmt != value))
                {
                    string old = this._loadMgmt;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnLoadMgmtChanging(e);
                    this.OnPropertyChanging("LoadMgmt", e, _loadMgmtAttribute);
                    this._loadMgmt = value;
                    this.OnLoadMgmtChanged(e);
                    this.OnPropertyChanged("LoadMgmt", e, _loadMgmtAttribute);
                }
            }
        }

        /// <summary>
        /// The budgetBill property
        /// </summary>
        [XmlElementNameAttribute("budgetBill")]
        [XmlAttributeAttribute(true)]
        public virtual string BudgetBill
        {
            get
            {
                return this._budgetBill;
            }
            set
            {
                if ((this._budgetBill != value))
                {
                    string old = this._budgetBill;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnBudgetBillChanging(e);
                    this.OnPropertyChanging("BudgetBill", e, _budgetBillAttribute);
                    this._budgetBill = value;
                    this.OnBudgetBillChanged(e);
                    this.OnPropertyChanged("BudgetBill", e, _budgetBillAttribute);
                }
            }
        }

        /// <summary>
        /// The ServiceSupplier property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual IServiceSupplier ServiceSupplier
        {
            get
            {
                return this._serviceSupplier;
            }
            set
            {
                if ((this._serviceSupplier != value))
                {
                    IServiceSupplier old = this._serviceSupplier;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnServiceSupplierChanging(e);
                    this.OnPropertyChanging("ServiceSupplier", e, _serviceSupplierReference);
                    this._serviceSupplier = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetServiceSupplier;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetServiceSupplier;
                    }
                    this.OnServiceSupplierChanged(e);
                    this.OnPropertyChanged("ServiceSupplier", e, _serviceSupplierReference);
                }
            }
        }

        /// <summary>
        /// The StandardIndustryCode property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual IStandardIndustryCode StandardIndustryCode
        {
            get
            {
                return this._standardIndustryCode;
            }
            set
            {
                if ((this._standardIndustryCode != value))
                {
                    IStandardIndustryCode old = this._standardIndustryCode;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnStandardIndustryCodeChanging(e);
                    this.OnPropertyChanging("StandardIndustryCode", e, _standardIndustryCodeReference);
                    this._standardIndustryCode = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetStandardIndustryCode;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetStandardIndustryCode;
                    }
                    this.OnStandardIndustryCodeChanged(e);
                    this.OnPropertyChanged("StandardIndustryCode", e, _standardIndustryCodeReference);
                }
            }
        }

        /// <summary>
        /// The ServiceDeliveryPoints property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreement")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IServiceDeliveryPoint> ServiceDeliveryPoints
        {
            get
            {
                return this._serviceDeliveryPoints;
            }
        }

        /// <summary>
        /// The MeterReadings property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreement")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IMeterReading> MeterReadings
        {
            get
            {
                return this._meterReadings;
            }
        }

        /// <summary>
        /// The ServiceLocations property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IServiceLocation> ServiceLocations
        {
            get
            {
                return this._serviceLocations;
            }
        }

        /// <summary>
        /// The PricingStructures property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IPricingStructure> PricingStructures
        {
            get
            {
                return this._pricingStructures;
            }
        }

        /// <summary>
        /// The AuxiliaryAgreements property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreement")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IAuxiliaryAgreement> AuxiliaryAgreements
        {
            get
            {
                return this._auxiliaryAgreements;
            }
        }

        /// <summary>
        /// The EndDeviceControls property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreement")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IEndDeviceControl> EndDeviceControls
        {
            get
            {
                return this._endDeviceControls;
            }
        }

        /// <summary>
        /// The Customer property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual ICustomer Customer
        {
            get
            {
                return this._customer;
            }
            set
            {
                if ((this._customer != value))
                {
                    ICustomer old = this._customer;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnCustomerChanging(e);
                    this.OnPropertyChanging("Customer", e, _customerReference);
                    this._customer = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetCustomer;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetCustomer;
                    }
                    this.OnCustomerChanged(e);
                    this.OnPropertyChanged("Customer", e, _customerReference);
                }
            }
        }

        /// <summary>
        /// The ServiceCategory property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual IServiceCategory ServiceCategory
        {
            get
            {
                return this._serviceCategory;
            }
            set
            {
                if ((this._serviceCategory != value))
                {
                    IServiceCategory old = this._serviceCategory;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnServiceCategoryChanging(e);
                    this.OnPropertyChanging("ServiceCategory", e, _serviceCategoryReference);
                    this._serviceCategory = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetServiceCategory;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetServiceCategory;
                    }
                    this.OnServiceCategoryChanged(e);
                    this.OnPropertyChanged("ServiceCategory", e, _serviceCategoryReference);
                }
            }
        }

        /// <summary>
        /// The CustomerAccount property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual ICustomerAccount CustomerAccount
        {
            get
            {
                return this._customerAccount;
            }
            set
            {
                if ((this._customerAccount != value))
                {
                    ICustomerAccount old = this._customerAccount;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnCustomerAccountChanging(e);
                    this.OnPropertyChanging("CustomerAccount", e, _customerAccountReference);
                    this._customerAccount = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetCustomerAccount;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetCustomerAccount;
                    }
                    this.OnCustomerAccountChanged(e);
                    this.OnPropertyChanged("CustomerAccount", e, _customerAccountReference);
                }
            }
        }

        /// <summary>
        /// The DemandResponseProgram property
        /// </summary>
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        public virtual IDemandResponseProgram DemandResponseProgram
        {
            get
            {
                return this._demandResponseProgram;
            }
            set
            {
                if ((this._demandResponseProgram != value))
                {
                    IDemandResponseProgram old = this._demandResponseProgram;
                    ValueChangedEventArgs e = new ValueChangedEventArgs(old, value);
                    this.OnDemandResponseProgramChanging(e);
                    this.OnPropertyChanging("DemandResponseProgram", e, _demandResponseProgramReference);
                    this._demandResponseProgram = value;
                    if ((old != null))
                    {
                        old.CustomerAgreements.Remove(this);
                        old.Deleted -= this.OnResetDemandResponseProgram;
                    }
                    if ((value != null))
                    {
                        value.CustomerAgreements.Add(this);
                        value.Deleted += this.OnResetDemandResponseProgram;
                    }
                    this.OnDemandResponseProgramChanged(e);
                    this.OnPropertyChanged("DemandResponseProgram", e, _demandResponseProgramReference);
                }
            }
        }

        /// <summary>
        /// The Equipments property
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
        [XmlAttributeAttribute(true)]
        [XmlOppositeAttribute("CustomerAgreements")]
        [ConstantAttribute()]
        public virtual IOrderedSetExpression<IEquipment> Equipments
        {
            get
            {
                return this._equipments;
            }
        }

        /// <summary>
        /// Gets the referenced model elements of this model element
        /// </summary>
        public override IEnumerableExpression<IModelElement> ReferencedElements
        {
            get
            {
                return base.ReferencedElements.Concat(new CustomerAgreementReferencedElementsCollection(this));
            }
        }

        /// <summary>
        /// Gets the Class model for this type
        /// </summary>
        public new static IClass ClassInstance
        {
            get
            {
                if ((_classInstance == null))
                {
                    _classInstance = ((IClass)(MetaRepository.Instance.Resolve("http://iec.ch/TC57/2009/CIM-schema-cim14#//IEC61968/Customers/CustomerAgreement")));
                }
                return _classInstance;
            }
        }

        /// <summary>
        /// Gets fired before the BillingCycle property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> BillingCycleChanging;

        /// <summary>
        /// Gets fired when the BillingCycle property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> BillingCycleChanged;

        /// <summary>
        /// Gets fired before the LoadMgmt property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> LoadMgmtChanging;

        /// <summary>
        /// Gets fired when the LoadMgmt property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> LoadMgmtChanged;

        /// <summary>
        /// Gets fired before the BudgetBill property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> BudgetBillChanging;

        /// <summary>
        /// Gets fired when the BudgetBill property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> BudgetBillChanged;

        /// <summary>
        /// Gets fired before the ServiceSupplier property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> ServiceSupplierChanging;

        /// <summary>
        /// Gets fired when the ServiceSupplier property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> ServiceSupplierChanged;

        /// <summary>
        /// Gets fired before the StandardIndustryCode property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> StandardIndustryCodeChanging;

        /// <summary>
        /// Gets fired when the StandardIndustryCode property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> StandardIndustryCodeChanged;

        /// <summary>
        /// Gets fired before the Customer property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> CustomerChanging;

        /// <summary>
        /// Gets fired when the Customer property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> CustomerChanged;

        /// <summary>
        /// Gets fired before the ServiceCategory property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> ServiceCategoryChanging;

        /// <summary>
        /// Gets fired when the ServiceCategory property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> ServiceCategoryChanged;

        /// <summary>
        /// Gets fired before the CustomerAccount property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> CustomerAccountChanging;

        /// <summary>
        /// Gets fired when the CustomerAccount property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> CustomerAccountChanged;

        /// <summary>
        /// Gets fired before the DemandResponseProgram property changes its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> DemandResponseProgramChanging;

        /// <summary>
        /// Gets fired when the DemandResponseProgram property changed its value
        /// </summary>
        public event System.EventHandler<ValueChangedEventArgs> DemandResponseProgramChanged;

        private static ITypedElement RetrieveBillingCycleAttribute()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("billingCycle")));
        }

        /// <summary>
        /// Raises the BillingCycleChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnBillingCycleChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.BillingCycleChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the BillingCycleChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnBillingCycleChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.BillingCycleChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        private static ITypedElement RetrieveLoadMgmtAttribute()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("loadMgmt")));
        }

        /// <summary>
        /// Raises the LoadMgmtChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnLoadMgmtChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.LoadMgmtChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the LoadMgmtChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnLoadMgmtChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.LoadMgmtChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        private static ITypedElement RetrieveBudgetBillAttribute()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("budgetBill")));
        }

        /// <summary>
        /// Raises the BudgetBillChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnBudgetBillChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.BudgetBillChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the BudgetBillChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnBudgetBillChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.BudgetBillChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        private static ITypedElement RetrieveServiceSupplierReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("ServiceSupplier")));
        }

        /// <summary>
        /// Raises the ServiceSupplierChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnServiceSupplierChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.ServiceSupplierChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the ServiceSupplierChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnServiceSupplierChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.ServiceSupplierChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the ServiceSupplier property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetServiceSupplier(object sender, System.EventArgs eventArgs)
        {
            this.ServiceSupplier = null;
        }

        private static ITypedElement RetrieveStandardIndustryCodeReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("StandardIndustryCode")));
        }

        /// <summary>
        /// Raises the StandardIndustryCodeChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnStandardIndustryCodeChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.StandardIndustryCodeChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the StandardIndustryCodeChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnStandardIndustryCodeChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.StandardIndustryCodeChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the StandardIndustryCode property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetStandardIndustryCode(object sender, System.EventArgs eventArgs)
        {
            this.StandardIndustryCode = null;
        }

        private static ITypedElement RetrieveServiceDeliveryPointsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("ServiceDeliveryPoints")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the ServiceDeliveryPoints property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void ServiceDeliveryPointsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("ServiceDeliveryPoints", e, _serviceDeliveryPointsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the ServiceDeliveryPoints property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void ServiceDeliveryPointsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("ServiceDeliveryPoints", e, _serviceDeliveryPointsReference);
        }

        private static ITypedElement RetrieveMeterReadingsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("MeterReadings")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the MeterReadings property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void MeterReadingsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("MeterReadings", e, _meterReadingsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the MeterReadings property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void MeterReadingsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("MeterReadings", e, _meterReadingsReference);
        }

        private static ITypedElement RetrieveServiceLocationsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("ServiceLocations")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the ServiceLocations property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void ServiceLocationsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("ServiceLocations", e, _serviceLocationsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the ServiceLocations property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void ServiceLocationsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("ServiceLocations", e, _serviceLocationsReference);
        }

        private static ITypedElement RetrievePricingStructuresReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("PricingStructures")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the PricingStructures property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void PricingStructuresCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("PricingStructures", e, _pricingStructuresReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the PricingStructures property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void PricingStructuresCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("PricingStructures", e, _pricingStructuresReference);
        }

        private static ITypedElement RetrieveAuxiliaryAgreementsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("AuxiliaryAgreements")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the AuxiliaryAgreements property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void AuxiliaryAgreementsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("AuxiliaryAgreements", e, _auxiliaryAgreementsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the AuxiliaryAgreements property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void AuxiliaryAgreementsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("AuxiliaryAgreements", e, _auxiliaryAgreementsReference);
        }

        private static ITypedElement RetrieveEndDeviceControlsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("EndDeviceControls")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the EndDeviceControls property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void EndDeviceControlsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("EndDeviceControls", e, _endDeviceControlsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the EndDeviceControls property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void EndDeviceControlsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("EndDeviceControls", e, _endDeviceControlsReference);
        }

        private static ITypedElement RetrieveCustomerReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("Customer")));
        }

        /// <summary>
        /// Raises the CustomerChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnCustomerChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.CustomerChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the CustomerChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnCustomerChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.CustomerChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the Customer property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetCustomer(object sender, System.EventArgs eventArgs)
        {
            this.Customer = null;
        }

        private static ITypedElement RetrieveServiceCategoryReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("ServiceCategory")));
        }

        /// <summary>
        /// Raises the ServiceCategoryChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnServiceCategoryChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.ServiceCategoryChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the ServiceCategoryChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnServiceCategoryChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.ServiceCategoryChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the ServiceCategory property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetServiceCategory(object sender, System.EventArgs eventArgs)
        {
            this.ServiceCategory = null;
        }

        private static ITypedElement RetrieveCustomerAccountReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("CustomerAccount")));
        }

        /// <summary>
        /// Raises the CustomerAccountChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnCustomerAccountChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.CustomerAccountChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the CustomerAccountChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnCustomerAccountChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.CustomerAccountChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the CustomerAccount property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetCustomerAccount(object sender, System.EventArgs eventArgs)
        {
            this.CustomerAccount = null;
        }

        private static ITypedElement RetrieveDemandResponseProgramReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("DemandResponseProgram")));
        }

        /// <summary>
        /// Raises the DemandResponseProgramChanging event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnDemandResponseProgramChanging(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.DemandResponseProgramChanging;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Raises the DemandResponseProgramChanged event
        /// </summary>
        /// <param name="eventArgs">The event data</param>
        protected virtual void OnDemandResponseProgramChanged(ValueChangedEventArgs eventArgs)
        {
            System.EventHandler<ValueChangedEventArgs> handler = this.DemandResponseProgramChanged;
            if ((handler != null))
            {
                handler.Invoke(this, eventArgs);
            }
        }

        /// <summary>
        /// Handles the event that the DemandResponseProgram property must reset
        /// </summary>
        /// <param name="sender">The object that sent this reset request</param>
        /// <param name="eventArgs">The event data for the reset event</param>
        private void OnResetDemandResponseProgram(object sender, System.EventArgs eventArgs)
        {
            this.DemandResponseProgram = null;
        }

        private static ITypedElement RetrieveEquipmentsReference()
        {
            return ((ITypedElement)(((ModelElement)(CustomerAgreement.ClassInstance)).Resolve("Equipments")));
        }

        /// <summary>
        /// Forwards CollectionChanging notifications for the Equipments property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void EquipmentsCollectionChanging(object sender, NMF.Collections.ObjectModel.NotifyCollectionChangingEventArgs e)
        {
            this.OnCollectionChanging("Equipments", e, _equipmentsReference);
        }

        /// <summary>
        /// Forwards CollectionChanged notifications for the Equipments property to the parent model element
        /// </summary>
        /// <param name="sender">The collection that raised the change</param>
        /// <param name="e">The original event data</param>
        private void EquipmentsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.OnCollectionChanged("Equipments", e, _equipmentsReference);
        }

        /// <summary>
        /// Resolves the given attribute name
        /// </summary>
        /// <returns>The attribute value or null if it could not be found</returns>
        /// <param name="attribute">The requested attribute name</param>
        /// <param name="index">The index of this attribute</param>
        protected override object GetAttributeValue(string attribute, int index)
        {
            if ((attribute == "BILLINGCYCLE"))
            {
                return this.BillingCycle;
            }
            if ((attribute == "LOADMGMT"))
            {
                return this.LoadMgmt;
            }
            if ((attribute == "BUDGETBILL"))
            {
                return this.BudgetBill;
            }
            return base.GetAttributeValue(attribute, index);
        }

        /// <summary>
        /// Gets the Model element collection for the given feature
        /// </summary>
        /// <returns>A non-generic list of elements</returns>
        /// <param name="feature">The requested feature</param>
        protected override System.Collections.IList GetCollectionForFeature(string feature)
        {
            if ((feature == "SERVICEDELIVERYPOINTS"))
            {
                return this._serviceDeliveryPoints;
            }
            if ((feature == "METERREADINGS"))
            {
                return this._meterReadings;
            }
            if ((feature == "SERVICELOCATIONS"))
            {
                return this._serviceLocations;
            }
            if ((feature == "PRICINGSTRUCTURES"))
            {
                return this._pricingStructures;
            }
            if ((feature == "AUXILIARYAGREEMENTS"))
            {
                return this._auxiliaryAgreements;
            }
            if ((feature == "ENDDEVICECONTROLS"))
            {
                return this._endDeviceControls;
            }
            if ((feature == "EQUIPMENTS"))
            {
                return this._equipments;
            }
            return base.GetCollectionForFeature(feature);
        }

        /// <summary>
        /// Sets a value to the given feature
        /// </summary>
        /// <param name="feature">The requested feature</param>
        /// <param name="value">The value that should be set to that feature</param>
        protected override void SetFeature(string feature, object value)
        {
            if ((feature == "SERVICESUPPLIER"))
            {
                this.ServiceSupplier = ((IServiceSupplier)(value));
                return;
            }
            if ((feature == "STANDARDINDUSTRYCODE"))
            {
                this.StandardIndustryCode = ((IStandardIndustryCode)(value));
                return;
            }
            if ((feature == "CUSTOMER"))
            {
                this.Customer = ((ICustomer)(value));
                return;
            }
            if ((feature == "SERVICECATEGORY"))
            {
                this.ServiceCategory = ((IServiceCategory)(value));
                return;
            }
            if ((feature == "CUSTOMERACCOUNT"))
            {
                this.CustomerAccount = ((ICustomerAccount)(value));
                return;
            }
            if ((feature == "DEMANDRESPONSEPROGRAM"))
            {
                this.DemandResponseProgram = ((IDemandResponseProgram)(value));
                return;
            }
            if ((feature == "BILLINGCYCLE"))
            {
                this.BillingCycle = ((string)(value));
                return;
            }
            if ((feature == "LOADMGMT"))
            {
                this.LoadMgmt = ((string)(value));
                return;
            }
            if ((feature == "BUDGETBILL"))
            {
                this.BudgetBill = ((string)(value));
                return;
            }
            base.SetFeature(feature, value);
        }

        /// <summary>
        /// Gets the property expression for the given attribute
        /// </summary>
        /// <returns>An incremental property expression</returns>
        /// <param name="attribute">The requested attribute in upper case</param>
        protected override NMF.Expressions.INotifyExpression<object> GetExpressionForAttribute(string attribute)
        {
            if ((attribute == "ServiceSupplier"))
            {
                return new ServiceSupplierProxy(this);
            }
            if ((attribute == "StandardIndustryCode"))
            {
                return new StandardIndustryCodeProxy(this);
            }
            if ((attribute == "Customer"))
            {
                return new CustomerProxy(this);
            }
            if ((attribute == "ServiceCategory"))
            {
                return new ServiceCategoryProxy(this);
            }
            if ((attribute == "CustomerAccount"))
            {
                return new CustomerAccountProxy(this);
            }
            if ((attribute == "DemandResponseProgram"))
            {
                return new DemandResponseProgramProxy(this);
            }
            return base.GetExpressionForAttribute(attribute);
        }

        /// <summary>
        /// Gets the property expression for the given reference
        /// </summary>
        /// <returns>An incremental property expression</returns>
        /// <param name="reference">The requested reference in upper case</param>
        protected override NMF.Expressions.INotifyExpression<NMF.Models.IModelElement> GetExpressionForReference(string reference)
        {
            if ((reference == "ServiceSupplier"))
            {
                return new ServiceSupplierProxy(this);
            }
            if ((reference == "StandardIndustryCode"))
            {
                return new StandardIndustryCodeProxy(this);
            }
            if ((reference == "Customer"))
            {
                return new CustomerProxy(this);
            }
            if ((reference == "ServiceCategory"))
            {
                return new ServiceCategoryProxy(this);
            }
            if ((reference == "CustomerAccount"))
            {
                return new CustomerAccountProxy(this);
            }
            if ((reference == "DemandResponseProgram"))
            {
                return new DemandResponseProgramProxy(this);
            }
            return base.GetExpressionForReference(reference);
        }

        /// <summary>
        /// Gets the Class for this model element
        /// </summary>
        public override IClass GetClass()
        {
            if ((_classInstance == null))
            {
                _classInstance = ((IClass)(MetaRepository.Instance.Resolve("http://iec.ch/TC57/2009/CIM-schema-cim14#//IEC61968/Customers/CustomerAgreement")));
            }
            return _classInstance;
        }

        /// <summary>
        /// The collection class to to represent the children of the CustomerAgreement class
        /// </summary>
        public class CustomerAgreementReferencedElementsCollection : ReferenceCollection, ICollectionExpression<IModelElement>, ICollection<IModelElement>
        {

            private CustomerAgreement _parent;

            /// <summary>
            /// Creates a new instance
            /// </summary>
            public CustomerAgreementReferencedElementsCollection(CustomerAgreement parent)
            {
                this._parent = parent;
            }

            /// <summary>
            /// Gets the amount of elements contained in this collection
            /// </summary>
            public override int Count
            {
                get
                {
                    int count = 0;
                    if ((this._parent.ServiceSupplier != null))
                    {
                        count = (count + 1);
                    }
                    if ((this._parent.StandardIndustryCode != null))
                    {
                        count = (count + 1);
                    }
                    count = (count + this._parent.ServiceDeliveryPoints.Count);
                    count = (count + this._parent.MeterReadings.Count);
                    count = (count + this._parent.ServiceLocations.Count);
                    count = (count + this._parent.PricingStructures.Count);
                    count = (count + this._parent.AuxiliaryAgreements.Count);
                    count = (count + this._parent.EndDeviceControls.Count);
                    if ((this._parent.Customer != null))
                    {
                        count = (count + 1);
                    }
                    if ((this._parent.ServiceCategory != null))
                    {
                        count = (count + 1);
                    }
                    if ((this._parent.CustomerAccount != null))
                    {
                        count = (count + 1);
                    }
                    if ((this._parent.DemandResponseProgram != null))
                    {
                        count = (count + 1);
                    }
                    count = (count + this._parent.Equipments.Count);
                    return count;
                }
            }

            protected override void AttachCore()
            {
                this._parent.ServiceSupplierChanged += this.PropagateValueChanges;
                this._parent.StandardIndustryCodeChanged += this.PropagateValueChanges;
                this._parent.ServiceDeliveryPoints.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.MeterReadings.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.ServiceLocations.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.PricingStructures.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.AuxiliaryAgreements.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.EndDeviceControls.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
                this._parent.CustomerChanged += this.PropagateValueChanges;
                this._parent.ServiceCategoryChanged += this.PropagateValueChanges;
                this._parent.CustomerAccountChanged += this.PropagateValueChanges;
                this._parent.DemandResponseProgramChanged += this.PropagateValueChanges;
                this._parent.Equipments.AsNotifiable().CollectionChanged += this.PropagateCollectionChanges;
            }

            protected override void DetachCore()
            {
                this._parent.ServiceSupplierChanged -= this.PropagateValueChanges;
                this._parent.StandardIndustryCodeChanged -= this.PropagateValueChanges;
                this._parent.ServiceDeliveryPoints.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.MeterReadings.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.ServiceLocations.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.PricingStructures.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.AuxiliaryAgreements.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.EndDeviceControls.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
                this._parent.CustomerChanged -= this.PropagateValueChanges;
                this._parent.ServiceCategoryChanged -= this.PropagateValueChanges;
                this._parent.CustomerAccountChanged -= this.PropagateValueChanges;
                this._parent.DemandResponseProgramChanged -= this.PropagateValueChanges;
                this._parent.Equipments.AsNotifiable().CollectionChanged -= this.PropagateCollectionChanges;
            }

            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                if ((this._parent.ServiceSupplier == null))
                {
                    IServiceSupplier serviceSupplierCasted = item.As<IServiceSupplier>();
                    if ((serviceSupplierCasted != null))
                    {
                        this._parent.ServiceSupplier = serviceSupplierCasted;
                        return;
                    }
                }
                if ((this._parent.StandardIndustryCode == null))
                {
                    IStandardIndustryCode standardIndustryCodeCasted = item.As<IStandardIndustryCode>();
                    if ((standardIndustryCodeCasted != null))
                    {
                        this._parent.StandardIndustryCode = standardIndustryCodeCasted;
                        return;
                    }
                }
                IServiceDeliveryPoint serviceDeliveryPointsCasted = item.As<IServiceDeliveryPoint>();
                if ((serviceDeliveryPointsCasted != null))
                {
                    this._parent.ServiceDeliveryPoints.Add(serviceDeliveryPointsCasted);
                }
                IMeterReading meterReadingsCasted = item.As<IMeterReading>();
                if ((meterReadingsCasted != null))
                {
                    this._parent.MeterReadings.Add(meterReadingsCasted);
                }
                IServiceLocation serviceLocationsCasted = item.As<IServiceLocation>();
                if ((serviceLocationsCasted != null))
                {
                    this._parent.ServiceLocations.Add(serviceLocationsCasted);
                }
                IPricingStructure pricingStructuresCasted = item.As<IPricingStructure>();
                if ((pricingStructuresCasted != null))
                {
                    this._parent.PricingStructures.Add(pricingStructuresCasted);
                }
                IAuxiliaryAgreement auxiliaryAgreementsCasted = item.As<IAuxiliaryAgreement>();
                if ((auxiliaryAgreementsCasted != null))
                {
                    this._parent.AuxiliaryAgreements.Add(auxiliaryAgreementsCasted);
                }
                IEndDeviceControl endDeviceControlsCasted = item.As<IEndDeviceControl>();
                if ((endDeviceControlsCasted != null))
                {
                    this._parent.EndDeviceControls.Add(endDeviceControlsCasted);
                }
                if ((this._parent.Customer == null))
                {
                    ICustomer customerCasted = item.As<ICustomer>();
                    if ((customerCasted != null))
                    {
                        this._parent.Customer = customerCasted;
                        return;
                    }
                }
                if ((this._parent.ServiceCategory == null))
                {
                    IServiceCategory serviceCategoryCasted = item.As<IServiceCategory>();
                    if ((serviceCategoryCasted != null))
                    {
                        this._parent.ServiceCategory = serviceCategoryCasted;
                        return;
                    }
                }
                if ((this._parent.CustomerAccount == null))
                {
                    ICustomerAccount customerAccountCasted = item.As<ICustomerAccount>();
                    if ((customerAccountCasted != null))
                    {
                        this._parent.CustomerAccount = customerAccountCasted;
                        return;
                    }
                }
                if ((this._parent.DemandResponseProgram == null))
                {
                    IDemandResponseProgram demandResponseProgramCasted = item.As<IDemandResponseProgram>();
                    if ((demandResponseProgramCasted != null))
                    {
                        this._parent.DemandResponseProgram = demandResponseProgramCasted;
                        return;
                    }
                }
                IEquipment equipmentsCasted = item.As<IEquipment>();
                if ((equipmentsCasted != null))
                {
                    this._parent.Equipments.Add(equipmentsCasted);
                }
            }

            /// <summary>
            /// Clears the collection and resets all references that implement it.
            /// </summary>
            public override void Clear()
            {
                this._parent.ServiceSupplier = null;
                this._parent.StandardIndustryCode = null;
                this._parent.ServiceDeliveryPoints.Clear();
                this._parent.MeterReadings.Clear();
                this._parent.ServiceLocations.Clear();
                this._parent.PricingStructures.Clear();
                this._parent.AuxiliaryAgreements.Clear();
                this._parent.EndDeviceControls.Clear();
                this._parent.Customer = null;
                this._parent.ServiceCategory = null;
                this._parent.CustomerAccount = null;
                this._parent.DemandResponseProgram = null;
                this._parent.Equipments.Clear();
            }

            /// <summary>
            /// Gets a value indicating whether the given element is contained in the collection
            /// </summary>
            /// <returns>True, if it is contained, otherwise False</returns>
            /// <param name="item">The item that should be looked out for</param>
            public override bool Contains(IModelElement item)
            {
                if ((item == this._parent.ServiceSupplier))
                {
                    return true;
                }
                if ((item == this._parent.StandardIndustryCode))
                {
                    return true;
                }
                if (this._parent.ServiceDeliveryPoints.Contains(item))
                {
                    return true;
                }
                if (this._parent.MeterReadings.Contains(item))
                {
                    return true;
                }
                if (this._parent.ServiceLocations.Contains(item))
                {
                    return true;
                }
                if (this._parent.PricingStructures.Contains(item))
                {
                    return true;
                }
                if (this._parent.AuxiliaryAgreements.Contains(item))
                {
                    return true;
                }
                if (this._parent.EndDeviceControls.Contains(item))
                {
                    return true;
                }
                if ((item == this._parent.Customer))
                {
                    return true;
                }
                if ((item == this._parent.ServiceCategory))
                {
                    return true;
                }
                if ((item == this._parent.CustomerAccount))
                {
                    return true;
                }
                if ((item == this._parent.DemandResponseProgram))
                {
                    return true;
                }
                if (this._parent.Equipments.Contains(item))
                {
                    return true;
                }
                return false;
            }

            /// <summary>
            /// Copies the contents of the collection to the given array starting from the given array index
            /// </summary>
            /// <param name="array">The array in which the elements should be copied</param>
            /// <param name="arrayIndex">The starting index</param>
            public override void CopyTo(IModelElement[] array, int arrayIndex)
            {
                if ((this._parent.ServiceSupplier != null))
                {
                    array[arrayIndex] = this._parent.ServiceSupplier;
                    arrayIndex = (arrayIndex + 1);
                }
                if ((this._parent.StandardIndustryCode != null))
                {
                    array[arrayIndex] = this._parent.StandardIndustryCode;
                    arrayIndex = (arrayIndex + 1);
                }
                IEnumerator<IModelElement> serviceDeliveryPointsEnumerator = this._parent.ServiceDeliveryPoints.GetEnumerator();
                try
                {
                    for (
                    ; serviceDeliveryPointsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = serviceDeliveryPointsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    serviceDeliveryPointsEnumerator.Dispose();
                }
                IEnumerator<IModelElement> meterReadingsEnumerator = this._parent.MeterReadings.GetEnumerator();
                try
                {
                    for (
                    ; meterReadingsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = meterReadingsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    meterReadingsEnumerator.Dispose();
                }
                IEnumerator<IModelElement> serviceLocationsEnumerator = this._parent.ServiceLocations.GetEnumerator();
                try
                {
                    for (
                    ; serviceLocationsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = serviceLocationsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    serviceLocationsEnumerator.Dispose();
                }
                IEnumerator<IModelElement> pricingStructuresEnumerator = this._parent.PricingStructures.GetEnumerator();
                try
                {
                    for (
                    ; pricingStructuresEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = pricingStructuresEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    pricingStructuresEnumerator.Dispose();
                }
                IEnumerator<IModelElement> auxiliaryAgreementsEnumerator = this._parent.AuxiliaryAgreements.GetEnumerator();
                try
                {
                    for (
                    ; auxiliaryAgreementsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = auxiliaryAgreementsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    auxiliaryAgreementsEnumerator.Dispose();
                }
                IEnumerator<IModelElement> endDeviceControlsEnumerator = this._parent.EndDeviceControls.GetEnumerator();
                try
                {
                    for (
                    ; endDeviceControlsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = endDeviceControlsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    endDeviceControlsEnumerator.Dispose();
                }
                if ((this._parent.Customer != null))
                {
                    array[arrayIndex] = this._parent.Customer;
                    arrayIndex = (arrayIndex + 1);
                }
                if ((this._parent.ServiceCategory != null))
                {
                    array[arrayIndex] = this._parent.ServiceCategory;
                    arrayIndex = (arrayIndex + 1);
                }
                if ((this._parent.CustomerAccount != null))
                {
                    array[arrayIndex] = this._parent.CustomerAccount;
                    arrayIndex = (arrayIndex + 1);
                }
                if ((this._parent.DemandResponseProgram != null))
                {
                    array[arrayIndex] = this._parent.DemandResponseProgram;
                    arrayIndex = (arrayIndex + 1);
                }
                IEnumerator<IModelElement> equipmentsEnumerator = this._parent.Equipments.GetEnumerator();
                try
                {
                    for (
                    ; equipmentsEnumerator.MoveNext();
                    )
                    {
                        array[arrayIndex] = equipmentsEnumerator.Current;
                        arrayIndex = (arrayIndex + 1);
                    }
                }
                finally
                {
                    equipmentsEnumerator.Dispose();
                }
            }

            /// <summary>
            /// Removes the given item from the collection
            /// </summary>
            /// <returns>True, if the item was removed, otherwise False</returns>
            /// <param name="item">The item that should be removed</param>
            public override bool Remove(IModelElement item)
            {
                if ((this._parent.ServiceSupplier == item))
                {
                    this._parent.ServiceSupplier = null;
                    return true;
                }
                if ((this._parent.StandardIndustryCode == item))
                {
                    this._parent.StandardIndustryCode = null;
                    return true;
                }
                IServiceDeliveryPoint serviceDeliveryPointItem = item.As<IServiceDeliveryPoint>();
                if (((serviceDeliveryPointItem != null)
                            && this._parent.ServiceDeliveryPoints.Remove(serviceDeliveryPointItem)))
                {
                    return true;
                }
                IMeterReading meterReadingItem = item.As<IMeterReading>();
                if (((meterReadingItem != null)
                            && this._parent.MeterReadings.Remove(meterReadingItem)))
                {
                    return true;
                }
                IServiceLocation serviceLocationItem = item.As<IServiceLocation>();
                if (((serviceLocationItem != null)
                            && this._parent.ServiceLocations.Remove(serviceLocationItem)))
                {
                    return true;
                }
                IPricingStructure pricingStructureItem = item.As<IPricingStructure>();
                if (((pricingStructureItem != null)
                            && this._parent.PricingStructures.Remove(pricingStructureItem)))
                {
                    return true;
                }
                IAuxiliaryAgreement auxiliaryAgreementItem = item.As<IAuxiliaryAgreement>();
                if (((auxiliaryAgreementItem != null)
                            && this._parent.AuxiliaryAgreements.Remove(auxiliaryAgreementItem)))
                {
                    return true;
                }
                IEndDeviceControl endDeviceControlItem = item.As<IEndDeviceControl>();
                if (((endDeviceControlItem != null)
                            && this._parent.EndDeviceControls.Remove(endDeviceControlItem)))
                {
                    return true;
                }
                if ((this._parent.Customer == item))
                {
                    this._parent.Customer = null;
                    return true;
                }
                if ((this._parent.ServiceCategory == item))
                {
                    this._parent.ServiceCategory = null;
                    return true;
                }
                if ((this._parent.CustomerAccount == item))
                {
                    this._parent.CustomerAccount = null;
                    return true;
                }
                if ((this._parent.DemandResponseProgram == item))
                {
                    this._parent.DemandResponseProgram = null;
                    return true;
                }
                IEquipment equipmentItem = item.As<IEquipment>();
                if (((equipmentItem != null)
                            && this._parent.Equipments.Remove(equipmentItem)))
                {
                    return true;
                }
                return false;
            }

            /// <summary>
            /// Gets an enumerator that enumerates the collection
            /// </summary>
            /// <returns>A generic enumerator</returns>
            public override IEnumerator<IModelElement> GetEnumerator()
            {
                return Enumerable.Empty<IModelElement>().Concat(this._parent.ServiceSupplier).Concat(this._parent.StandardIndustryCode).Concat(this._parent.ServiceDeliveryPoints).Concat(this._parent.MeterReadings).Concat(this._parent.ServiceLocations).Concat(this._parent.PricingStructures).Concat(this._parent.AuxiliaryAgreements).Concat(this._parent.EndDeviceControls).Concat(this._parent.Customer).Concat(this._parent.ServiceCategory).Concat(this._parent.CustomerAccount).Concat(this._parent.DemandResponseProgram).Concat(this._parent.Equipments).GetEnumerator();
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the billingCycle property
        /// </summary>
        private sealed class BillingCycleProxy : ModelPropertyChange<ICustomerAgreement, string>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public BillingCycleProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "billingCycle")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override string Value
            {
                get
                {
                    return this.ModelElement.BillingCycle;
                }
                set
                {
                    this.ModelElement.BillingCycle = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the loadMgmt property
        /// </summary>
        private sealed class LoadMgmtProxy : ModelPropertyChange<ICustomerAgreement, string>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public LoadMgmtProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "loadMgmt")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override string Value
            {
                get
                {
                    return this.ModelElement.LoadMgmt;
                }
                set
                {
                    this.ModelElement.LoadMgmt = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the budgetBill property
        /// </summary>
        private sealed class BudgetBillProxy : ModelPropertyChange<ICustomerAgreement, string>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public BudgetBillProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "budgetBill")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override string Value
            {
                get
                {
                    return this.ModelElement.BudgetBill;
                }
                set
                {
                    this.ModelElement.BudgetBill = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the ServiceSupplier property
        /// </summary>
        private sealed class ServiceSupplierProxy : ModelPropertyChange<ICustomerAgreement, IServiceSupplier>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public ServiceSupplierProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "ServiceSupplier")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override IServiceSupplier Value
            {
                get
                {
                    return this.ModelElement.ServiceSupplier;
                }
                set
                {
                    this.ModelElement.ServiceSupplier = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the StandardIndustryCode property
        /// </summary>
        private sealed class StandardIndustryCodeProxy : ModelPropertyChange<ICustomerAgreement, IStandardIndustryCode>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public StandardIndustryCodeProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "StandardIndustryCode")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override IStandardIndustryCode Value
            {
                get
                {
                    return this.ModelElement.StandardIndustryCode;
                }
                set
                {
                    this.ModelElement.StandardIndustryCode = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the Customer property
        /// </summary>
        private sealed class CustomerProxy : ModelPropertyChange<ICustomerAgreement, ICustomer>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public CustomerProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "Customer")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override ICustomer Value
            {
                get
                {
                    return this.ModelElement.Customer;
                }
                set
                {
                    this.ModelElement.Customer = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the ServiceCategory property
        /// </summary>
        private sealed class ServiceCategoryProxy : ModelPropertyChange<ICustomerAgreement, IServiceCategory>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public ServiceCategoryProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "ServiceCategory")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override IServiceCategory Value
            {
                get
                {
                    return this.ModelElement.ServiceCategory;
                }
                set
                {
                    this.ModelElement.ServiceCategory = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the CustomerAccount property
        /// </summary>
        private sealed class CustomerAccountProxy : ModelPropertyChange<ICustomerAgreement, ICustomerAccount>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public CustomerAccountProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "CustomerAccount")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override ICustomerAccount Value
            {
                get
                {
                    return this.ModelElement.CustomerAccount;
                }
                set
                {
                    this.ModelElement.CustomerAccount = value;
                }
            }
        }

        /// <summary>
        /// Represents a proxy to represent an incremental access to the DemandResponseProgram property
        /// </summary>
        private sealed class DemandResponseProgramProxy : ModelPropertyChange<ICustomerAgreement, IDemandResponseProgram>
        {

            /// <summary>
            /// Creates a new observable property access proxy
            /// </summary>
            /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
            public DemandResponseProgramProxy(ICustomerAgreement modelElement) :
                    base(modelElement, "DemandResponseProgram")
            {
            }

            /// <summary>
            /// Gets or sets the value of this expression
            /// </summary>
            public override IDemandResponseProgram Value
            {
                get
                {
                    return this.ModelElement.DemandResponseProgram;
                }
                set
                {
                    this.ModelElement.DemandResponseProgram = value;
                }
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub