我必须解决一个练习,但我无法解决一个错误。 抱歉,我对Boo语言知之甚少。 我的代码是:
public class Item (IIDataReaderLoadable):
Sequence as long
Code as string
Description as string
Weight as decimal
Id as Guid
def LoadFromReader(reader as IDataReader):
Sequence = long.Parse(reader[0].ToString());
Code = reader[1].ToString();
Weight = decimal.Parse(reader[2].ToString());
Description = reader[3].ToString();
Id = Guid.Parse(reader[4].ToString());
TableName as string:
get:
return "Hoja1$"
operation read_MasterData_etlexcel:
log = ProcessContext.GetLogger()
file = ProcessContext.InputFile
log.Info("Reading $file")
for Data in EntityReader[of Item].Read(file):
yield Row.FromObject(Data)
operation print_etlexcel:
log = ProcessContext.GetLogger()
for row in rows:
log.Info(row.ToString())
yield row
def serialize_row(it as Object, id as Guid):
serializer = XmlSerializer(typeof(Item))
writer = FileStream("output" + id.ToString() +".xml", FileMode.Create);
serializer.Serialize(writer, it);
writer.Close();
serialize_row(Item, Item.Id)
process process_owners_etlexcel:
read_MasterData_etlexcel()
print_etlexcel()
当我在命令窗口中执行它时,我得到下一个错误:
2018-05-14 14:18:44.0479 [Error] [Mss.Etl.DSLLoader.EtlSetup] Cannot execute ./e
xcelfile/import.boo BCE0000: C:\Program Files\Mecalux\GnaService2015\excelfile\i
mport.boo(57,30): BCE0020: Boo.Lang.Compiler.CompilerError: An instance of type
'Mss.Item' is required to access non static member 'Id'.
我想阅读包含一些列的Excel文件,我必须创建一个恢复Excel文件内容的boo脚本,然后我必须将Excel文件中的每一行映射到我的类Ítem的对象中,并在XML文件中序列化对象
由于
答案 0 :(得分:0)
错误就在这一行:
serialize_row(Item, Item.Id)
Item.Id字段是成员字段而不是静态字段,这意味着您需要一个实例。看起来你在那里称它为静态因此它的爆炸。我不确定解决方案是什么,因为你有几个宏没有在代码示例中定义,所以我不确定他们在做什么,但我认为你要么删除该行或传入会员ID或随机会员ID。
我不得不猜测这是解决方案:
item = Item()
serialize_row(item, item.Id)