< Summary

Class:Microsoft.Azure.Batch.PropertyCollection
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\PropertyCollection.cs
Covered lines:19
Uncovered lines:0
Coverable lines:19
Total lines:106
Line coverage:100% (19 of 19)
Covered branches:2
Total branches:2
Branch coverage:100% (2 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_HasBeenModified()-100%100%
get_IsReadOnly()-100%100%
set_IsReadOnly(...)-100%100%
get_BindingState()-100%100%
CreatePropertyAccessor(...)-100%100%
CreatePropertyAccessor(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\PropertyCollection.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for license information.
 3
 4namespace Microsoft.Azure.Batch
 5{
 6    using System.Collections.Generic;
 7    using System.Linq;
 8
 9    /// <summary>
 10    /// A collection of properties.
 11    /// </summary>
 12    internal abstract class PropertyCollection : IPropertyMetadata
 13    {
 14        private readonly IList<IPropertyMetadata> propertyMetadata;
 15        private readonly PropertyAccessController propertyAccessController;
 16
 17        private bool isReadOnly;
 18
 19        /// <summary>
 20        /// Creates a new instance of a <see cref="PropertyCollection"/>.
 21        /// </summary>
 22        /// <param name="bindingState">The binding state for the collection.</param>
 4989923        protected PropertyCollection(BindingState bindingState)
 24        {
 4989925            this.propertyMetadata = new List<IPropertyMetadata>();
 4989926            this.propertyAccessController = new PropertyAccessController(bindingState);
 4989927            this.isReadOnly = false;
 4989928        }
 29
 30        /// <summary>
 31        /// Gets if any properties in the collection have been modified.
 32        /// </summary>
 33        public bool HasBeenModified
 34        {
 35            get
 36            {
 20437                bool hasChanged = this.propertyMetadata.Any(p => p.HasBeenModified);
 38
 2939                return hasChanged;
 40            }
 41        }
 42
 43        /// <summary>
 44        /// Gets or sets the readonlyness of this collection and all of it's properties.
 45        /// </summary>
 46        public bool IsReadOnly
 47        {
 48            get
 49            {
 150                return this.isReadOnly;
 51            }
 52
 53            set
 54            {
 4947355                this.isReadOnly = value;
 46747656                foreach (IPropertyMetadata metadata in this.propertyMetadata)
 57                {
 18426558                    metadata.IsReadOnly = value;
 59                }
 4947360            }
 61        }
 62
 63        internal BindingState BindingState
 64        {
 95765            get { return this.propertyAccessController.BindingState; }
 66        }
 67
 68        #region Property creation helpers
 69
 70        /// <summary>
 71        /// Creates a <see cref="PropertyAccessor{T}"/> included in this <see cref="PropertyCollection"/>.
 72        /// </summary>
 73        /// <typeparam name="T">The type of the underlying property.</typeparam>
 74        /// <param name="propertyName">The name of the property.</param>
 75        /// <param name="allowedAccess">The allowed access of the <see cref="PropertyAccessor{T}"/>.</param>
 76        /// <returns>A <see cref="PropertyAccessor{T}"/> included in this <see cref="PropertyCollection"/>.</returns>
 77        internal PropertyAccessor<T> CreatePropertyAccessor<T>(string propertyName, BindingAccess allowedAccess)
 78        {
 8439079            var result = new PropertyAccessor<T>(this.propertyAccessController, propertyName, allowedAccess);
 80
 8439081            this.propertyMetadata.Add(result);
 82
 8439083            return result;
 84        }
 85
 86        /// <summary>
 87        /// Creates a <see cref="PropertyAccessor{T}"/> included in this <see cref="PropertyCollection"/>.
 88        /// </summary>
 89        /// <typeparam name="T">The type of the underlying property.</typeparam>
 90        /// <param name="value">The initial value of the underlying property.</param>
 91        /// <param name="propertyName">The name of the property.</param>
 92        /// <param name="allowedAccess">The allowed access of the <see cref="PropertyAccessor{T}"/>.</param>
 93        /// <returns>A <see cref="PropertyAccessor{T}"/> included in this <see cref="PropertyCollection"/>.</returns>
 94        internal PropertyAccessor<T> CreatePropertyAccessor<T>(T value, string propertyName, BindingAccess allowedAccess
 95        {
 25801596            var result = new PropertyAccessor<T>(value, this.propertyAccessController, propertyName, allowedAccess);
 97
 25801598            this.propertyMetadata.Add(result);
 99
 258015100            return result;
 101        }
 102
 103        #endregion
 104    }
 105
 106}