public ActiveRecordPropertyDescriptor[] InferProperties(TableDefinition tableDef) { ArrayList list = new ArrayList(); foreach (ColumnDefinition col in tableDef.Columns) { if (col.ForeignKey) { continue; } String propertyName = _namingService.CreatePropertyName(col.Name); Type propertyType = _typeInfService.ConvertOleType(col.Type); String colType = col.Type.ToString(); String colName = col.Name; ActiveRecordFieldDescriptor field = null; if (col.PrimaryKey) { field = new ActiveRecordPrimaryKeyDescriptor( colName, colType, propertyName, propertyType, "Native"); } else { field = new ActiveRecordFieldDescriptor( colName, colType, propertyName, propertyType, col.Nullable); } list.Add(field); } return((ActiveRecordFieldDescriptor[])list.ToArray(typeof(ActiveRecordFieldDescriptor))); }
private void AddOperations(ActiveRecordDescriptor descriptor, CodeTypeDeclaration declaration) { CodeMemberMethod deleteAll = new CodeMemberMethod(); deleteAll.Name = "DeleteAll"; deleteAll.Attributes = MemberAttributes.Static | MemberAttributes.Public; deleteAll.Statements.Add(new CodeExpressionStatement( new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), "DeleteAll", new CodeTypeOfExpression(descriptor.ClassName)))); declaration.Members.Add(deleteAll); CodeMemberMethod findAll = new CodeMemberMethod(); findAll.Name = "FindAll"; findAll.ReturnType = new CodeTypeReference(descriptor.ClassName, 1); findAll.Attributes = MemberAttributes.Static | MemberAttributes.Public; findAll.Statements.Add(new CodeMethodReturnStatement( new CodeCastExpression(findAll.ReturnType, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), "FindAll", new CodeTypeOfExpression(descriptor.ClassName))))); declaration.Members.Add(findAll); CodeMemberMethod find = new CodeMemberMethod(); ActiveRecordPrimaryKeyDescriptor primaryKey = descriptor.PrimaryKeyProperty; if (primaryKey != null) { find.Name = "Find"; find.ReturnType = new CodeTypeReference(descriptor.ClassName); find.Attributes = MemberAttributes.Static | MemberAttributes.Public; find.Parameters.Add(new CodeParameterDeclarationExpression(primaryKey.PropertyType, primaryKey.PropertyName)); find.Statements.Add(new CodeMethodReturnStatement( new CodeCastExpression(find.ReturnType, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), "FindByPrimaryKey", new CodeTypeOfExpression(descriptor.ClassName), new CodeArgumentReferenceExpression(primaryKey.PropertyName))))); declaration.Members.Add(find); } }