Esempio n. 1
0
        private void CalculateWrappedFields()
        {
            foreach (PropertyInfo field in ClassToWrap.GetProperties())
            {
                // wrap all member
                PropertyWrapper wrapper = WrappingHandler.CreateFieldWrapper(this, field);
                WrappedFields.Put(field.Name, wrapper);


                // wrap persistent member
                if ((ClassToWrap.GetCustomAttribute <PersistentAttribute>() != null ||
                     field.HasCustomAttribute <PersistentAttribute>() || field.HasCustomAttribute <AssociationAttribute>()) &&
                    !field.HasCustomAttribute <NonPersistentAttribute>() && !wrapper.IsList)
                {
                    WrappedPersistentFields.Put(field.Name, wrapper);

                    // wrap reference member
                    if (typeof(PersistentObject).IsAssignableFrom(field.PropertyType))
                    {
                        // add to all wrappedRelations
                        WrappedRelations.Put(field.Name, wrapper);

                        AssociationAttribute associationAttribute = field.GetCustomAttribute <AssociationAttribute>();

                        // add also to anonymous or identified relations
                        if (associationAttribute == null)
                        {
                            WrappedAnonymousRelations.Put(field.Name, wrapper);
                        }
                        else
                        {
                            WrappedIdentifiedAssociations.Put(associationAttribute.Name, wrapper);
                        }
                    }
                    else
                    { // wrap value Member
                        WrappedValueMember.Put(field.Name, wrapper);
                    }
                }
                else // wrap non persistent member
                {
                    NonPersistentFields.Put(field.Name, wrapper);

                    if (wrapper.IsList)
                    {
                        AssociationAttribute associationAttribute = field.GetCustomAttribute <AssociationAttribute>();

                        if (associationAttribute != null)
                        {
                            WrappedRelations.Put(field.Name, wrapper);
                            WrappedIdentifiedAssociations.Put(associationAttribute.Name, wrapper);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public PropertyWrapper GetPrimaryKeyMember()
        {
            if (PrimaryKey == null)
            {
                foreach (var fieldWrapper in WrappedPersistentFields)
                {
                    if (fieldWrapper.Value.IsPrimaryKey)
                    {
                        PrimaryKey = fieldWrapper.Value;
                        return(PrimaryKey);
                    }
                }
            }

            return(PrimaryKey);
        }