Example #1
0
 public static object ExtractNullableEnhancedTimeSpanFromSeconds(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(EnhancedTimeSpan?) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(double), out obj))
         {
             return(new EnhancedTimeSpan?(EnhancedTimeSpan.FromSeconds((double)obj)));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Example #2
0
 public static object ExtractUnlimitedByteQuantifiedSizeFromPages(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(Unlimited <ByteQuantifiedSize>) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(int), out obj))
         {
             long num = (long)((int)obj);
             if (0L > num)
             {
                 return(Unlimited <ByteQuantifiedSize> .UnlimitedValue);
             }
             return(new Unlimited <ByteQuantifiedSize>(ByteQuantifiedSize.FromBytes(checked ((ulong)num * 32UL * 1024UL))));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Example #3
0
 public static object ExtractNullableUnlimitedByteQuantifiedSizeFromKilobytes(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(Unlimited <ByteQuantifiedSize>?) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(long), out obj))
         {
             long num = (long)obj;
             if (0L > num)
             {
                 return(new Unlimited <ByteQuantifiedSize>?(Unlimited <ByteQuantifiedSize> .UnlimitedValue));
             }
             return(new Unlimited <ByteQuantifiedSize>?(new Unlimited <ByteQuantifiedSize>(ByteQuantifiedSize.FromKB(checked ((ulong)num)))));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
        public static object Extract(PropValue value, MapiPropertyDefinition propertyDefinition)
        {
            bool isReadOnly     = propertyDefinition.IsReadOnly;
            Type type           = propertyDefinition.Type;
            Type underlyingType = Nullable.GetUnderlyingType(type);

            if (null != underlyingType)
            {
                type = underlyingType;
            }
            if (propertyDefinition.PropertyTag.Id() != value.PropTag.Id())
            {
                throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ExceptionUnmatchedPropTag(propertyDefinition.PropertyTag.ToString(), value.PropTag.ToString()));
            }
            if (PropType.Binary == value.PropType)
            {
                if (typeof(Guid) == type)
                {
                    return(new Guid(value.GetBytes()));
                }
                if (typeof(Schedule) == type)
                {
                    return(Schedule.FromByteArray(value.GetBytes()));
                }
                if (typeof(MapiEntryId) == type)
                {
                    return(new MapiEntryId(value.GetBytes()));
                }
            }
            if (typeof(short) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <short>(isReadOnly, propertyDefinition, value.GetShortArray()));
                }
                return(value.GetShort());
            }
            else if (typeof(int) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <int>(isReadOnly, propertyDefinition, value.GetIntArray()));
                }
                return(value.GetInt());
            }
            else if (typeof(long) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <long>(isReadOnly, propertyDefinition, value.GetLongArray()));
                }
                return(value.GetLong());
            }
            else if (typeof(float) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <float>(isReadOnly, propertyDefinition, value.GetFloatArray()));
                }
                return(value.GetFloat());
            }
            else if (typeof(double) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <double>(isReadOnly, propertyDefinition, value.GetDoubleArray()));
                }
                return(value.GetDouble());
            }
            else if (typeof(DateTime) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    DateTime[]      dateTimeArray = value.GetDateTimeArray();
                    List <DateTime> list          = new List <DateTime>(dateTimeArray.Length);
                    foreach (DateTime dateTime in dateTimeArray)
                    {
                        list.Add(dateTime.ToLocalTime());
                    }
                    return(new MultiValuedProperty <DateTime>(isReadOnly, propertyDefinition, list.ToArray()));
                }
                return(value.GetDateTime().ToLocalTime());
            }
            else if (typeof(bool) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <bool>(isReadOnly, propertyDefinition, value.GetBoolArray()));
                }
                return(value.GetBoolean());
            }
            else if (typeof(string) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <string>(isReadOnly, propertyDefinition, value.GetStringArray()));
                }
                return(value.GetString());
            }
            else if (typeof(Guid) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <Guid>(isReadOnly, propertyDefinition, value.GetGuidArray()));
                }
                return(value.GetGuid());
            }
            else if (typeof(byte[]) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <byte[]>(isReadOnly, propertyDefinition, value.GetBytesArray()));
                }
                return(value.GetBytes());
            }
            else
            {
                if (typeof(short[]) == type)
                {
                    return(value.GetShortArray());
                }
                if (typeof(int[]) == type)
                {
                    return(value.GetIntArray());
                }
                if (typeof(long[]) == type)
                {
                    return(value.GetLongArray());
                }
                if (typeof(float[]) == type)
                {
                    return(value.GetFloatArray());
                }
                if (typeof(double[]) == type)
                {
                    return(value.GetDoubleArray());
                }
                if (typeof(DateTime[]) == type)
                {
                    DateTime[]      dateTimeArray2 = value.GetDateTimeArray();
                    List <DateTime> list2          = new List <DateTime>(dateTimeArray2.Length);
                    foreach (DateTime dateTime2 in dateTimeArray2)
                    {
                        list2.Add(dateTime2.ToLocalTime());
                    }
                    return(list2.ToArray());
                }
                if (typeof(bool[]) == type)
                {
                    return(value.GetBoolArray());
                }
                if (typeof(string[]) == type)
                {
                    return(value.GetStringArray());
                }
                if (typeof(Guid[]) == type)
                {
                    return(value.GetGuidArray());
                }
                if (typeof(byte[][]) == type)
                {
                    return(value.GetBytesArray());
                }
                if (type.IsAssignableFrom(MapiPropValueConvertor.TypeFromPropType(value.PropType, false)))
                {
                    return(value.RawValue);
                }
                object result = null;
                if (MapiPropValueConvertor.TryCastValueToExtract(value, type, out result))
                {
                    return(result);
                }
                throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
            }
        }