public override object Clone() { MultiValuedProperty <T> multiValuedProperty = (MultiValuedProperty <T>)CloneHelper.SerializeObj(this); multiValuedProperty.propertyDefinition = this.propertyDefinition; return(multiValuedProperty); }
protected virtual bool TryAddInternal(T item, out Exception error) { error = null; if (this.IsReadOnly) { error = new InvalidOperationException(this.ReadOnlyErrorMessage.ToString()); return(false); } if (item == null) { error = new ArgumentNullException("item", DataStrings.ErrorCannotAddNullValue); return(false); } if (this.Contains(item)) { if (!base.CopyChangesOnly) { error = new InvalidOperationException(DataStrings.ErrorValueAlreadyPresent(item.ToString())); } return(false); } ValidationError validationError = this.ValidateValue(item); if (validationError != null) { error = new DataValidationException(validationError); return(false); } base.BeginUpdate(); bool result; try { this.changed = true; if (!this.IsChangesOnlyCopy) { this.propertyValues.Add(item); } if (MultiValuedProperty <T> .Contains(this.removed, item, StringComparison.Ordinal)) { this.removed.Remove(item); } else { this.added.Add(item); } result = true; } catch (Exception) { this.errorOnUpdate = true; throw; } finally { base.EndUpdate(); } return(result); }
private static void WriteMultiValuedProperty <T>(StreamPropertyType propId, MultiValuedProperty <T> list, byte[] buffer, ref int offset) { int num = (list != null) ? list.Count : 0; offset += ExBitConverter.Write(num, buffer, offset); for (int i = 0; i < num; i++) { PropertyStreamWriter.WriteValue(propId & ~StreamPropertyType.MultiValuedProperty, list[i], buffer, ref offset); } }
public static MultiValuedProperty <T> operator -(MultiValuedProperty <T> oldCollection, object newValue) { if (oldCollection.IsChangesOnlyCopy) { throw new InvalidOperationException(DataStrings.ErrorNotSupportedForChangesOnlyCopy); } object[] args = new object[] { oldCollection.IsReadOnly, oldCollection.PropertyDefinition, oldCollection }; MultiValuedProperty <T> multiValuedProperty = (MultiValuedProperty <T>)Activator.CreateInstance(oldCollection.GetType(), BindingFlags.Instance | BindingFlags.NonPublic, null, args, null); multiValuedProperty.Remove(newValue); return(multiValuedProperty); }
internal static MbxPropertyDefinition ProxyAddressFromStringPropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false) { GetterDelegate getterDelegate = delegate(IPropertyBag propertyBag) { if (propertyBag[rawPropertyDefinition] != null) { return(ProxyAddress.Parse((string)propertyBag[rawPropertyDefinition])); } return(null); }; SetterDelegate setterDelegate = delegate(object value, IPropertyBag propertyBag) { propertyBag[rawPropertyDefinition] = ((ProxyAddress)value).ToString(); }; GetterDelegate getterDelegate2 = delegate(IPropertyBag propertyBag) { MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition]; MultiValuedProperty <ProxyAddress> multiValuedProperty2 = new MultiValuedProperty <ProxyAddress>(); foreach (string proxyAddressString in multiValuedProperty) { multiValuedProperty2.Add(ProxyAddress.Parse(proxyAddressString)); } return(multiValuedProperty2); }; SetterDelegate setterDelegate2 = delegate(object value, IPropertyBag propertyBag) { MultiValuedProperty <ProxyAddress> multiValuedProperty = (MultiValuedProperty <ProxyAddress>)value; MultiValuedProperty <string> multiValuedProperty2 = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition]; for (int i = multiValuedProperty2.Count - 1; i >= 0; i--) { if (!string.IsNullOrEmpty(multiValuedProperty2[i])) { multiValuedProperty2.RemoveAt(i); } } foreach (ProxyAddress proxyAddress in multiValuedProperty) { multiValuedProperty2.Add(proxyAddress.ToString()); } }; return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(ProxyAddress), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : null, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[] { rawPropertyDefinition }, multivalued ? getterDelegate2 : getterDelegate, multivalued ? setterDelegate2 : setterDelegate)); }
protected virtual void SetAt(int index, T item) { if (this.IsReadOnly) { throw new InvalidOperationException(this.ReadOnlyErrorMessage.ToString()); } if (item == null) { throw new ArgumentNullException("item", DataStrings.ErrorCannotAddNullValue); } if (index < 0 || index >= this.propertyValues.Count) { throw new ArgumentOutOfRangeException("index", index, DataStrings.ErrorOutOfRange(0, this.propertyValues.Count - 1)); } if (MultiValuedProperty <T> .Contains(this.propertyValues, item, StringComparison.Ordinal)) { T t = this[index]; if (t.Equals(item)) { return; } } int num = this.IndexOf(item); if (num >= 0 && num != index) { throw new InvalidOperationException(DataStrings.ErrorValueAlreadyPresent(item.ToString())); } this.ValidateValueAndThrow(item); base.BeginUpdate(); try { this.RemoveAt(index); this.Insert(index, item); } catch (Exception) { this.errorOnUpdate = true; throw; } finally { base.EndUpdate(); } }
public virtual bool Remove(T item) { if (this.IsReadOnly) { throw new InvalidOperationException(this.ReadOnlyErrorMessage.ToString()); } if (item == null) { return(false); } if (!this.IsChangesOnlyCopy) { int num = this.IndexOf(item); if (-1 == num) { return(false); } item = this.propertyValues[num]; } base.BeginUpdate(); try { this.changed = true; this.propertyValues.Remove(item); if (MultiValuedProperty <T> .Contains(this.added, item, StringComparison.Ordinal)) { this.added.Remove(item); } else { this.removed.Add(item); } } catch (Exception) { this.errorOnUpdate = true; throw; } finally { base.EndUpdate(); } return(true); }
internal static MbxPropertyDefinition Int32FromNullableInt32PropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false) { GetterDelegate getterDelegate = (IPropertyBag propertyBag) => (propertyBag[rawPropertyDefinition] == null) ? 0 : ((int)propertyBag[rawPropertyDefinition]); SetterDelegate setterDelegate = delegate(object value, IPropertyBag propertyBag) { propertyBag[rawPropertyDefinition] = (((int?)value) ?? 0); }; GetterDelegate getterDelegate2 = delegate(IPropertyBag propertyBag) { MultiValuedProperty <int> multiValuedProperty = (MultiValuedProperty <int>)propertyBag[rawPropertyDefinition]; MultiValuedProperty <int> multiValuedProperty2 = new MultiValuedProperty <int>(); foreach (int value in multiValuedProperty) { int?num = new int?(value); if (num != null) { multiValuedProperty2.Add(num.Value); } } return(multiValuedProperty2); }; SetterDelegate setterDelegate2 = delegate(object value, IPropertyBag propertyBag) { MultiValuedProperty <int> multiValuedProperty = (MultiValuedProperty <int>)value; MultiValuedProperty <int> multiValuedProperty2 = (MultiValuedProperty <int>)propertyBag[rawPropertyDefinition]; for (int i = multiValuedProperty2.Count - 1; i >= 0; i--) { multiValuedProperty2.RemoveAt(i); } foreach (int item in multiValuedProperty) { multiValuedProperty2.Add(item); } }; return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(int), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : 0, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[] { rawPropertyDefinition }, multivalued ? getterDelegate2 : getterDelegate, multivalued ? setterDelegate2 : setterDelegate)); }
public static MultiValuedProperty <TransportQueueLog> Parse(string stringXml) { MultiValuedProperty <TransportQueueLog> queueLogs = new MultiValuedProperty <TransportQueueLog>(); if (!string.IsNullOrWhiteSpace(stringXml)) { using (XmlReader xmlReader = XmlReader.Create(new StringReader(stringXml), new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment })) { TransportQueueLogs transportQueueLogs = (TransportQueueLogs)TransportQueueLogs.Serializer.Deserialize(xmlReader); if (transportQueueLogs != null && transportQueueLogs.Count > 0) { transportQueueLogs.ForEach(delegate(TransportQueueLog i) { queueLogs.Add(i); }); } } } return(queueLogs); }
internal static int SizeOfValue(StreamPropertyType propType, object value) { int num = 0; if (propType <= (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List)) { switch (propType) { case StreamPropertyType.Null: return(num); case StreamPropertyType.Bool: case StreamPropertyType.Byte: case StreamPropertyType.SByte: return(num + 1); case StreamPropertyType.Int16: case StreamPropertyType.UInt16: return(num + 2); case StreamPropertyType.Int32: case StreamPropertyType.UInt32: case StreamPropertyType.Single: case StreamPropertyType.RecipientType: return(num + 4); case StreamPropertyType.Int64: case StreamPropertyType.UInt64: case StreamPropertyType.Double: case StreamPropertyType.DateTime: return(num + 8); case StreamPropertyType.Decimal: case StreamPropertyType.Guid: case StreamPropertyType.IPAddress: return(num + 16); case StreamPropertyType.Char: return(num + PropertyStreamWriter.SizeOfValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array, new char[] { (char)value })); case StreamPropertyType.String: { num += 4; string text = (string)value; if (!string.IsNullOrEmpty(text)) { return(num + Encoding.UTF8.GetByteCount(text)); } return(num); } case StreamPropertyType.IPEndPoint: return(num + 18); case StreamPropertyType.RoutingAddress: case StreamPropertyType.ADObjectId: goto IL_48F; default: switch (propType) { case StreamPropertyType.Bool | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array: case StreamPropertyType.SByte | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length)); case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.Array: case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length * 2)); case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array: case StreamPropertyType.UInt32 | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length * 4)); case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.Array: case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array: case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: case StreamPropertyType.DateTime | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length * 8)); case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.Array: case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length * 16)); case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: num += 4; if (value != null) { return(num + Encoding.UTF8.GetByteCount((char[])value)); } return(num); case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: { num += 4; string[] array = (string[])value; for (int i = 0; i < array.Length; i++) { num += PropertyStreamWriter.SizeOfValue(StreamPropertyType.String, array[i]); } return(num); } case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array: return(num + (4 + ((Array)value).Length * 18)); default: switch (propType) { case StreamPropertyType.Bool | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.List: case StreamPropertyType.SByte | StreamPropertyType.List: break; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.List: case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List: goto IL_308; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List: case StreamPropertyType.UInt32 | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List: goto IL_31F; case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.List: case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List: case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: case StreamPropertyType.DateTime | StreamPropertyType.List: goto IL_336; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.List: case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List: goto IL_34D; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: { List <char> list = (List <char>)value; char[] chars = list.ToArray(); num += 4; if (value != null) { return(num + Encoding.UTF8.GetByteCount(chars)); } return(num); } case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: goto IL_3DB; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List: goto IL_365; default: goto IL_48F; } break; } break; } } else { if (propType == (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.List)) { num += 4; List <byte[]> list2 = (List <byte[]>)value; for (int j = 0; j < list2.Count; j++) { num += PropertyStreamWriter.SizeOfValue(propType & ~StreamPropertyType.List, list2[j]); } return(num); } switch (propType) { case StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: break; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: goto IL_308; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: goto IL_31F; case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: goto IL_336; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: goto IL_34D; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: { MultiValuedProperty <char> multiValuedProperty = (MultiValuedProperty <char>)value; char[] chars2 = multiValuedProperty.ToArray(); num += 4; if (value != null) { return(num + Encoding.UTF8.GetByteCount(chars2)); } return(num); } case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: goto IL_3DB; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: goto IL_365; default: { if (propType != (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.MultiValuedProperty)) { goto IL_48F; } num += 4; MultiValuedProperty <byte[]> multiValuedProperty2 = (MultiValuedProperty <byte[]>)value; for (int k = 0; k < multiValuedProperty2.Count; k++) { num += PropertyStreamWriter.SizeOfValue(propType & ~StreamPropertyType.MultiValuedProperty, multiValuedProperty2[k]); } return(num); } } } return(num + (4 + ((ICollection)value).Count)); IL_308: return(num + (4 + ((ICollection)value).Count * 2)); IL_31F: return(num + (4 + ((ICollection)value).Count * 4)); IL_336: return(num + (4 + ((ICollection)value).Count * 8)); IL_34D: return(num + (4 + ((ICollection)value).Count * 16)); IL_365: return(num + (4 + ((ICollection)value).Count * 18)); IL_3DB: num += 4; IList <string> list3 = (IList <string>)value; for (int l = 0; l < list3.Count; l++) { num += PropertyStreamWriter.SizeOfValue(StreamPropertyType.String, list3[l]); } return(num); IL_48F: throw new InvalidOperationException(string.Format("Data type {0} is unknown", propType)); }
public int IndexOf(T value) { return(MultiValuedProperty <T> .IndexOf(this.propertyValues, value, StringComparison.OrdinalIgnoreCase)); }
public bool Contains(T item) { return(MultiValuedProperty <T> .Contains(this.propertyValues, item, StringComparison.OrdinalIgnoreCase)); }
public MultiValuedProperty(Dictionary <string, object> table) : this(false, true, null, new T[0], null, null) { this.isChangesOnlyCopy = true; bool copyChangesOnly = base.CopyChangesOnly; base.CopyChangesOnly = true; foreach (string text in table.Keys) { object values = ValueConvertor.UnwrapPSObjectIfNeeded(table[text]); if (!this.TryAddValues(text, values) && !this.TryRemoveValues(text, values)) { throw new NotSupportedException(DataStrings.ErrorUnknownOperation(text, MultiValuedProperty <T> .ArrayToString(MultiValuedProperty <T> .AddKeys), MultiValuedProperty <T> .ArrayToString(MultiValuedProperty <T> .RemoveKeys))); } } base.CopyChangesOnly = copyChangesOnly; this.isReadOnly = true; }
public MultiValuedProperty(object value) : this(true, true, null, MultiValuedProperty <T> .GetObjectAsEnumerable(value), null, null) { }
public bool Equals(MultiValuedProperty <T> other) { return(other != null && (object.ReferenceEquals(other, this) || (other.Count == this.Count && other.WasCleared == this.WasCleared && other.IsReadOnly == this.IsReadOnly && other.IsCompletelyRead == base.IsCompletelyRead && other.Changed == this.Changed && object.Equals(other.GetType(), base.GetType()) && object.Equals(other.PropertyDefinition, this.PropertyDefinition) && (MultiValuedProperty <T> .ListsAreEqual(other.added, this.added) && MultiValuedProperty <T> .ListsAreEqual(other.removed, this.removed) && MultiValuedProperty <T> .ListsAreEqual(other.propertyValues, this.propertyValues) && MultiValuedProperty <T> .ListsAreEqual(other.serializedAddedValues, this.serializedAddedValues) && MultiValuedProperty <T> .ListsAreEqual(other.serializedRemovedValues, this.serializedRemovedValues) && MultiValuedProperty <T> .ListsAreEqual(other.serializedPropertyValues, this.serializedPropertyValues))))); }