private void CreateParameter() { var type = ProperCSTypeName.Get(datacolumn); string name = ProperVarName.Get(datacolumn.ColumnName.ToLower()); this.MethodArgs.Add(new CSArgument(type, name)); }
private void ConstructBody() { string className = datatable.TableName; string instanceName = ProperVarName.Get(datatable.TableName.ToLower()); this.Statements.Add("var dt = table.DbAccess.GetDataTable(sqlCommand);"); this.Statements.Add($"List<{className}> list = new List<{className}>();"); CSBlock forEachBlock = new CSBlock("foreach (DataRow dataRow in dt.Rows)"); forEachBlock.Statements.Add($"{className} {instanceName} = new {className}();"); foreach (DataColumn clm in datatable.Columns) { string clmName = ProperVarName.Get(clm.ColumnName, false); string propName = ProperVarName.Get(clm.ColumnName, true); if (clm.AllowDBNull) { forEachBlock.Statements.Add($"{instanceName}.{propName} = ({ProperCSTypeName.Get(clm)})(dataRow[{Quotes}{clmName}{Quotes}] == DBNull.Value ? null : dataRow[{Quotes}{clmName}{Quotes}]);"); } else { forEachBlock.Statements.Add($"{instanceName}.{propName} = ({ProperCSTypeName.Get(clm)})dataRow[{Quotes}{clmName}{Quotes}];"); } } forEachBlock.Statements.Add($"list.Add({instanceName});"); this.Statements.Add(forEachBlock.ToString()); this.Statements.Add("return list;"); }
private void ConstructParameter() { foreach (DataColumn clm in this.datatable.PrimaryKey) { var type = ProperCSTypeName.Get(clm); string name = clm.ColumnName.ToLower(); this.MethodArgs.Add(new CSArgument(type, name)); } }
private void CreateProperties(DataTable dataTable) { CSProperty property; List <CSProperty> properties = new List <CSProperty>(); foreach (DataColumn clm in dataTable.Columns) { string typeName = ProperCSTypeName.Get(clm); string name = ProperVarName.Get(clm.ColumnName); property = new CSProperty(typeName, name, CSMemberModifier.PublicVirtual); properties.Add(property); } this.Properties = properties; }