有好文章提出了不同的实施方式INotifyPropertyChanged.
考虑以下基本实现:
class BasicClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void FirePropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
private int sampleIntField;
public int SampleIntProperty
{
get { return sampleIntField; }
set
{
if (value != sampleIntField)
{
sampleIntField = value;
FirePropertyChanged("SampleIntProperty"); // ouch ! magic string here
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想用这个替换它:
using System.Runtime.CompilerServices;
class BetterClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// Check the attribute …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
PropertyInfo[] originalProperties = myType.GetProperties();
Run Code Online (Sandbox Code Playgroud)
我想从originalProperties所有索引器中排除(myVar ["key"]显示为名为"Item"的属性).
什么是正确的方法?
排除所有propInfo.Name == "Item"不可选的属性.
我喜欢将自定义属性添加到Application Insights 为我的应用程序的每个请求采取的指标.例如,我想添加用户登录和租户代码,例如我可以在Azure门户中对指标进行分段/分组.
相关的doc页面似乎就是这样:设置默认属性值
但是示例是针对事件(即gameTelemetry.TrackEvent("WinGame");),而不是针对HTTP请求:
var context = new TelemetryContext();
context.Properties["Game"] = currentGame.Name;
var gameTelemetry = new TelemetryClient(context);
gameTelemetry.TrackEvent("WinGame");
Run Code Online (Sandbox Code Playgroud)
我的问题:
TelemetryContext足够的代码吗?我是否应该创建一个TelemetryClient,如果是,我应该将它链接到当前请求吗?怎么样 ?Application_BeginRequest方法可以global.asax吗?当我们使用Nuget安装MVVM Light Toolkit时,似乎没有安装MVVM Light的片段.
我在哪里可以找到它们?
With Visual Studio 2013, I used to open 2 instances of Visual Studio :
The 2 solutions have a common project, but this was not an issue : I could start the first in debug mode, start the second in debug mode, find a bug, stop one to fix the bug, and start it again (without stopping the second).
This scenario is …
在Windows Azure存储中,我们曾经这样做来创建表:
var tableClient = account.CreateCloudTableClient();
tableClient.CreateTableIfNotExist(TableName);
Run Code Online (Sandbox Code Playgroud)
我刚刚下载了最新版本的azure存储库(v2),而我之前的代码不再适用了:
'Microsoft.WindowsAzure.Storage.Table.CloudTableClient'不包含'CreateTableIfNotExist'的定义,并且没有扩展方法'CreateTableIfNotExist'可以找到接受类型'Microsoft.WindowsAzure.Storage.Table.CloudTableClient'的第一个参数.
v2中的优秀代码是什么?
我的目标是能够在XAML中编写:
<Grid>
<Rectangle Fill="AliceBlue"
myCore:MyTimePanel.BeginningDate="03/03/2010"
/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
问题: Silverlight XAML无法从字符串中解析DateTime.所以在运行时我有XamlParseException"无法从该字符串创建DateTime".
当我使用一个简单的DependencyProperty时,我只需在getter/setter上添加一个TypeConverterAttribute即可.像这样(来自这里的想法):
[TypeConverter(typeof(DateTimeTypeConverter))]
public DateTime MyDate
{
get { return (DateTime)GetValue(MyDateProperty); }
set { SetValue(MyDateProperty, value); }
}
Run Code Online (Sandbox Code Playgroud)
但是附加了 DP,没有getter/setter.如何才能在XAML中编写字符串日期?
谢谢 !
我有一个有效日期的字符串,但它是一个字符串,它需要是一个字符串.但是,当我尝试将其自动映射到日期时,它会抛出异常
Trying to map System.String to System.DateTime.
Trying to map System.String to System.DateTime.
Using mapping configuration for ViewModels.FormViewModel to Framework.Domain.Test
Destination property: DueDate
Missing type map configuration or unsupported mapping.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: AutoMapper.AutoMapperMappingException: Trying to map System.String to System.DateTime.
Using mapping configuration for …Run Code Online (Sandbox Code Playgroud) 我需要以编程方式使用C#获取Git历史记录中特定行的最后一位作者.我尝试使用libgit2sharp:
var repo = new LibGit2Sharp.Repository(gitRepositoryPath);
string relativePath = MakeRelativeSimple(filename);
var blameHunks = repo.Blame(relativePath);
// next : find the hunk which overlap the desired line number
Run Code Online (Sandbox Code Playgroud)
但这相当于命令
git blame <file>
事实上我需要
git blame -w <file> (比较时忽略空格)
Libgit2sharp不设置-w开关,也不提供任何参数/选项来设置它.我有什么选择?你知道其他任何与命令-w切换兼容的库blame吗?
我们有一个MVC 5.1项目,正在使用属性路由.一切都工作正常,除了默认页面上有登录表单.
[RoutePrefix("Home")]
public class HomeController : BaseController
{
[Route("~/")]
[Route]
[Route("Index")]
[HttpGet]
public ActionResult Index()
{
var model = new LoginViewModel();
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(String Username, String Password)
Run Code Online (Sandbox Code Playgroud)
表格通过GET罚款显示,但在POST后我们得到......
HTTP错误405.0 - 不允许的方法
由于使用了无效的方法(HTTP动词),因此无法显示您要查找的页面.
通常,默认路由将处理POST和GET罚款.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{dealerId}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
显然我在默认路由上的帖子的路由中遗漏了一些东西,因为其他页面上的后续帖子工作正常.
有没有人这样做过?
谢谢,
c# asp.net-mvc-routing attributerouting asp.net-mvc-5 asp.net-mvc-5.1
c# ×9
.net ×1
asp.net ×1
automapper ×1
azure ×1
git ×1
git-blame ×1
libgit2 ×1
libgit2sharp ×1
mvvm-light ×1
propertyinfo ×1
reflection ×1
silverlight ×1
xaml ×1