コード例 #1
0
            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);
            }
コード例 #2
0
            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));
            }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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}");
            }
        }