Beispiel #1
0
 private static bool TrySerializeAsPrimitiveValue(Type propertyType, 
     ProtobufFieldAttribute attribute,
     out BuildingSerializer buildingSerializer)
 {
     buildingSerializer = null;
     SerializerWithWireType serializer;
     if ((attribute.DataType != DataType.Default &&
         DataTypeToSerializerCache.TryGetSerializer(attribute.DataType, out serializer))
             || DefaultSerializersCache.TryGetSerializer(propertyType, out serializer))
     {
         {
             buildingSerializer = new BuildingSerializer(serializer,
                 new SingleValueBuilder(propertyType));
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 private static bool TrySerializeAsNullable(Type propertyType,
     ProtobufFieldAttribute attribute, out BuildingSerializer buildingSerializer)
 {
     buildingSerializer = null;
     if (propertyType.IsGenericType &&
         propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
     {
         Type underlyingType = propertyType.GetGenericArguments()[0];
         SerializerWithWireType underlyingSerializer = CreateBuildingSerializer(
             underlyingType, attribute, false).Serializer;
         buildingSerializer = new BuildingSerializer(
             underlyingSerializer, new NullableValueBuilder(underlyingType));
         return true;
     }
     return false;
 }
Beispiel #3
0
 private static bool TrySerializeAsCollection(Type propertyType, 
     ProtobufFieldAttribute attribute, bool examineForCollection, 
     out BuildingSerializer buildingSerializer)
 {
     buildingSerializer = null;
     if (examineForCollection &&
         propertyType.IsGenericType &&
             propertyType.GetGenericTypeDefinition() == typeof(ICollection<>))
     {
         Type underlyingType = propertyType.GetGenericArguments()[0];
         SerializerWithWireType underlyingSerializer = CreateBuildingSerializer(
             underlyingType, attribute, false).Serializer;
         {
             buildingSerializer = new BuildingSerializer(attribute.Packed
                 ? (SerializerWithWireType)new PackedRepeatedSerializer(underlyingSerializer)
                 : new RepeatedSerializer(attribute.FieldNumber, underlyingSerializer),
                 new RepeatedValueBuilder(underlyingType, !attribute.Packed));
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
 private static bool TrySerializeAsEnum(Type propertyType,
     out BuildingSerializer buildingSerializer)
 {
     buildingSerializer = null;
     if (propertyType.IsSubclassOf(typeof(Enum)))
     {
         buildingSerializer = new BuildingSerializer(
             new EnumSerializer(propertyType),
             new SingleValueBuilder(propertyType));
         return true;
     }
     return false;
 }
Beispiel #5
0
 public BuildingProperty(PropertyInfo property,
     BuildingSerializer buildingSerializer)
 {
     this.property = property;
     this.buildingSerializer = buildingSerializer;
 }