我使用的是使用ironruby的Revit API进行可扩展的存储,我认为我的问题是ironruby。我正在尝试在Ironruby中复制这个C#示例杰里米·坦尼克(Jeremy Tannik)的修订博客:
// create a field to store a string map
FieldBuilder fieldBuilder =
schemaBuilder.AddMapField( "StringMap", typeof( string ), typeof( string ) );
. . .
// set the value for this entity
IDictionary<string, string> stringMap = new Dictionary<string, string>();
stringMap.Add( "key1", "value1" );
stringMap.Add( "key2", "value2" );
entity.Set<IDictionary<string, string>>( field, stringMap );
当我尝试做我认为Ironruby中相同的事情时:
# create a field to store a string map
schema_builder.AddMapField( "manually_checked", System::String.to_clr_type, System::Boolean.to_clr_type )
. . .
# set the value for this entity
xDict = Dictionary[System::String,System::Boolean].new
IDictionary_module = xDict.class.ancestors.detect { |i| i.to_s ==
"System::Collections::Generic::IDictionary[System::String, System::Boolean]" }
xDict.Add( "blah", true )
# all three of these fail with the same error
x.Set( "manually_checked", xDict )
x.method(:Set).of(Dictionary[System::String,System::Boolean]).call( "manually_checked", xDict )
x.method(:Set).of(IDictionary_module).call( "manually_checked", xDict )
我称之为set()失败的所有三种方式都以相同的消息失败:
不支持类型: system.collections.generic.dictionary`2 [[System.String,Mscorlib, 版本= 4.0.0.0,文化=中性, publicKeyToken = B77A5C561934E089],[System.Boolean,Mscorlib, 版本= 4.0.0.0,文化=中性,publicKeyToken = B77A5C561934E089]]]] (InvalidOperationException)
使我认为错误消息中的" dictionary" 2是对xdict.class.ancestors [2]的引用,这是IDictionary [System :: String,System :: Boolean]的位置祖先数组。
所以,我的问题是,是否有一个允许它的铁鲁比语法,或者由于Ruby模块和.NET界面之间的差异而撞到了Showstopper?
您的字典add()使用ironruby字符串作为关键参数,但字典期望CLR字符串类型。将" to_clr_string"调用添加到您的Ruby字符串中,以使其与预期的内容保持一致。