是否可以同时使用变量和字符串?例如,我想定义结合变量和字符串的路径和其他选项?
private void ComboBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
var cb = sender as ComboBox;
if ((e.Key == Key.Return ||
e.Key == Key.Enter) &&
cb.Text != "")
{
bool duplicate = false;
foreach (ClockGroupVM vm in Clocks.GroupsVM)
{
if (vm.Name == cb.Text)
{
cb.SelectedItem = vm;
duplicate = true;
break;
}
}
if (duplicate)
{
return;
}
// create a ClockGroupM and corresponding ClockGroupVM
// (ClockGroupVM inherits from ClockGroupM)
var cvm = new ClockGroupVM()
{
Name = cb.Text
};
Clocks.Groups.Insert(0, cvm);
cb.SelectedItem = cvm;
}
}
internal bool HandlingSelectionChange = false;
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (HandlingSelectionChange)
{
return;
}
HandlingSelectionChange = true;
var cb = sender as ComboBox;
//if (cb.SelectedItem is the VM with Style != Normal)
ClockGroupVM foundVM = null;
foreach (ClockGroupVM vm in Clocks.GroupsVM)
{
if (vm.FontStyle != FontStyles.Normal &&
ReferenceEquals(cb.SelectedItem, vm))
{
foundVM = vm;
break;
}
}
if (foundVM != null)
{
cb.Text = "";
e.Handled = true;
}
HandlingSelectionChange = false;
}
当然有一个简单的答案,但一时找不到答案
答案 0 :(得分:2)
path 的声明应使用单引号(')。那么反斜杠(\)将不会被解释为转义字符。参见Gotchas
单引号和双引号之间的区别在于,在双引号中可以使用转义符
path: '{{ directory_path }}\AppName-{{ env }}'
代码缩进是错误的。正确的语法如下
tasks:
#Add Directory
- name: Add Directory
win_file:
path: '{{ directory_path }}\AppName-{{ env }}'
state: directory
#Add IUSR to directory path
- name: ADD IUSR
win_acl:
path: '{{ directory_path }}\AppName-{{ env }}'
user: IUSR
rights: Read
type: allow
state: present
propagation: 'NoPropagateInherit'
#Add website
- name: "{{ env }} Add App Name"
win_iis_website:
name: "AppName-{{ env }}"
state: started
port: 80
ip: "{{ serverip }}"
hostname: "appname-{{ env }}.com"
application_pool: "{{ application_pool4 }}"
physical_path: '{{ directory_path }}\AppName-{{ env }}'
register: website
用 ansible-lint 测试剧本是个好主意。