| | 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 | |
|
| | 4 | | namespace 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> |
| 49899 | 23 | | protected PropertyCollection(BindingState bindingState) |
| | 24 | | { |
| 49899 | 25 | | this.propertyMetadata = new List<IPropertyMetadata>(); |
| 49899 | 26 | | this.propertyAccessController = new PropertyAccessController(bindingState); |
| 49899 | 27 | | this.isReadOnly = false; |
| 49899 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets if any properties in the collection have been modified. |
| | 32 | | /// </summary> |
| | 33 | | public bool HasBeenModified |
| | 34 | | { |
| | 35 | | get |
| | 36 | | { |
| 204 | 37 | | bool hasChanged = this.propertyMetadata.Any(p => p.HasBeenModified); |
| | 38 | |
|
| 29 | 39 | | 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 | | { |
| 1 | 50 | | return this.isReadOnly; |
| | 51 | | } |
| | 52 | |
|
| | 53 | | set |
| | 54 | | { |
| 49473 | 55 | | this.isReadOnly = value; |
| 467476 | 56 | | foreach (IPropertyMetadata metadata in this.propertyMetadata) |
| | 57 | | { |
| 184265 | 58 | | metadata.IsReadOnly = value; |
| | 59 | | } |
| 49473 | 60 | | } |
| | 61 | | } |
| | 62 | |
|
| | 63 | | internal BindingState BindingState |
| | 64 | | { |
| 957 | 65 | | 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 | | { |
| 84390 | 79 | | var result = new PropertyAccessor<T>(this.propertyAccessController, propertyName, allowedAccess); |
| | 80 | |
|
| 84390 | 81 | | this.propertyMetadata.Add(result); |
| | 82 | |
|
| 84390 | 83 | | 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 | | { |
| 258015 | 96 | | var result = new PropertyAccessor<T>(value, this.propertyAccessController, propertyName, allowedAccess); |
| | 97 | |
|
| 258015 | 98 | | this.propertyMetadata.Add(result); |
| | 99 | |
|
| 258015 | 100 | | return result; |
| | 101 | | } |
| | 102 | |
|
| | 103 | | #endregion |
| | 104 | | } |
| | 105 | |
|
| | 106 | | } |