Esempio n. 1
0
        private CodeMemberProperty WriteProperty(FieldDefinition definition)
        {
            CodeMemberProperty property = null;

            Type type = definition.Type;

            if (type.IsValueType)
            {
                //CodeTypeReference t2 = new CodeTypeReference(typeof(System.Nullable));
                //t2.TypeArguments.Add(type);
                //property = new CodeMemberProperty();
                //property.Type = t2;
                property = new CodeMemberProperty();
                if (definition.ForeignKey)
                    property.Type = new CodeTypeReference(definition.ForeignKeyType);
                else
                    property.Type = new CodeTypeReference(definition.Type);
            }
            else
            {
                property = new CodeMemberProperty();
                if (definition.ForeignKey)
                    property.Type = new CodeTypeReference(definition.ForeignKeyType);
                else
                    property.Type = new CodeTypeReference(definition.Type);
            }

            property.Name = definition.PropertyName;
            property.Attributes = MemberAttributes.Public | MemberAttributes.Final;

            if (property.Name != definition.ColumnName)
            {
                property.CustomAttributes.Add(new CodeAttributeDeclaration("Column",
                    new CodeAttributeArgument[] {
                        new CodeAttributeArgument(new CodePrimitiveExpression(definition.ColumnName))
                    }));
            }

            #region property comments
            property.Comments.AddRange(InsertDocumentation(Documetation.Summary, new string[]
                {
                    "Property that that maps column '" + definition.ColumnName + "'."
                }));
            #endregion

            property.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(null, definition.FieldName)));

            property.SetStatements.Add(
              new CodeAssignStatement(
                new CodeFieldReferenceExpression(null, definition.FieldName),
                    new CodeArgumentReferenceExpression("value")));

            if (definition.PrimaryKey)
            {
                property.CustomAttributes.Add(new CodeAttributeDeclaration("PrimaryKey",
                    new CodeAttributeArgument[] { }));
            }

            return property;
        }
Esempio n. 2
0
        private CodeTypeMember WriteField(FieldDefinition definition)
        {
            CodeMemberField field = null;

            if (definition.Type.IsValueType)
            {
                //CodeTypeReference t2 = new CodeTypeReference(typeof(System.Nullable));
                //t2.TypeArguments.Add(type);
                //field = new CodeMemberField(t2, fieldName);
                if (definition.ForeignKey)
                    field = new CodeMemberField(definition.ForeignKeyType, definition.FieldName);
                else
                    field = new CodeMemberField(definition.Type, definition.FieldName);
            }
            else
            {
                if (definition.ForeignKey)
                    field = new CodeMemberField(definition.ForeignKeyType, definition.FieldName);
                else
                    field = new CodeMemberField(definition.Type, definition.FieldName);
            }

            field.Attributes = MemberAttributes.Private;

            return field;
        }