I am warpping an ArcGIS IFeature object with a class that has my required properties to get and set them easily. Basically, the get and set operations just use feature.get_value(index)
and feature.set_value(indes, value)
, and expose the strongly typed value.
I have several fields that use a domain (basically, an IDictionary<string, object>
) to represent common properties across the application.
At first I figured I would only use the keys of the domain (which are normal int values) in my wrapping class, and use the domain in my ToString()
method, to translate to strings for the UI.
Later I figured out I can use strings in my applicaiton (which makes it easier to pass around nulls, as the actual domain fields are nullable most of the time), and only change those fields' getters and setters to use GetDomainValue(index)
and SetDomainValue(index, value)
method that will translate between the key and value to/from the underlying feature object.
我正在使用具有我所需属性的类来扭曲ArcGIS IFeature对象,以便轻松获取和设置它们。基本上,get和set操作只使用feature.get_value(index)和feature.set_value(indes,value),并公开强类型值。我有几个字段使用域(基本上是IDictionary
What approach do you think is better? I figured the string approach is a bit more "persistent ignorant", as my class doesn't care how the values are being saved, just their string representation. On the other hand, it makes the code jump through loops a bit - instead of returning what's in the feature, every getter needs to iterate the domain.
你认为哪种方法更好?我认为字符串方法更加“持久无知”,因为我的课程并不关心如何保存值,只是它们的字符串表示。另一方面,它使代码跳过循环 - 而不是返回功能中的内容,每个getter都需要迭代域。
2 个解决方案
#1
You might want to think about representing your domain fields with Nullable< Int32>
. This would give you a way to represent features that have a domain value specified but it also allows you to directly specify null
where appropriate.
您可能想要考虑使用Nullable
#2
I ended up sticking with the domain values, so that I can also verify that the calling code passed a valid value.
我最终坚持使用域值,这样我也可以验证调用代码是否传递了有效值。
#1
You might want to think about representing your domain fields with Nullable< Int32>
. This would give you a way to represent features that have a domain value specified but it also allows you to directly specify null
where appropriate.
您可能想要考虑使用Nullable
#2
I ended up sticking with the domain values, so that I can also verify that the calling code passed a valid value.
我最终坚持使用域值,这样我也可以验证调用代码是否传递了有效值。