internal AttributedProperty(PropertyInfo property, FirestorePropertyAttribute attribute) { _propertyInfo = property; FirestoreName = attribute.Name ?? property.Name; _sentinelValue = SentinelValue.FromPropertyAttributes(property); if (attribute.ConverterType != null) { _converter = CustomConverter.ForConverterType(attribute.ConverterType, property.PropertyType); } // Note that the error messages in here don't use nameof, as we don't have an overload of CheckState accepting three // format arguments. // TODO: Put that in GAX and use nameof. string typeName = property.DeclaringType.FullName; GaxPreconditions.CheckState(property.GetIndexParameters().Length == 0, "{0}.{1} is an indexer, and should not be decorated with FirestorePropertyAttribute.", typeName, property.Name); // Annoyingly, we can't easily check whether the property is static - we have to check the individual methods. var getMethod = property.GetGetMethod(nonPublic: true); var setMethod = property.GetSetMethod(nonPublic: true); GaxPreconditions.CheckState(getMethod == null || !getMethod.IsStatic, "{0}.{1} is static, and should not be decorated with FirestorePropertyAttribute.", typeName, property.Name); GaxPreconditions.CheckState(setMethod == null || !setMethod.IsStatic, "{0}.{1} is static, and should not be decorated with FirestorePropertyAttribute.", typeName, property.Name); }
internal AttributedProperty(PropertyInfo property, FirestorePropertyAttribute attribute) { _propertyInfo = property; FirestoreName = attribute.Name ?? property.Name; _sentinelValue = SentinelValue.FromPropertyAttributes(property); if (attribute.ConverterType != null) { _converter = CustomConverter.ForConverterType(attribute.ConverterType, property.PropertyType); } string typeName = property.DeclaringType.FullName; GaxPreconditions.CheckState(property.GetIndexParameters().Length == 0, "{0}.{1} is an indexer, and should not be decorated with {2}.", typeName, property.Name, nameof(FirestorePropertyAttribute)); // Annoyingly, we can't easily check whether the property is static - we have to check the individual methods. var getMethod = property.GetGetMethod(nonPublic: true); var setMethod = property.GetSetMethod(nonPublic: true); GaxPreconditions.CheckState(getMethod == null || !getMethod.IsStatic, "{0}.{1} is static, and should not be decorated with {2}.", typeName, property.Name, nameof(FirestorePropertyAttribute)); GaxPreconditions.CheckState(setMethod == null || !setMethod.IsStatic, "{0}.{1} is static, and should not be decorated with {2}.", typeName, property.Name, nameof(FirestorePropertyAttribute)); }
public void ArrayUnion() { var sentinel = FieldValue.ArrayUnion("a", "b"); var value = ValueSerializer.Serialize(SerializationContext.Default, sentinel); Assert.Equal(SentinelKind.ArrayUnion, SentinelValue.GetKind(value)); var array = SentinelValue.GetArrayValue(value); var expected = CreateArray(CreateValue("a"), CreateValue("b")).ArrayValue; Assert.Equal(expected, array); }
public void ArrayRemove() { var sentinel = FieldValue.ArrayRemove("a", 1); var value = ValueSerializer.Serialize(sentinel); Assert.Equal(SentinelKind.ArrayRemove, SentinelValue.GetKind(value)); var array = SentinelValue.GetArrayValue(value); var expected = CreateArray(CreateValue("a"), CreateValue(1)).ArrayValue; Assert.Equal(expected, array); }
public void Increment_Double() { var sentinel = FieldValue.Increment(12.5); var value = ValueSerializer.Serialize(SerializationContext.Default, sentinel); Assert.Equal(SentinelKind.NumericIncrement, SentinelValue.GetKind(value)); var increment = SentinelValue.GetIncrement(value); var expected = new Value { DoubleValue = 12.5 }; Assert.Equal(expected, increment); }
public void Increment_Int64() { var sentinel = FieldValue.Increment(100L); var value = ValueSerializer.Serialize(sentinel); Assert.Equal(SentinelKind.NumericIncrement, SentinelValue.GetKind(value)); var increment = SentinelValue.GetIncrement(value); var expected = new Value { IntegerValue = 100L }; Assert.Equal(expected, increment); }
internal static Value ToProtoValue(this SentinelValue value) { switch (value) { case SentinelValue.ServerTimestamp: return(ServerTimestampSentinel); case SentinelValue.Delete: return(DeleteSentinel); default: throw new ArgumentException($"Unable to convert {nameof(SentinelValue)} value {value}"); } }