表单上有七个复选框,用于指定以下参数:
1.Publish without text
2.Publish with your text
3.Publish with signature
4.Do not publish without photos
5.Do not publish without audio
6.Do not publish without video
7.Do not publish without text
还有一个功能,你可以设置一些发布选项(但不是全部,其他人有另一个代码)。这是:
patterns.vknet.Wall.Post(new WallPostParams
{
OwnerId = -yourcom,
Message = yorTextBox.Text,
Attachments = SetAttachments(),
FromGroup = true,
PublishDate = DateForPost()
});
如何通过组合多个选项来驯服复杂性?
答案 0 :(得分:-1)
解决此问题的另一种方法是在赋值表达式中应用条件,而不是使用嵌套的ifs。这允许您分别对每个属性应用条件:
patterns.vknet.Wall.Post(new WaalPostParameters
{
onwerId = -yourcom,
Message = yourTextCeckbox.Checked ? yourTextBox.Text : null,
Attachemnts = <condition> ? <if true> : <if false>
...
});
你也可以链接这些三元运算符(?:)。
x = c1 ? "a" : c2 ? "b" : "c"
当然,您也可以提前准备值并将它们存储在临时变量中。这使您可以自由使用ifs。重点是分别确定每个值,而不是将它们分成一堆,从而避免组合问题。
这是一个澄清我的观点的例子。这是......
if (x) {
if (y) {
if (z) {
result = new Result { R = a, S = c, T = e };
} else {
result = new Result { R = a, S = c, T = f };
}
} else {
if (z) {
result = new Result { R = a, S = d, T = e };
} else {
result = new Result { R = a, S = d, T = f };
}
}
} else {
if (y) {
if (z) {
result = new Result { R = b, S = c, T = e };
} else {
result = new Result { R = b, S = c, T = f };
}
} else {
if (z) {
result = new Result { R = b, S = d, T = e };
} else {
result = new Result { R = b, S = d, T = f };
}
}
}
......相当于
result = new Result {
R = x ? a : b,
S = y ? c : d,
T = z ? e : f
};