将域实体属性映射到 Word 书签
我们需要打印带有书签的Word文档。我们还有域实体,其属性映射到 Word 文档中的一个(或多个)书签。现在,为了测试,我们有一个 switch 语句(foo 是域实体):
private static string GetValueForBookmark(Bookmark bookmark, Foo foo)
{
// ToDo: Un-switch this.
switch (bookmark.Name)
{
case "dist":
return foo.Measurment.Distance;
case "serialNo":
return foo.SerialNumber;
default:
return string.Empty;
}
}
我不想在框架中向 Foo 的属性添加属性。这看起来很混乱而且错误,因为域实体不应该知道所有这些一次性应用程序需求。
一种想法是创建书签名称到域实体属性的映射。也许创建一个表示书签名称的枚举,然后向这些表示域实体属性的枚举元素添加属性。属性必须指定这些属性,我不知道是否可以这样做。这里可以使用表达式树吗?
还有其他选择吗?我只是想将域实体属性映射到字符串文字。
解决这个问题的最佳方法是什么?
We need to print Word documents that have bookmarks in them. We also have domain entities whose properties map to one (or more) of the bookmarks in the Word documents. Right now, to test, we have a switch statement (foo is the domain entity):
private static string GetValueForBookmark(Bookmark bookmark, Foo foo)
{
// ToDo: Un-switch this.
switch (bookmark.Name)
{
case "dist":
return foo.Measurment.Distance;
case "serialNo":
return foo.SerialNumber;
default:
return string.Empty;
}
}
I would hate to add attributes to the properties of Foo in the framework. It seems messy and wrong, since the domain entities shouldn't know about all these one-off application needs.
One idea is to create a mapping of bookmark names to domain entity properties. Maybe create an enum that represents the bookmark names, then add attributes to these enum elements, that represent domain entity properties. The attributes would have to specify these properties, and I don't know if that can be done. Can expression trees be used here?
Is there another option? I simply want to map domain entity properties to string literals.
What is the best way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是这样做:
然后,访问它就这么简单:
I just went with this:
Then, accessing it, is as simple as this: