コード例 #1
0
        public void BlogPlainFields()
        {
            Kernel.AddComponent("plainfields", typeof(IPlainFieldInferenceService), typeof(PlainFieldInferenceService));
            Kernel.AddComponent("nameService", typeof(INamingService), typeof(NamingService));
            Kernel.AddComponent("typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService));

            IPlainFieldInferenceService plainService = Kernel[typeof(IPlainFieldInferenceService)] as IPlainFieldInferenceService;

            TableDefinition table = new TableDefinition("blogs", new DatabaseDefinition("alias"));

            table.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer));
            table.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar));
            table.AddColumn(new ColumnDefinition("authorid", false, true, false, false, OleDbType.VarChar));

            ActiveRecordPropertyDescriptor[] descs = plainService.InferProperties(table);

            Assert.IsNotNull(descs);
            Assert.AreEqual(2, descs.Length);

            ActiveRecordPropertyDescriptor desc1 = descs[0];
            ActiveRecordPropertyDescriptor desc2 = descs[1];

            Assert.AreEqual("id", desc1.ColumnName);
            Assert.AreEqual("Integer", desc1.ColumnTypeName);
            Assert.AreEqual("Id", desc1.PropertyName);
            Assert.AreEqual(typeof(int), desc1.PropertyType);

            Assert.AreEqual("name", desc2.ColumnName);
            Assert.AreEqual("VarChar", desc2.ColumnTypeName);
            Assert.AreEqual("Name", desc2.PropertyName);
            Assert.AreEqual(typeof(String), desc2.PropertyType);
        }
コード例 #2
0
        public override void Deactivated(IDictionary context)
        {
            base.Deactivated(context);

            ActiveRecordDescriptor desc = context["ardesc"] as ActiveRecordDescriptor;

            foreach (ListViewItem item in listView1.Items)
            {
                ActiveRecordPropertyDescriptor property = item.Tag as ActiveRecordPropertyDescriptor;
                property.Generate = item.Checked;
            }
        }
コード例 #3
0
 private void listView1_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e)
 {
     if (e.Label == null || e.Label.Length == 0)
     {
         e.CancelEdit = true;
     }
     else
     {
         ActiveRecordPropertyDescriptor desc = listView1.Items[e.Item].Tag as ActiveRecordPropertyDescriptor;
         desc.PropertyName = e.Label;
     }
 }
コード例 #4
0
        private void AddAppropriateAttribute(CodeMemberProperty memberProperty, ActiveRecordPropertyDescriptor property)
        {
            bool needExplicitColumnName = (String.Compare(property.ColumnName, property.PropertyName, true) != 0);

            CodeAttributeDeclaration codeAttribute = null;

            if (property is ActiveRecordPrimaryKeyDescriptor)
            {
                codeAttribute = new CodeAttributeDeclaration("PrimaryKey");
                codeAttribute.Arguments.Add(new CodeAttributeArgument(
                                                new CodeSnippetExpression("PrimaryKeyType.Native")));

                if (needExplicitColumnName)
                {
                    codeAttribute.Arguments.Add(new CodeAttributeArgument(
                                                    new CodeSnippetExpression(Quote(property.ColumnName))));
                }
            }
            else
            {
                codeAttribute = new CodeAttributeDeclaration("Property");

                if (!property.Insert)
                {
                    codeAttribute.Arguments.Add(new CodeAttributeArgument("Insert",
                                                                          new CodeSnippetExpression("false")));
                }
                if (!property.Update)
                {
                    codeAttribute.Arguments.Add(new CodeAttributeArgument("Update",
                                                                          new CodeSnippetExpression("false")));
                }

                if (needExplicitColumnName)
                {
                    codeAttribute.Arguments.Add(new CodeAttributeArgument("Column",
                                                                          new CodeSnippetExpression(Quote(property.ColumnName))));
                }
            }

            memberProperty.CustomAttributes.Add(codeAttribute);
        }
コード例 #5
0
        private void SaveClassProperties()
        {
            _descriptor.Properties.Clear();

            foreach (ListViewItem item in listView1.Items)
            {
                ActiveRecordPropertyDescriptor prop = item.Tag as ActiveRecordPropertyDescriptor;

                if (_parent != null && _parent.Properties.Contains(prop))
                {
                    // This is important as modification here
                    // wont affect the property descriptor on the parent
                    prop = (ActiveRecordPropertyDescriptor)prop.Clone();
                }

                _descriptor.Properties.Add(prop);

                prop.Generate = item.Checked;
            }
        }
コード例 #6
0
        private CodeMemberProperty CreatePropertyMember(ActiveRecordPropertyDescriptor property, CodeTypeDeclaration declaration)
        {
            String targetTypeName = null;

            if (property.PropertyType != null)
            {
                targetTypeName = property.PropertyType.FullName;
            }
            else if (property is ActiveRecordPropertyRelationDescriptor)
            {
                targetTypeName = (property as ActiveRecordPropertyRelationDescriptor).TargetType.ClassName;
            }
            else
            {
                throw new ApplicationException("Could not resolve property type");
            }


            String fieldName = _namingService.CreateFieldName(property.PropertyName);

            declaration.Members.Add(new CodeMemberField(targetTypeName, fieldName));

            CodeMemberProperty memberProperty = new CodeMemberProperty();

            memberProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            memberProperty.Name       = property.PropertyName;
            memberProperty.Type       = new CodeTypeReference(targetTypeName);

            CodeFieldReferenceExpression fieldReference = new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), fieldName);

            memberProperty.GetStatements.Add(
                new CodeMethodReturnStatement(fieldReference));
            memberProperty.SetStatements.Add(
                new CodeAssignStatement(fieldReference,
                                        new CodeArgumentReferenceExpression("value")));
            return(memberProperty);
        }