internal void SetAutogeneratedConstraints(PropertyDefinitionConstraint[] autogeneratedConstraints) { if (autogeneratedConstraints == null) { throw new ArgumentNullException("autogeneratedConstraints"); } PropertyDefinitionConstraint[] array; CollectionPropertyDefinitionConstraint[] list; if (autogeneratedConstraints.Length == 0) { array = this.allStaticConstraints; list = this.allStaticCollectionConstraints; } else { array = new PropertyDefinitionConstraint[this.allStaticConstraints.Length + autogeneratedConstraints.Length]; Array.Copy(this.allStaticConstraints, array, this.allStaticConstraints.Length); Array.Copy(autogeneratedConstraints, 0, array, this.allStaticConstraints.Length, autogeneratedConstraints.Length); List <CollectionPropertyDefinitionConstraint> list2 = new List <CollectionPropertyDefinitionConstraint>(this.allStaticCollectionConstraints); for (int i = 0; i < autogeneratedConstraints.Length; i++) { CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint = autogeneratedConstraints[i] as CollectionPropertyDefinitionConstraint; if (collectionPropertyDefinitionConstraint != null) { list2.Add(collectionPropertyDefinitionConstraint); } } list = list2.ToArray(); } lock (this.autogeneratedConstraintsSyncObject) { this.readOnlyAllConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(array); this.readOnlyAllCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(list); this.hasAutogeneratedConstraints = (0 != autogeneratedConstraints.Length); } }
public ProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, type) { if (supportingProperties == null) { throw new ArgumentNullException("supportingProperties"); } if (readConstraints == null) { throw new ArgumentNullException("readConstraints"); } if (writeConstraints == null) { throw new ArgumentNullException("writeConstraints"); } if (name == null) { throw new ArgumentNullException("name"); } if (type == null) { throw new ArgumentNullException("type"); } if (versionAdded == null) { throw new ArgumentNullException("versionAdded"); } if (defaultValue != null && !ReflectionHelper.IsInstanceOfType(defaultValue, type)) { throw new ArgumentException(DataStrings.ExceptionDefaultTypeMismatch.ToString(), "defaultValue (" + name + ")"); } if (type == typeof(bool) && defaultValue != null) { defaultValue = BoxedConstants.GetBool((bool)defaultValue); } this.defaultValue = defaultValue; this.customFilterBuilderDelegate = customFilterBuilderDelegate; this.versionAdded = versionAdded; if (readConstraints.Length < 1) { this.readOnlyReadConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection; } else { this.readOnlyReadConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(readConstraints); } if (writeConstraints.Length < 1 && readConstraints.Length < 1) { this.allStaticConstraints = PropertyDefinitionConstraint.None; this.readOnlyAllConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection; } else { this.allStaticConstraints = new PropertyDefinitionConstraint[readConstraints.Length + writeConstraints.Length]; Array.Copy(writeConstraints, this.allStaticConstraints, writeConstraints.Length); Array.Copy(readConstraints, 0, this.allStaticConstraints, writeConstraints.Length, readConstraints.Length); this.readOnlyAllConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(this.allStaticConstraints); } this.getterDelegate = getterDelegate; this.setterDelegate = setterDelegate; if (supportingProperties.Length < 1) { this.supportingProperties = ProviderPropertyDefinition.EmptyCollection; } else { this.supportingProperties = new ReadOnlyCollection <ProviderPropertyDefinition>(supportingProperties); } List <CollectionPropertyDefinitionConstraint> list = new List <CollectionPropertyDefinitionConstraint>(); List <CollectionPropertyDefinitionConstraint> list2 = new List <CollectionPropertyDefinitionConstraint>(); for (int i = 0; i < writeConstraints.Length; i++) { CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint = writeConstraints[i] as CollectionPropertyDefinitionConstraint; if (collectionPropertyDefinitionConstraint != null) { list.Add(collectionPropertyDefinitionConstraint); } } for (int j = 0; j < readConstraints.Length; j++) { CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint2 = readConstraints[j] as CollectionPropertyDefinitionConstraint; if (collectionPropertyDefinitionConstraint2 != null) { list.Add(collectionPropertyDefinitionConstraint2); list2.Add(collectionPropertyDefinitionConstraint2); } } if (list.Count < 1) { this.allStaticCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Array; this.readOnlyAllCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection; } else { this.allStaticCollectionConstraints = list.ToArray(); this.readOnlyAllCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(this.allStaticCollectionConstraints); } if (list2.Count < 1) { this.readOnlyReadCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection; } else { this.readOnlyReadCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(list2.ToArray()); } this.readOnlyDependentProperties = ProviderPropertyDefinition.EmptyCollection; if (this.supportingProperties.Count == 0) { this.dependentProperties = new List <ProviderPropertyDefinition>(); } foreach (ProviderPropertyDefinition providerPropertyDefinition in supportingProperties) { if (providerPropertyDefinition.IsCalculated) { throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on another calculated property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties"); } if (this.VersionAdded.IsOlderThan(providerPropertyDefinition.VersionAdded)) { throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on the newer property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties"); } providerPropertyDefinition.AddDependency(this); } if (defaultValue != null && defaultValue != string.Empty) { PropertyValidationError propertyValidationError = this.ValidateValue(defaultValue, false); if (propertyValidationError != null) { throw new ArgumentException(propertyValidationError.Description, "defaultValue"); } } }