Example #1
0
 public static PropValue PackNullableUnlimitedByteQuantifiedSizeIntoKilobytes(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(Unlimited <ByteQuantifiedSize>) == value.GetType())
     {
         long num = -1L;
         if (value != null)
         {
             Unlimited <ByteQuantifiedSize> unlimited = (Unlimited <ByteQuantifiedSize>)value;
             if (unlimited.IsUnlimited)
             {
                 num = -1L;
             }
             else
             {
                 num = checked ((long)unlimited.Value.ToKB());
             }
         }
         object value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack(num, propertyDefinition.PropertyTag.ValueType(), out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Example #2
0
 public static PropValue PackNullableEnhancedTimeSpanIntoSeconds(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value != null && typeof(EnhancedTimeSpan) == value.GetType())
     {
         object value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack(((EnhancedTimeSpan)value).TotalSeconds, propertyDefinition.PropertyTag.ValueType(), out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Example #3
0
 public static PropValue PackNullableEnhancedTimeSpanIntoDays(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(EnhancedTimeSpan) == value.GetType())
     {
         PropType type   = propertyDefinition.PropertyTag.ValueType();
         object   value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack((value == null) ? 0.0 : ((EnhancedTimeSpan)value).TotalDays, type, out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Example #4
0
 public static PropValue PackNullableValueToBool(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(bool) == value.GetType())
     {
         PropType type   = propertyDefinition.PropertyTag.ValueType();
         object   value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack((value == null) ? false : value, type, out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
        public static PropValue Pack(object value, MapiPropertyDefinition propertyDefinition)
        {
            PropTag  propertyTag = propertyDefinition.PropertyTag;
            PropType propType    = propertyTag.ValueType();
            Type     type        = MapiPropValueConvertor.TypeFromPropType(propType, false);

            if (value != null)
            {
                if (typeof(byte[]) == type)
                {
                    if (typeof(Guid) == value.GetType())
                    {
                        return(new PropValue(propertyTag, ((Guid)value).ToByteArray()));
                    }
                    if (typeof(Schedule) == value.GetType())
                    {
                        return(new PropValue(propertyTag, ((Schedule)value).ToByteArray()));
                    }
                }
                if (typeof(DateTime) == type && typeof(DateTime) == value.GetType())
                {
                    return(new PropValue(propertyTag, ((DateTime)value).ToUniversalTime()));
                }
                if (typeof(DateTime[]) == type)
                {
                    Type type2 = value.GetType();
                    if (typeof(MultiValuedProperty <DateTime>) == type2 || typeof(DateTime[]) == type2)
                    {
                        List <DateTime> list = new List <DateTime>(((ICollection)value).Count);
                        foreach (object obj in ((ICollection)value))
                        {
                            list.Add(((DateTime)obj).ToUniversalTime());
                        }
                        return(new PropValue(propertyTag, list.ToArray()));
                    }
                }
                if (type.IsAssignableFrom(value.GetType()))
                {
                    return(new PropValue(propertyTag, value));
                }
            }
            object value2 = null;

            if (MapiPropValueConvertor.TryCastValueToPack(value, propType, out value2))
            {
                return(new PropValue(propertyTag, value2));
            }
            throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
        }
Example #6
0
 public static PropValue PackMultiAnsiStringsIntoBytes(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(MultiValuedProperty <string>) == value.GetType())
     {
         MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)value;
         List <byte> list = new List <byte>();
         foreach (string s in multiValuedProperty)
         {
             byte[] bytes = Encoding.ASCII.GetBytes(s);
             list.AddRange(bytes);
             if (bytes[bytes.Length - 1] != 0)
             {
                 list.Add(0);
             }
         }
         return(new PropValue(propertyDefinition.PropertyTag, list.ToArray()));
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }