我正在查看Amibroker在VBScript和JS中的OLE文档示例,试图将其转换为C#代码: http://www.amibroker.de/guide/objects.html
在里面说:
try
{
ShapefileFeatureTable shpFileFeatTable = new ShapefileFeatureTable("/storage/sdcard/map.shp");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
我有一个构建的C#动态对象,我可以找到并调用Filter()函数,但我不知道如何在函数调用后设置值,因为那不是有效的C#语法。
这是C#代码:
Filter( 0, "index" ) = 1; // include only indices
Filter( 1, "market" ) = 2; // exclude 2nd market
当我调用ab.Analysis.Filter(0," market")时,它只返回当前设置的int。是以某种方式使用反射的答案吗?我还没想过要想知道是否有更简单的解决方案。
答案 0 :(得分:1)
你找到的代码片段是jscript,而不是VBScript。它不是函数属性,而是索引属性。 VB.NET很好地支持它们。但是C#团队不喜欢它们,并且只允许一个类的索引属性,即索引器(this [])。根据大众需求,他们在版本4中添加了支持。仅适用于COM互操作。这就是你正在使用的。
就像索引器一样,您使用方括号表示索引属性:
import re
import os
# Read the file, split the contents into a list of lines,
# removing line separators
with open('input.txt') as infile:
lines = infile.read().splitlines()
# Remove any whitespace around the word.
# If you are certain the list doesn't contain whitespace
# around the word, you can leave this out...
# (this is called a "list comprehansion", by the way)
lines = [line.strip() for line in lines]
# Remove letters if necessary, using regular expressions.
outlines = [re.sub('[ao]$', '', line) for line in lines]
# Join the output with appropriate line separators
outdata = os.linesep.join(outlines)
# Write the output to a file
with open('output.txt', 'w') as outfile:
outfile.write(outdata)
动态也应该支持哪些内容。显式调用setter函数将是另一种方式,AA.set_Filter(0,“market”,1)。
请注意,在添加对类型库的引用时,您可以更轻松地编写此代码 。这点亮了IntelliSense和红色曲线。