Example #1
0
 public PropertyBuilderInfoItem(AttributedProperty attribute, Property property, __IPropertyGetterInterceptor interfaceGetter, __IPropertySetterInterceptor interfaceSetter)
 {
     this.Attribute            = attribute;
     this.InterfaceGetter      = interfaceGetter;
     this.InterfaceSetter      = interfaceSetter;
     this.Property             = property;
     this.HasSyncRootInterface = attribute.Attribute.Type.Implements(__ISyncRoot.TypeName);
 }
Example #2
0
        private FirestoreDataAttributedType(BclType type)
        {
            var typeInfo = type.GetTypeInfo();

            _attribute = typeInfo.GetCustomAttribute <FirestoreDataAttribute>(inherit: false);
            // This would be an internal library bug. We shouldn't be calling it in this case.
            GaxPreconditions.CheckState(_attribute != null, "Type {0} is not decorated with {1}.", type.FullName, nameof(FirestoreDataAttribute));

            // The rest are user bugs.
            GaxPreconditions.CheckState(Enum.IsDefined(typeof(UnknownPropertyHandling), UnknownPropertyHandling),
                                        "Type {0} has invalid {1} value", type.FullName, nameof(UnknownPropertyHandling));

            _ctor = typeInfo
                    .GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
                    .SingleOrDefault(ctor => ctor.GetParameters().Length == 0);
            GaxPreconditions.CheckState(_ctor != null, "Type {0} has no parameterless constructor", type.FullName);

            List <AttributedProperty> readableProperties = new List <AttributedProperty>();
            Dictionary <string, AttributedProperty> writableProperties = new Dictionary <string, AttributedProperty>();

            // We look for static properties specifically to find problems. We'll never use static properties.
            foreach (var property in typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                FirestorePropertyAttribute attribute = property.GetCustomAttribute <FirestorePropertyAttribute>(inherit: true);
                if (attribute == null)
                {
                    continue;
                }
                var    attributedProperty = new AttributedProperty(property, attribute);
                string firestoreName      = attributedProperty.FirestoreName;

                // Note that we check readable and writable properties separately. We could theoretically have
                // two separate properties, one read-only and one write-only, with the same name in Firestore.
                if (attributedProperty.CanRead)
                {
                    // This is O(N), but done once per type so should be okay.
                    GaxPreconditions.CheckState(!readableProperties.Any(p => p.FirestoreName == firestoreName),
                                                "Type {0} contains multiple readable properties with name {1}", type.FullName, firestoreName);
                    readableProperties.Add(attributedProperty);
                }
                if (attributedProperty.CanWrite)
                {
                    GaxPreconditions.CheckState(!writableProperties.ContainsKey(firestoreName),
                                                "Type {0} contains multiple writable properties with name {1}", type.FullName, firestoreName);
                    writableProperties[firestoreName] = attributedProperty;
                }
            }
            ReadableProperties = readableProperties.AsReadOnly();
            WritableProperties = new ReadOnlyDictionary <string, AttributedProperty>(writableProperties);
        }
Example #3
0
 public PropertyBuilderInfoItem(
     AttributedProperty attribute,
     Property property,
     __IPropertyGetterInterceptor interfaceGetter,
     __IPropertySetterInterceptor interfaceSetter,
     __IPropertyInterceptorInitialize interfaceInitializer)
 {
     this.Attribute                  = attribute;
     this.InterfaceGetter            = interfaceGetter;
     this.InterfaceSetter            = interfaceSetter;
     this.InterfaceInitializer       = interfaceInitializer;
     this.Property                   = property;
     this.HasSyncRootInterface       = attribute.Attribute.Type.Implements(__ISyncRoot.Type.Fullname);
     this.AssignMethodAttributeInfos = AssignMethodAttributeInfo.GetAllAssignMethodAttributedFields(attribute);
     this.InterceptorInfo            = new InterceptorInfo(this.Attribute.Attribute.Type);
 }
        private AttributedTypeConverter(BclType targetType, FirestoreDataAttribute attribute) : base(targetType)
        {
            var typeInfo = targetType.GetTypeInfo();

            _attribute = attribute;

            // Check for user bugs in terms of attribute specifications.
            GaxPreconditions.CheckState(Enum.IsDefined(typeof(UnknownPropertyHandling), _attribute.UnknownPropertyHandling),
                                        "Type {0} has invalid {1} value", targetType.FullName, nameof(FirestoreDataAttribute.UnknownPropertyHandling));

            _createInstance = CreateObjectCreator(typeInfo);

            List <AttributedProperty> readableProperties = new List <AttributedProperty>();
            Dictionary <string, AttributedProperty> writableProperties = new Dictionary <string, AttributedProperty>();

            // We look for static properties specifically to find problems. We'll never use static properties.
            foreach (var property in typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                FirestorePropertyAttribute propertyAttribute = property.GetCustomAttribute <FirestorePropertyAttribute>(inherit: true);
                if (propertyAttribute == null)
                {
                    continue;
                }
                var    attributedProperty = new AttributedProperty(property, propertyAttribute);
                string firestoreName      = attributedProperty.FirestoreName;

                // Note that we check readable and writable properties separately. We could theoretically have
                // two separate properties, one read-only and one write-only, with the same name in Firestore.
                if (attributedProperty.CanRead)
                {
                    // This is O(N), but done once per type so should be okay.
                    GaxPreconditions.CheckState(!readableProperties.Any(p => p.FirestoreName == firestoreName),
                                                "Type {0} contains multiple readable properties with name {1}", targetType.FullName, firestoreName);
                    readableProperties.Add(attributedProperty);
                }
                if (attributedProperty.CanWrite)
                {
                    GaxPreconditions.CheckState(!writableProperties.ContainsKey(firestoreName),
                                                "Type {0} contains multiple writable properties with name {1}", targetType.FullName, firestoreName);
                    writableProperties[firestoreName] = attributedProperty;
                }
            }
            _readableProperties = readableProperties.AsReadOnly();
            _writableProperties = new ReadOnlyDictionary <string, AttributedProperty>(writableProperties);
        }
Example #5
0
 public static AssignMethodAttributeInfo[] GetAllAssignMethodAttributedFields(AttributedProperty attributedProperty) =>
 GetAllAssignMethodAttributedFields(attributedProperty.Property.Setter ?? attributedProperty.Property.Getter, attributedProperty.Attribute, attributedProperty.Property.OriginType, attributedProperty.Property.Name, GetDelegateType(attributedProperty.Property.ReturnType));
Example #6
0
 public BooleanExpressionCallCoder NewObj(AttributedProperty attributedProperty)
 {
     this.NewObj(attributedProperty.customAttribute);
     return(new BooleanExpressionCallCoder(this, attributedProperty.Attribute.Type));
 }