Exemplo n.º 1
0
        public void Parse(PropertyInfo propertyInfo, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            memberMetadata.Attributes = MemberAttributes.Property;

            if (!propertyInfo.CanRead || (!propertyInfo.GetMethod.IsPublic && !propertyInfo.GetMethod.IsFamily) ||
                propertyInfo.GetMethod.IsStatic || propertyInfo.GetIndexParameters().Length > 0)
            {
                memberMetadata.Attributes |= MemberAttributes.Unmappable;
            }

            if (propertyInfo.CanRead)
            {
                if ((propertyInfo.GetMethod.IsPublic || propertyInfo.GetMethod.IsFamily) && !propertyInfo.GetMethod.IsStatic)
                {
                    memberMetadata.Getter = GetterSetterAttributes.Defined;
                }

                if (propertyInfo.GetMethod.IsVirtual && !propertyInfo.GetMethod.IsFinal)
                {
                    memberMetadata.Getter |= GetterSetterAttributes.Virtual;
                }
            }

            if (propertyInfo.CanWrite)
            {
                if ((propertyInfo.SetMethod.IsPublic || propertyInfo.SetMethod.IsFamily) && !propertyInfo.SetMethod.IsStatic)
                {
                    memberMetadata.Setter = GetterSetterAttributes.Defined;
                }

                if (propertyInfo.SetMethod.IsVirtual && !propertyInfo.SetMethod.IsFinal)
                {
                    memberMetadata.Setter |= GetterSetterAttributes.Virtual;
                }
            }
        }
Exemplo n.º 2
0
 protected abstract void Parse(TAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata);
Exemplo n.º 3
0
 public void Parse(PropertyInfo propertyInfo, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
 {
     Parse(propertyInfo.GetCustomAttribute <TAttribute>(), typeMetadata, memberMetadata);
 }
Exemplo n.º 4
0
 public void Parse(FieldInfo fieldInfo, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
 {
     Parse(fieldInfo.GetCustomAttribute <TAttribute>(), typeMetadata, memberMetadata);
 }
Exemplo n.º 5
0
        protected override void Parse(EnumConvertionAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Unmappable) == MemberAttributes.Unmappable)
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                        string.Format("Member {0} of {1} cannot be marked with EnumConvertion.", memberMetadata.Name, typeMetadata.Type.FullName));
                if ((memberMetadata.Attributes & MemberAttributes.Ignored) == MemberAttributes.Ignored)
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                        string.Format("Member {0} of {1} cannot be marked with both EnumConvertion and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));

                if (!EnumConverter.IsEnum(memberMetadata.Type) && !NullableEnumConverter.IsNullableEnum(memberMetadata.Type))
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type,
                        string.Format("Member {0} of {1} not of type Enum cannot be marked with EnumConvertion.", memberMetadata.Name, typeMetadata.Type.FullName));

                memberMetadata.Attributes |= MemberAttributes.Mapped;
                memberMetadata.FormatProvider = attribute.ConvertionInfo;
            }
        }
Exemplo n.º 6
0
        protected override void Parse(MappingIgnoreAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Mapped) == MemberAttributes.Mapped)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with both MappingMember and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                memberMetadata.Attributes |= MemberAttributes.Ignored;
            }
        }
Exemplo n.º 7
0
        protected override void Parse(MappingKeyAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Unmappable) == MemberAttributes.Unmappable)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with MappingKey.", memberMetadata.Name, typeMetadata.Type.FullName));
                }
                if ((memberMetadata.Attributes & MemberAttributes.Ignored) == MemberAttributes.Ignored)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with both MappingKey and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                // TODO: check for key type

                if (typeMetadata.IdentityMember != null)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type,
                                                             string.Format("Type {0} cannot contain more than one member marked with MappingKey.", typeMetadata.Type.FullName));
                }

                memberMetadata.Attributes  |= MemberAttributes.Mapped;
                typeMetadata.IdentityMember = memberMetadata;
            }
        }
        protected override void Parse(MappingConcurrencyAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Unmappable) == MemberAttributes.Unmappable)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with MappingConcurrency.", memberMetadata.Name, typeMetadata.Type.FullName));
                }
                if ((memberMetadata.Attributes & MemberAttributes.Ignored) == MemberAttributes.Ignored)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with both MappingConcurrency and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                if (memberMetadata.Type != typeof(DateTime))
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} not of type DateTime cannot be marked with MappingConcurrency.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                if (typeMetadata.ConcurrencyMember != null)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type,
                                                             string.Format("Type {0} cannot contain more than one member marked with MappingConcurrency.", typeMetadata.Type.FullName));
                }

                if (memberMetadata.FormatProvider != null && ((DateTimeConvertionInfo)memberMetadata.FormatProvider).DateOnly)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} marked with MappingConcurrency cannot use DateTimeConvertionInfo.AsDate.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                memberMetadata.Attributes     |= MemberAttributes.Mapped;
                typeMetadata.ConcurrencyMember = memberMetadata;
            }
        }
Exemplo n.º 9
0
        protected override void Parse(MappingIndexAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Unmappable) == MemberAttributes.Unmappable)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with MappingIndex.", memberMetadata.Name, typeMetadata.Type.FullName));
                }
                if ((memberMetadata.Attributes & MemberAttributes.Ignored) == MemberAttributes.Ignored)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with both MappingIndex and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                // TODO: check for index type

                memberMetadata.Attributes |= MemberAttributes.Mapped;
                typeMetadata.IndexedMembers.Add(memberMetadata);
            }
        }
        protected override void Parse(DateTimeConvertionAttribute attribute, TypeMetadata typeMetadata, MemberMetadata memberMetadata)
        {
            if (attribute != null)
            {
                if ((memberMetadata.Attributes & MemberAttributes.Unmappable) == MemberAttributes.Unmappable)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with DateTimeConvertion.", memberMetadata.Name, typeMetadata.Type.FullName));
                }
                if ((memberMetadata.Attributes & MemberAttributes.Ignored) == MemberAttributes.Ignored)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} cannot be marked with both DateTimeConvertion and MappingIgnore.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                if (memberMetadata.Type != typeof(DateTime) && memberMetadata.Type != typeof(DateTime?))
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type,
                                                             string.Format("Member {0} of {1} not of type DateTime cannot be marked with DateTimeConvertion.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                if (memberMetadata == typeMetadata.ConcurrencyMember && attribute.ConvertionInfo.DateOnly)
                {
                    throw new OhmSharpInvalidSchemaException(typeMetadata.Type, memberMetadata.Name,
                                                             string.Format("Member {0} of {1} marked with MappingConcurrency cannot use DateTimeConvertionInfo.AsDate.", memberMetadata.Name, typeMetadata.Type.FullName));
                }

                memberMetadata.Attributes    |= MemberAttributes.Mapped;
                memberMetadata.FormatProvider = attribute.ConvertionInfo;
            }
        }