private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var result = new CriteriaPropertyCollection();
            var index  = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                          CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
        private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var isCSharp = GeneratorController.Current.CurrentUnit.GenerationParams.OutputLanguage == CodeLanguage.CSharp;
            var result   = new CriteriaPropertyCollection();
            var index    = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            if (isCSharp)
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                            else
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperVB.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
            private void OnPropertyChanged(string propertyName)
            {
                if (propertyName == "PropertyValue" && _propertyName == "ParentType" &&
                    !string.IsNullOrEmpty(_propertyValue))
                {
                    var parentInfo = GeneratorController.Current.CurrentUnit.CslaObjects.Find(_propertyValue);
                    var lstBox     = _parent.tableLayoutPanel.Controls.Find("ParentProperties", true)[0] as ListBox;
                    if (lstBox != null)
                    {
                        lstBox.Items.Clear();

                        if (CslaTemplateHelperCS.IsCollectionType(parentInfo.ObjectType))
                        {
                            lstBox.Enabled = false;
                        }
                        else
                        {
                            lstBox.Enabled = true;

                            var valProps = parentInfo.GetAllValueProperties();
                            foreach (var prop in valProps)
                            {
                                lstBox.Items.Add(prop.Name);
                            }

                            var first       = true;
                            var parentProps = string.Empty;
                            foreach (var prop in parentInfo.ValueProperties)
                            {
                                if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                                {
                                    lstBox.SelectedItems.Add(prop.Name);
                                    if (!first)
                                    {
                                        parentProps += ",";
                                    }
                                    else
                                    {
                                        first = false;
                                    }
                                    parentProps += prop.Name;
                                }
                            }

                            lstBox.Tag = parentProps;
                        }
                    }
                }

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
        private bool IsBrowsable(string[] objectType, string propertyName)
        {
            try
            {
                // is it non-root?
                var mainCslaObject = GeneratorController.Current.CurrentUnit.CslaObjects.Find(SelectedObject[0].MainObject);
                if (CslaTemplateHelperCS.IsNotRootType(mainCslaObject))
                {
                    if (propertyName == "MainLoadParameters" || propertyName == "SecondaryLoadParameters")
                    {
                        return(false);
                    }
                }

                if (objectType[0] == "OneToMultiple" &&
                    (propertyName == "SecondaryObject" ||
                     propertyName == "SecondaryPropertyName" ||
                     propertyName == "SecondaryCollectionTypeName" ||
                     propertyName == "SecondaryItemTypeName" ||
                     propertyName == "SecondaryLazyLoad" ||
                     propertyName == "SecondaryLoadingScheme" ||
                     propertyName == "SecondaryLoadProperties" ||
                     propertyName == "SecondaryLoadParameters"))
                {
                    return(false);
                }

                if (objectType[1] == "ParentLoad" && (propertyName == "MainLoadProperties" || propertyName == "MainLazyLoad"))
                {
                    return(false);
                }

                if (objectType[2] == "ParentLoad" && (propertyName == "SecondaryLoadProperties" || propertyName == "SecondaryLazyLoad"))
                {
                    return(false);
                }

                if (_selectedObject.Length > 1 && IsEnumerable(GetPropertyInfoCache(propertyName)))
                {
                    return(false);
                }

                return(true);
            }
            catch //(Exception e)
            {
                Debug.WriteLine(objectType + ":" + propertyName);
                return(true);
            }
        }
        private void BuildCollectionCriteriaGet(CslaObjectInfo info, AssociativeEntity.EntityFacade entity, ChildProperty child)
        {
            const string critName = "CriteriaGet";

            var selfLoad = CslaTemplateHelperCS.IsChildSelfLoaded(info);

            if (!selfLoad)
            {
                DeleteDefaultCollectionCriteria(info, critName);
                return;
            }

            StringBuilder sb;

            // make collection criteria if needed
            var      collCriteria = info.CriteriaObjects;
            Criteria criteria     = null;

            foreach (var crit in collCriteria)
            {
                if (CheckAndSetCollectionCriteriaGet(crit, info, critName))
                {
                    criteria = crit;
                    break;
                }
            }

            if (criteria == null)
            {
                criteria      = new Criteria(info);
                criteria.Name = critName;
                SetCollectionCriteriaGet(criteria, info, critName);
                info.CriteriaObjects.Add(criteria);

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added criteria {0} to {1} collection object.", critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            if (criteria.Name != critName)
            {
                return;
            }

            if (criteria.Properties.Count > 0)
            {
                // clear CriteriaGet properties
                criteria.Properties.Clear();

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully removed all criteria properties of {0} on {1} collection object.",
                                critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // populate collection criteria properties
            var addedProps = new List <string>();

            if (entity.LoadProperties.Count == 0)
            {
                criteria.Properties.AddRange(CriteriaPropertyCollection.Clone(FacadeRootCriteriaProperties));
                foreach (var property in FacadeRootCriteriaProperties)
                {
                    addedProps.Add(property.Name);
                }
            }
            else
            {
                criteria.Properties.AddRange(CriteriaPropertyCollection.Clone(entity.LoadProperties));
                foreach (var property in entity.LoadProperties)
                {
                    addedProps.Add(property.Name);
                }
            }

            if (addedProps.Count > 0)
            {
                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added the following properties to criteria {0}:" + Environment.NewLine, criteria.Name);
                foreach (var propName in addedProps)
                {
                    sb.AppendFormat("\t{0}.{1}.{2}" + Environment.NewLine, critName, info.ObjectName, propName);
                }
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // is it non-root?
            var entityCslaObject = _cslaObjects.Find(entity.ObjectName);

            if (entityCslaObject != null)
            {
                if (entityCslaObject.IsNotRootType())
                {
                    // re-fill LoadParameters with child criteria
                    child.LoadParameters.Clear();
                    foreach (var property in criteria.Properties)
                    {
                        child.LoadParameters.Add(new Parameter(criteria.Name, property.Name));
                    }
                }
            }
        }
        private bool IsBrowsable(ChildProperty[] objectType, string propertyName)
        {
            try
            {
                foreach (var childProperty in objectType)
                {
                    if ((GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.None ||
                         GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.ObjectLevel ||
                         ((childProperty.AuthzProvider == AuthorizationProvider.Custom) &&
                          !GeneratorController.Current.CurrentUnit.GenerationParams.UsesCslaAuthorizationProvider)) &&
                        (propertyName == "ReadRoles" ||
                         propertyName == "WriteRoles"))
                    {
                        return(false);
                    }
                    if ((GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.None ||
                         GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.ObjectLevel ||
                         ((childProperty.AuthzProvider == AuthorizationProvider.IsInRole ||
                           childProperty.AuthzProvider == AuthorizationProvider.IsNotInRole) &&
                          !GeneratorController.Current.CurrentUnit.GenerationParams.UsesCslaAuthorizationProvider) ||
                         GeneratorController.Current.CurrentUnit.GenerationParams.UsesCslaAuthorizationProvider) &&
                        (propertyName == "ReadAuthzRuleType" ||
                         propertyName == "WriteAuthzRuleType"))
                    {
                        return(false);
                    }
                    if (((GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.None ||
                          GeneratorController.Current.CurrentUnit.GenerationParams.GenerateAuthorization == AuthorizationLevel.ObjectLevel) ||
                         GeneratorController.Current.CurrentUnit.GenerationParams.UsesCslaAuthorizationProvider) &&
                        propertyName == "AuthzProvider")
                    {
                        return(false);
                    }
                    if (!GeneratorController.Current.CurrentUnit.GenerationParams.TargetIsCsla4All &&
                        propertyName == "BusinessRules")
                    {
                        return(false);
                    }

                    var isParentCollection = false;
                    var cslaObject         = (CslaObjectInfo)GeneratorController.Current.MainForm.ProjectPanel.ListObjects.SelectedItem;
                    var parentInfo2        = cslaObject.Parent.CslaObjects.Find(cslaObject.ParentType);
                    if (parentInfo2 != null)
                    {
                        isParentCollection = CslaTemplateHelperCS.IsCollectionType(parentInfo2.ObjectType);
                    }

                    if (GeneratorController.Current.CurrentUnit.GenerationParams.TargetIsCsla4All &&
                        isParentCollection &&
                        propertyName == "LoadParameters")
                    {
                        return(false);
                    }
                    if ((!GeneratorController.Current.CurrentUnit.GenerationParams.TargetIsCsla4All ||
                         !isParentCollection) &&
                        propertyName == "ParentLoadProperties")
                    {
                        return(false);
                    }

                    /*if (SelectedObject[0].LoadingScheme == LoadingScheme.ParentLoad && propertyName == "LazyLoad")
                     *  return false;*/
                    if (_selectedObject.Length > 1 && IsEnumerable(GetPropertyInfoCache(propertyName)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch //(Exception e)
            {
                Debug.WriteLine(objectType + ":" + propertyName);
                return(true);
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (_editorService != null)
            {
                if (context.Instance != null)
                {
                    // CR modifying to accomodate PropertyBag
                    Type   instanceType = null;
                    object objinfo      = null;
                    TypeHelper.GetContextInstanceObject(context, ref objinfo, ref instanceType);
                    var obj = (CslaObjectInfo)objinfo;
                    _lstProperties.Items.Clear();
                    _lstProperties.Items.Add("(None)");
                    foreach (var o in GeneratorController.Current.CurrentUnit.CslaObjects)
                    {
                        var accept = false;
                        if (o.ObjectType == CslaObjectType.UnitOfWork)
                        {
                            if (CslaTemplateHelperCS.IsReadOnlyType(obj.ObjectType))
                            {
                                if (o.UnitOfWorkType == UnitOfWorkFunction.Getter)
                                {
                                    accept = true;
                                }
                            }
                            else
                            {
                                if (o.UnitOfWorkType != UnitOfWorkFunction.Deleter &&
                                    o.UnitOfWorkType != UnitOfWorkFunction.Updater)
                                {
                                    accept = true;
                                }
                            }
                            if (accept)
                            {
                                _lstProperties.Items.Add(o.ObjectName);
                            }
                        }
                    }
                    _lstProperties.Sorted = true;

                    if (_lstProperties.Items.Contains(obj.UseUnitOfWorkType))
                    {
                        _lstProperties.SelectedItem = obj.UseUnitOfWorkType;
                    }
                    else
                    {
                        _lstProperties.SelectedItem = "(None)";
                    }

                    _editorService.DropDownControl(_lstProperties);
                    if (_lstProperties.SelectedIndex < 0 || _lstProperties.SelectedItem.ToString() == "(None)")
                    {
                        return(string.Empty);
                    }

                    return(_lstProperties.SelectedItem.ToString());
                }
            }

            return(value);
        }
        public static List <UoWCriteria> CriteriaOutputForm(CslaObjectInfo info, UnitOfWorkFunction function, bool generatingCriteria)
        {
            var result = new List <UoWCriteria>();

            var propertyDeclarationCache = new Dictionary <string, PropertyDeclaration>();

            foreach (var uowProperty in info.UnitOfWorkProperties)
            {
                propertyDeclarationCache[uowProperty.TypeName] = uowProperty.DeclarationMode;
            }

            var criteriaCollectionCounter = 0;

            foreach (var criteriaCollection in info.UnitOfWorkCriteriaObjects)
            {
                var creatorCounter = criteriaCollection.Count(crit => crit.IsCreator);

                if (function == UnitOfWorkFunction.Creator)
                {
                    if (creatorCounter == 0)
                    {
                        continue;
                    }
                }
                else if (function == UnitOfWorkFunction.Getter)
                {
                    if (creatorCounter != 0)
                    {
                        continue;
                    }
                }

                var uowCriteria = new UoWCriteria();
                criteriaCollectionCounter++;

                foreach (var crit in criteriaCollection)
                {
                    if (function == UnitOfWorkFunction.Creator && (!crit.IsCreator && (crit.IsGetter &&
                                                                                       CslaTemplateHelperCS.IsEditableType(crit.ParentObject.ObjectType))))
                    {
                        break;
                    }
                    if (function == UnitOfWorkFunction.Getter && !crit.IsGetter)
                    {
                        break;
                    }
                    if (function == UnitOfWorkFunction.Deleter && !crit.IsDeleter)
                    {
                        break;
                    }

                    var elementCriteria = new ElementCriteria();
                    elementCriteria.ParentObject    = crit.ParentObject.ObjectName;
                    elementCriteria.DeclarationMode = propertyDeclarationCache[elementCriteria.ParentObject];
                    elementCriteria.IsGetter        = !CslaTemplateHelperCS.IsEditableType(crit.ParentObject.ObjectType);
                    if (crit.Properties.Count == 0)
                    {
                        uowCriteria.ElementCriteriaList.Add(elementCriteria);
                    }
                    else
                    {
                        elementCriteria.Name      = crit.Name;
                        elementCriteria.Namespace = GetElementCriteriaNamesapce(crit);
                        elementCriteria.Type      = crit.Name;
                        if (crit.Properties.Count == 1)
                        {
                            elementCriteria.Name = crit.Properties[0].Name;
                            elementCriteria.Type =
                                CslaTemplateHelperCS.GetDataTypeGeneric(crit.Properties[0], crit.Properties[0].PropertyType);
                        }
                        if (generatingCriteria)
                        {
                            var newElementCriteria = new ElementCriteria();
                            foreach (var prop in crit.Properties.Where(prop => !string.IsNullOrEmpty(prop.UnitOfWorkFactoryParameter)))
                            {
                                newElementCriteria.ParentObject    = elementCriteria.Parameter;
                                newElementCriteria.DeclarationMode = elementCriteria.DeclarationMode;
                                newElementCriteria.IsGetter        = elementCriteria.IsGetter;
                                newElementCriteria.Namespace       = elementCriteria.Namespace;
                                newElementCriteria.Type            = "bool";
                                newElementCriteria.Name            = "Create" + elementCriteria.ParentObject;
                            }
                            uowCriteria.ElementCriteriaList.Add(newElementCriteria);
                        }
                        else
                        {
                            foreach (var prop in crit.Properties.Where(prop => !string.IsNullOrEmpty(prop.UnitOfWorkFactoryParameter)))
                            {
                                if (!string.IsNullOrEmpty(elementCriteria.Parameter))
                                {
                                    elementCriteria.Parameter += ", ";
                                }
                                elementCriteria.Parameter += prop.UnitOfWorkFactoryParameter;
                            }
                        }
                        uowCriteria.ElementCriteriaList.Add(elementCriteria);
                    }
                }
                var elementCriteriaListCount = uowCriteria.ElementCriteriaList.Count(elementCriteria => !string.IsNullOrEmpty(elementCriteria.Name));
                if ((generatingCriteria && elementCriteriaListCount > 1) ||
                    (!generatingCriteria && elementCriteriaListCount > 0))
                {
                    uowCriteria.CriteriaName = GetNumberedCriteria(info.UnitOfWorkCriteriaObjects.Count, criteriaCollectionCounter);
                }
                else
                {
                    criteriaCollectionCounter--;
                }

                if (uowCriteria.ElementCriteriaList.Count > 0)
                {
                    result.Add(uowCriteria);
                }
            }

            return(result);
        }
示例#9
0
        /// <summary>
        /// Should be called after the object has all it's properties (if applicable).
        /// It creates the default criteria classes depending on the object type.
        /// </summary>
        /// <param name="getSprocName">Name of the sproc.</param>
        public void AddDefaultCriteriaAndParameters(string getSprocName)
        {
            if (_currentCslaObject.CriteriaObjects.Count != 0)
            {
                return;
            }

            if (_currentCslaObject.ObjectType == CslaObjectType.EditableRootCollection ||
                _currentCslaObject.ObjectType == CslaObjectType.DynamicEditableRootCollection)
            {
                if (_currentUnit.Params.AutoCriteria)
                {
                    var crit = CreateEmptyNewAndFetchCriteria();
                    _currentCslaObject.CriteriaObjects.Add(crit);
                    crit.SetSprocNames();
                }
                //no need to go through the properties here.
                return;
            }

            if (_currentCslaObject.ObjectType == CslaObjectType.NameValueList ||
                (_currentCslaObject.ObjectType == CslaObjectType.ReadOnlyCollection &&
                 _currentCslaObject.ParentType == string.Empty))
            {
                if (_currentUnit.Params.AutoCriteria)
                {
                    var crit = CreateEmptyFetchCriteria();
                    _currentCslaObject.CriteriaObjects.Add(crit);
                    crit.SetSprocNames(getSprocName);
                }
                //no need to go through the properties here.
                return;
            }

            // Condition excludes NameValueList
            if (CslaTemplateHelperCS.IsCollectionType(_currentCslaObject.ObjectType))
            {
                return;
            }

            var           primaryKeyProperties = new List <ValueProperty>();
            ValueProperty timestampProperty    = null;
            var           useForCreate         = false;

            // retrieve all primary key and timestamp properties
            foreach (var prop in _currentCslaObject.ValueProperties)
            {
                if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                {
                    primaryKeyProperties.Add(prop);
                    if (!(prop.DbBindColumn.IsIdentity || prop.PropertyType == TypeCodeEx.Guid))
                    {
                        useForCreate = true;
                    }
                }
                else if (prop.DbBindColumn.NativeType == "timestamp")
                {
                    timestampProperty = prop;
                }
            }

            if (primaryKeyProperties.Count > 0 || timestampProperty != null)
            {
                // Try to find default Criteria object
                Criteria defaultCriteria   = _currentCslaObject.CriteriaObjects.Find("Criteria");
                Criteria timestampCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaTS");

                // If criteria objects are not set
                if (_currentCslaObject.CriteriaObjects.Count == 0)
                {
                    // If default criteria doesn't exists, create a new criteria
                    if (defaultCriteria == null)
                    {
                        if (!(_currentCslaObject.ObjectType == CslaObjectType.ReadOnlyObject &&
                              _currentCslaObject.ParentType != string.Empty))
                        {
                            defaultCriteria      = new Criteria(_currentCslaObject);
                            defaultCriteria.Name = _currentCslaObject.ObjectType == CslaObjectType.ReadOnlyObject
                                                       ? "CriteriaGet"
                                                       : "Criteria";
                            defaultCriteria.GetOptions.Enable();
                            if (_currentCslaObject.ObjectType == CslaObjectType.EditableRoot ||
                                _currentCslaObject.ObjectType == CslaObjectType.EditableSwitchable ||
                                _currentCslaObject.ObjectType == CslaObjectType.EditableChild ||
                                _currentCslaObject.ObjectType == CslaObjectType.DynamicEditableRoot)
                            {
                                defaultCriteria.DeleteOptions.Enable();
                                if (defaultCriteria.Properties.Count > 0 && useForCreate)
                                {
                                    defaultCriteria.CreateOptions.Factory    = true;
                                    defaultCriteria.CreateOptions.DataPortal = true;
                                    defaultCriteria.CreateOptions.RunLocal   = true;
                                }
                                else
                                {
                                    var createCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaNew");
                                    if (createCriteria == null)
                                    {
                                        createCriteria      = new Criteria(_currentCslaObject);
                                        createCriteria.Name = "CriteriaNew";
                                        createCriteria.CreateOptions.DataPortal = true;
                                        createCriteria.CreateOptions.Factory    = true;
                                        createCriteria.CreateOptions.RunLocal   = true;
                                        _currentCslaObject.CriteriaObjects.Add(createCriteria);
                                    }
                                }
                            }
                            if (_currentCslaObject.ObjectType == CslaObjectType.EditableChild)
                            {
                                return;
                            }

                            defaultCriteria.SetSprocNames();

                            if (_currentUnit.GenerationParams.TargetIsCsla4All &&
                                _currentCslaObject.ObjectType != CslaObjectType.EditableRoot &&
                                _currentCslaObject.ObjectType != CslaObjectType.EditableSwitchable &&
                                _currentCslaObject.ObjectType != CslaObjectType.ReadOnlyObject)
                            {
                                defaultCriteria.Name = "CriteriaDelete";
                                defaultCriteria.GetOptions.Factory       = false;
                                defaultCriteria.GetOptions.DataPortal    = false;
                                defaultCriteria.GetOptions.Procedure     = false;
                                defaultCriteria.GetOptions.ProcedureName = string.Empty;
                                defaultCriteria.DeleteOptions.Factory    = false;
                                defaultCriteria.DeleteOptions.DataPortal = false;
                            }

                            _currentCslaObject.CriteriaObjects.Add(defaultCriteria);
                            AddPropertiesToCriteria(primaryKeyProperties, defaultCriteria);

                            if (_currentUnit.Params.AutoTimestampCriteria && timestampProperty != null &&
                                timestampCriteria == null)
                            {
                                AddTimestampProperty(defaultCriteria, timestampProperty);
                            }
                        }
                    }
                }
            }
            else if (getSprocName != string.Empty && _currentUnit.Params.AutoCriteria)
            {
                var crit = CreateEmptyFetchCriteria();
                _currentCslaObject.CriteriaObjects.Add(crit);
                crit.SetSprocNames(getSprocName);
            }
        }
示例#10
0
        public void SetValuePropertyInfo(IDataBaseObject obj, IResultSet rs, IColumnInfo prop, ValueProperty destination)
        {
            var p = prop;

            SetDbBindColumn(obj, rs, p, destination.DbBindColumn);
            destination.Nullable = (p.IsNullable);

            if (p.NativeType == "timestamp")
            {
                destination.ReadOnly          = true;
                destination.MarkDirtyOnChange = false;
                destination.Undoable          = false;
                destination.DeclarationMode   = _currentUnit.Params.CreateTimestampPropertyMode;
            }

            if (_currentCslaObject.ObjectType == CslaObjectType.ReadOnlyObject)
            {
                destination.DeclarationMode = _currentUnit.Params.CreateReadOnlyObjectsPropertyMode;
                destination.ReadOnly        = true;
            }

            if (p.IsPrimaryKey)
            {
                if (p.IsIdentity)
                {
                    destination.PrimaryKey           = ValueProperty.UserDefinedKeyBehaviour.DBProvidedPK;
                    destination.ReadOnly             = true;
                    destination.PropSetAccessibility = AccessorVisibility.Default;
                }
                else
                {
                    destination.PrimaryKey = ValueProperty.UserDefinedKeyBehaviour.UserProvidedPK;
                }

                if (destination.PropertyType == TypeCodeEx.Guid)
                {
                    destination.DefaultValue = _currentUnit.Params.IDGuidDefaultValue;
                }
                else if (p.IsIdentity)
                {
                    switch (p.DbType)
                    {
                    case DbType.Int16:
                        destination.DefaultValue = _currentUnit.Params.IDInt16DefaultValue;
                        break;

                    case DbType.Int32:
                        destination.DefaultValue = _currentUnit.Params.IDInt32DefaultValue;
                        break;

                    case DbType.Int64:
                        destination.DefaultValue = _currentUnit.Params.IDInt64DefaultValue;
                        break;
                    }
                }
            }

            if (_currentUnit.Params.CreationDateColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                destination.DataAccess           = ValueProperty.DataAccessBehaviour.CreateOnly;
                if (destination.PropertyType == TypeCodeEx.SmartDate)
                {
                    destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                                                   ? "new SmartDate(DateTime.Now)"
                                                   : "new SmartDate(DateTime.Today)";
                }
                else
                {
                    destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                                                   ? "DateTime.Now"
                                                   : "DateTime.Today";
                }
            }
            else if (_currentUnit.Params.CreationUserColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                destination.DataAccess           = ValueProperty.DataAccessBehaviour.CreateOnly;
                destination.DefaultValue         = _currentUnit.Params.GetUserMethod;
            }
            else if (_currentUnit.Params.ChangedDateColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                if (CslaTemplateHelperCS.IsCreationDateColumnPresent(_currentCslaObject))
                {
                    destination.DefaultValue = "$" + _currentUnit.Params.CreationDateColumn;
                }
                else
                {
                    destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                                                   ? "new SmartDate(DateTime.Now)"
                                                   : "new SmartDate(DateTime.Today)";
                }
            }
            else if (_currentUnit.Params.ChangedUserColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                if (CslaTemplateHelperCS.IsCreationUserColumnPresent(_currentCslaObject))
                {
                    destination.DefaultValue = "$" + _currentUnit.Params.CreationUserColumn;
                }
                else
                {
                    destination.DefaultValue = _currentUnit.Params.GetUserMethod;
                }
            }
            else if (_currentUnit.Params.DatesDefaultStringWithTypeConversion &&
                     (destination.PropertyType == TypeCodeEx.SmartDate ||
                      destination.PropertyType == TypeCodeEx.DateTime))
            {
                destination.BackingFieldType = destination.PropertyType;
                destination.PropertyType     = TypeCodeEx.String;
                destination.DeclarationMode  = PropertyDeclaration.ManagedWithTypeConversion;
            }
        }