public ReferenceListPropertyMapping(ReferenceListMappingOptions options)
     : base(options)
 {
     _options = options;
 }
        public static MappingOptionsSet AddDefaultRules(this MappingOptionsSet mappingOptionsSet)
        {
            mappingOptionsSet.AddTypeRule(x => !x.GetTypeInfo().IsAbstract, o => { throw new NotSupportedException("InheritedPropertyMapping supports abstract classes and interfaces only."); });
            mappingOptionsSet.AddTypeRule(x => x.GetCustomAttribute <TableAttribute>() != null, o => {
                TableAttribute attribute = o.Type.GetCustomAttribute <TableAttribute>();
                o.TableName    = attribute.TableName;
                o.LoadBehavior = attribute.LoadBehavior;
            });

            mappingOptionsSet.AddTypeRule(x => x.GetTypeInfo().ImplementedInterfaces.Contains(typeof(INotifyPropertyChanged)), o => {
                o.RaisePropertyChangeMethod = o.Type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(x =>
                                                                                                                                            x.GetParameters().Length == 1 &&
                                                                                                                                            x.GetParameters()[0].ParameterType == typeof(PropertyChangedEventArgs) &&
                                                                                                                                            x.GetCustomAttributes(typeof(IsRaisePropertyChangeMethodAttribute), true).Any()).FirstOrDefault();
            });

            mappingOptionsSet.AddMemberTypeRule(x => x.GetCustomAttribute <ForeignObjectMappingAttribute>() != null, x => { x.MappingType = MappingType.ForeignObjectMapping; });
            mappingOptionsSet.AddMemberTypeRule(x => x.GetCustomAttribute <ReferenceListMappingAttribute>() != null, x => { x.MappingType = MappingType.ReferenceListMapping; });

            mappingOptionsSet.AddMemberMappingRule(x => x.GetCustomAttribute <ForeignObjectMappingAttribute>() != null, o => {
                ForeignObjectMappingOptions options     = (ForeignObjectMappingOptions)o;
                ForeignObjectMappingAttribute attribute = options.Member.GetCustomAttribute <ForeignObjectMappingAttribute>();
                options.DatabaseFieldName = attribute.Fieldname;

                if (attribute.ForeignObjectType != null)
                {
                    options.ForeignObjectType = attribute.ForeignObjectType;
                }

                if (attribute.ReadOnly)
                {
                    options.IsReadonly = true;
                }
                else
                {
                    options.IsInsertable = attribute.Insertable;
                    options.IsUpdateable = attribute.Updateable;
                }
                options.IsPrimaryKey = options.Member.GetCustomAttribute <IsPrimaryKeyAttribute>() != null;
            });

            mappingOptionsSet.AddMemberMappingRule(x => x.GetCustomAttribute <ReferenceListMappingAttribute>() != null, o => {
                ReferenceListMappingOptions options     = (ReferenceListMappingOptions)o;
                ReferenceListMappingAttribute attribute = options.Member.GetCustomAttribute <ReferenceListMappingAttribute>();

                options.SaveCascade        = attribute.SaveCascade;
                options.DeleteCascade      = attribute.DeleteCascade;
                options.DropChangesCascade = attribute.DropChangesCascade;

                options.ForeignProperty = attribute.ForeignProperty ?? attribute.ForeignType.GetProperties().Where(x => x.PropertyType == options.Member.DeclaringType).Single();
                foreach (EqualsObjectConditionAttribute equalsObjectAttribute in options.Member.GetCustomAttributes <EqualsObjectConditionAttribute>())
                {
                    options.Conditions.Add(attribute.ForeignType.GetProperty(equalsObjectAttribute.PropertyName), equalsObjectAttribute.Value);
                }
            });

            mappingOptionsSet.AddMemberMappingRule(x => x.GetCustomAttribute <ForeignObjectMappingAttribute>() == null && x.GetCustomAttribute <ReferenceListMappingAttribute>() == null, o => {
                FieldMappingOptions options = (FieldMappingOptions)o;
                MappingAttribute attribute  = options.Member.GetCustomAttribute <MappingAttribute>();
                if (attribute != null)
                {
                    options.DatabaseFieldName = attribute.FieldName ?? options.DatabaseFieldName;
                    if (attribute.ReadOnly)
                    {
                        options.IsReadonly = true;
                    }
                    else
                    {
                        options.IsInsertable = attribute.Insertable;
                        options.IsUpdateable = attribute.Updateable;
                    }
                }
                options.IsPrimaryKey = options.Member.GetCustomAttribute <IsPrimaryKeyAttribute>() != null;
            });

            return(mappingOptionsSet);
        }