Exemplo n.º 1
0
        private CodeMemberProperty GetJoinedKeyProperty(PropertyData property)
        {
            string basePropertyName = property.ModelClass.PrimaryKey.Name;
            CodeTypeReference basePropertyType = GetPropertyType(property.ModelClass.PrimaryKey);

            CodeMemberProperty memberProperty = new CodeMemberProperty();
            memberProperty.CustomAttributes.Add(property.GetPrimaryKeyAttribute());
            memberProperty.Attributes = MemberAttributes.Public;
            if (Context.Model.UseVirtualProperties)
            {
                if (property.Name == basePropertyName)
                    memberProperty.Attributes |= MemberAttributes.Override;
            }
            else
            {
                memberProperty.Attributes |= MemberAttributes.Final;
                if (property.Name == basePropertyName)
                    memberProperty.Attributes |= MemberAttributes.New;
            }

            memberProperty.Name = property.Name;
            memberProperty.Type = basePropertyType;
            memberProperty.HasGet = true;
            memberProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodePropertyReferenceExpression(new CodeBaseReferenceExpression(), basePropertyName)));
            memberProperty.HasSet = true;
            memberProperty.SetStatements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeBaseReferenceExpression(), basePropertyName), new CodeVariableReferenceExpression("value")));

            return memberProperty;
        }
Exemplo n.º 2
0
        private CodeMemberProperty GetActiveRecordMemberProperty(CodeMemberField memberField,
                                                                 PropertyData property)
        {
            CodeMemberProperty memberProperty =
                GetMemberProperty(memberField, property.Name, property.ColumnType,
								  property.CustomMemberType,
								  property.NotNull,
                                  true,
                                  true,
                                  property.ImplementsINotifyPropertyChanged(),
                                  property.ImplementsINotifyPropertyChanging(),
                                  property.Description);
            CodeAttributeDeclaration attributeDecleration = null;

            switch (property.KeyType)
            {
                // Composite keys must be handled in upper levels
                case KeyType.None:
                    attributeDecleration = property.GetPropertyAttribute();
                    break;
                case KeyType.PrimaryKey:
                    attributeDecleration = property.GetPrimaryKeyAttribute();
                    break;
            }

            memberProperty.CustomAttributes.Add(attributeDecleration);

            return memberProperty;
        }