有一些不同的方法可以在ASP.NET中创建多值cookie:
var cookie = new HttpCookie("MyCookie");
cookie["Information 1"] = "value 1";
cookie["Information 2"] = "value 2";
// first way
Response.Cookies.Add(cookie);
// second way
Response.AppendCookie(cookie);
// third way
Response.SetCookie(cookie);
Run Code Online (Sandbox Code Playgroud)
我什么时候应该使用哪种方式?我已经读过该SetCookie方法更新cookie,如果它已经退出.其他方式也不会更新现有的cookie吗?
编写单值cookie是以下代码最佳实践吗?
Response.Cookies["MyCookie"].Value = "value";
我有一个具有复杂属性类型的ViewModel,并希望将我的视图绑定到此对象的嵌套属性.
我的ViewModel正在实现INotifyPropertyChanged(或者确实是extact BaseViewModel正在实现它).父属性的类未实现INotifyPropertyChanged.
当我更新父属性的值时,嵌套属性不会更新.你能告诉我如何实现这个功能吗?
视图模型
public class ViewModel : BaseViewModel
{
private Car _myCarProperty;
public Car MyCarProperty
{
get { return _myCarProperty; }
set
{
if (value == _myCarProperty) return;
_myCarProperty = value;
OnPropertyChanged();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在视图中绑定
<TextBlock Text="{Binding Path=MyCarProperty.Manufacturer}" />
Run Code Online (Sandbox Code Playgroud)
当我更改MyCarPropertyView 的值时不更新.
谢谢你的帮助!
编辑:OnPropertyChanged()实现
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new …Run Code Online (Sandbox Code Playgroud) 我有这样的事情:
public class DomainEntity
{
public string Name { get; set; }
public string Street { get; set; }
public IEnumerable<DomainOtherEntity> OtherEntities { get; set; }
public IEnumerable<DomainAnotherEntity> AnotherEntities { get; set; }
}
public class ApiEntity
{
public string Name { get; set; }
public string Street { get; set; }
public int OtherEntitiesCount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并遵循映射器配置:
Mapper.Configuration.AllowNullCollections = true;
Mapper.CreateMap<DomainEntity, ApiEntity>().
ForSourceMember(e => e.OtherEntities, opt => opt.Ignore()).
ForSourceMember(e => e.AntherEntities, opt => opt.Ignore()).
ForMember(e => …Run Code Online (Sandbox Code Playgroud) 因为我已经为Visual Studio 2012安装了mysql连接器6.7.4和Update 3,所以MySQL连接器远离了Connection Manager对话框.
这是一个有效的项目,因此数据源配置是正确的.但是当我打开现有的*.edmx文件时,我收到一个错误(见下图).
我试图重新安装连接器,在每个安装步骤之间重新启动,控制GAC,但我无法让连接器再次工作.
我相信它与Update 3有关,正如答案帖子的评论中提到的:Visual Studio 2012上的mySQL DataSource
我无法阅读葡萄牙语,所以我不知道是否已经有解决这个问题的方法.
有人有同样的问题或有人知道解决方案吗?
最好的问候菲利克斯


我正在尝试了解扩展激活例程,也许有人可以帮助我。
在文件中package.json有activationEvents节点,我在其中定义了扩展将被激活的时间(例如,当通过 执行命令时onCommand)。查看帮助
从示例扩展的代码文档中,我了解到扩展只会在第一次执行命令时被激活。
当我在扩展中定义多个命令时会发生什么?我会在activate函数中注册所有命令并将它们添加到activationEvents:
"activationEvents": [
"onCommand:extension.testCommand1",
"onCommand:extension.testCommand2",
"onCommand:extension.testCommand3"
],
Run Code Online (Sandbox Code Playgroud)
该activate函数是否只会在第一次执行任何命令时调用一次?或者它会在第一次执行extension.testCommand1, extension.testCommand2and extension.testCommand3(--> 3 次)时调用函数?
我也在编写一个语言服务器,并希望将所有内容都放在同一个扩展名中。这是可能的还是我需要创建两个额外的扩展(客户端和服务器)?
我已经看到多个资源之间可能存在依赖关系。这样资源1就可以使用资源2的功能。资源之间的通信如何进行?
什么时候应该将脚本分离到不同的资源中?在整个游戏模式中坚持使用一种资源还是将其分开更好?
干杯
我写了一个customcontrol.它是一个带有按钮的文本框,用于打开OpenFileDialog.
TextBox的Text属性绑定到我的依赖项属性"FileName".如果用户通过OpenFileDialog选择文件,我将结果设置为此属性.
TextBox通过绑定获得正确的值.
但现在我的问题.对于我的观点,我正在使用ViewModel.所以我有一个绑定到我的DependencyProperty"FileName"到我的ViewModel中的属性.更改"FileName"属性(直接更改为文本框或通过对话框选择文件)后,viewmodel属性不会更新.
CustomControl.xaml.cs
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
namespace WpfApplication1.CustomControl
{
/// <summary>
/// Interaction logic for FileSelectorTextBox.xaml
/// </summary>
public partial class FileSelectorTextBox
: UserControl, INotifyPropertyChanged
{
public FileSelectorTextBox()
{
InitializeComponent();
DataContext = this;
}
#region FileName dependency property
public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register(
"FileName",
typeof(string),
typeof(FileSelectorTextBox),
new FrameworkPropertyMetadata(string.Empty,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(OnFileNamePropertyChanged),
new CoerceValueCallback(OnCoerceFileNameProperty)));
public string FileName
{
get { return (string)GetValue(FileNameProperty); }
set { /*SetValue(FileNameProperty, value);*/ CoerceFileName(value); }
}
private bool …Run Code Online (Sandbox Code Playgroud) 一位同事在他的VB.net解决方案中发现了有线调试器行为.我承认这将是一个学术问题,因为这只会影响调试时突出显示的语句序列,而不会影响代码的整体行为.所以对于所有好奇的人:
我们将其拆除为以下最小控制台应用程序:
Private Sub PlayWithExceptions
Dim a = 2
Try
throw new Exception("1")
Catch ex As Exception
If a = 2 Then
Dim x = New XElement("Dummy")
Else
throw
End If
End Try
End Sub
Sub Main()
Try
PlayWithExceptions()
Catch ex As Exception
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
很明显,调试器会抛出异常("1"),调试器会跳转到PlayWithExceptions方法的catch子句中.在那里,由于"a"始终为2,调试器跳转到一些虚拟代码(New XElement ...),从那里跳到"End If",最后返回到Else-leaf到throw语句.我承认Visual Studio不会重新抛出异常,但它看起来很奇怪.
将条件"If a = 2"更改为"If True"会消除此行为.
重构为条件捕获也消除了这种行为.
Private Sub PlayWithExceptions
Dim a = 2
Try
throw new Exception("1")
Catch ex As Exception When a = 2
Dim …Run Code Online (Sandbox Code Playgroud) 以下代码适用于类型集合IQueryable:
Expression<Func<Activity, bool>> filter = e => e.IsDeleted && e.CategoryId == 1;
但是这个表达式不适用于类型集合IEnumerable.
我如何修改表达式以使其正常工作?
在我的实际场景中,我的集合对象是实体框架模型类的导航属性: person.Activities.Where(filter);
这些是错误:
Error 1
Instance argument: cannot convert from 'System.Collections.Generic.ICollection<Application.Models.Activity>' to 'System.Linq.IQueryable<Application.Models.Activity>'
Error 2
'System.Collections.Generic.ICollection<Application.Models.Activity>' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Queryable.Where<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,bool>>)' has some invalid arguments
Run Code Online (Sandbox Code Playgroud) 我在php中有正则表达式的问题.
得到以下模式: ^\s*(\d{8})\s+(.+?)\s+(\d+,\d{2})\s.?\s(.*)$
我的搜索字符串如下:
12345678这是一个小产品描述,其中包含一些特殊字符,如®16,00€,也许这里有一些文字
我用这个PHP代码:
$regex = '/^\s*(\d{8})\s+(.+?)\s+(\d+,\d{2})\s.?\s(.*)$/';
echo preg_match($regex, $input);
Run Code Online (Sandbox Code Playgroud)
但没有比赛!
java或c#中的相同正则表达式模式有效!你能解释一下我做错了什么吗?
这里有一些在线正则表达式测试器:
PHP:http://regexp-evaluator.de/evaluator/d721ca1ed32d76db960262ba7298cff3/#ergebnis
c# ×5
wpf ×3
.net-3.5 ×1
altv ×1
asp.net ×1
automapper ×1
binding ×1
cookies ×1
datasource ×1
debugging ×1
exception ×1
expression ×1
ienumerable ×1
iqueryable ×1
java ×1
linq ×1
mvvm ×1
php ×1
regex ×1
vb.net ×1
wpf-controls ×1