internal static object ConvertValueFromStore(EwsStoreObjectPropertyDefinition property, object originalValue) { if (originalValue == null) { return(null); } Type type = originalValue.GetType(); if (type == typeof(EmailAddressCollection) && property.Type == typeof(ADRecipientOrAddress)) { return(new MultiValuedProperty <ADRecipientOrAddress>(false, property, (from x in (EmailAddressCollection)originalValue select EwsStoreValueConverter.ConvertValueFromStore(property, x)).ToArray <object>())); } if (type == typeof(PolicyTag)) { return(((PolicyTag)originalValue).RetentionId); } Type type2 = property.Type; if (type2 == typeof(ADRecipientOrAddress)) { EmailAddress emailAddress = (EmailAddress)originalValue; return(new ADRecipientOrAddress(new Participant(emailAddress.Name, emailAddress.Address, emailAddress.RoutingType))); } if (!(type2 != typeof(byte[])) || !(property.StorePropertyDefinition.Type == typeof(byte[])) || !(originalValue is byte[])) { return(StoreValueConverter.ConvertValueFromStore(property, originalValue)); } if (type2 == typeof(ADObjectId)) { return(StoreValueConverter.ConvertValueFromStore(property, originalValue)); } return(Convert.ChangeType(EwsStoreValueConverter.DeserializeFromBinary((byte[])originalValue), type2)); }
internal void CopyFromItemObject(Item item, ExchangeVersion ewsVersion) { if (item == null) { throw new ArgumentNullException("item"); } base.InstantiationErrors.Clear(); foreach (PropertyDefinition propertyDefinition in this.ObjectSchema.AllProperties) { if (propertyDefinition != EwsStoreObjectSchema.ExchangeVersion) { EwsStoreObjectPropertyDefinition ewsStoreObjectPropertyDefinition = propertyDefinition as EwsStoreObjectPropertyDefinition; if (ewsStoreObjectPropertyDefinition != null) { object obj = null; if (ewsStoreObjectPropertyDefinition.GetItemProperty(item, out obj)) { if (ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version > ewsVersion) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "Skip loading property '{0}.{1}' because the current EWS version '{2}' is lower than '{3}'.", new object[] { base.GetType().FullName, ewsStoreObjectPropertyDefinition.Name, ewsVersion, ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version }); } else { Exception ex = null; try { obj = EwsStoreValueConverter.ConvertValueFromStore(ewsStoreObjectPropertyDefinition, obj); this.propertyBag.SetField(ewsStoreObjectPropertyDefinition, obj); base.InstantiationErrors.AddRange(ewsStoreObjectPropertyDefinition.ValidateProperty(obj, this.propertyBag, true)); } catch (LocalizedException ex2) { base.InstantiationErrors.Add(new PropertyValidationError(ex2.LocalizedString, ewsStoreObjectPropertyDefinition, obj)); } catch (InvalidCastException ex3) { ex = ex3; } catch (FormatException ex4) { ex = ex4; } catch (SerializationException ex5) { ex = ex5; } if (ex != null) { base.InstantiationErrors.Add(new PropertyValidationError(new LocalizedString(ex.Message), ewsStoreObjectPropertyDefinition, obj)); } } } } } } }