就像卡尔在这里的问题一样,我想问你(因为我自己找不到它:()如果通过删除非静态或动态(例如通过反射)的汇编引用有任何好处.
我有一个简单的问题,在Silverlight 3.0中设置一个复选框的双向数据绑定.它一定是不费脑子的,但今天我可能忘记了我的大脑...
我定义了一个Model类来表示我的''数据'.我实现了INotifyPropertyChanged接口,以使UI能够查看数据何时发生更改.
public class Model : INotifyPropertyChanged
{
private bool _value;
public bool Value
{
get { return this._value; }
set
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs("Value"));
this._value = value;
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Run Code Online (Sandbox Code Playgroud)
接下来,我在..'表单'上放了一个复选框和一个按钮:
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="check" IsChecked="{Binding Value, Mode=TwoWay}" Content="SomeLabel"/>
<Button Click="Button_Click" Content="Test" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
然后我在构造函数中提供了数据:
public MainPage()
{
InitializeComponent();
this.DataContext = new Model() { Value = true };
}
Run Code Online (Sandbox Code Playgroud)
问题是您必须在复选框上单击两次才能检查/取消选中,除非我取消实现INotifyPropertyChanged.但是,如果取消实现它,则UI不会注意到我是否更改了基础数据.
如果我从IsChecked绑定表达式中删除Mode = TwoWay位,那么即使模型正在实现接口,UI也不会注意到底层数据的更改.
我该怎么做:
data-binding silverlight checkbox silverlight-2.0 silverlight-3.0
如果我做
try(Lock lock = lockProvider.lock()) {
// some code that doesn't use variable lock
}
Run Code Online (Sandbox Code Playgroud)
编译器或JITer是否存在删除锁创建的风险,因为它在块中看到它未使用?
后来编辑:
一点背景.我来自.NET背景,在C#中,它允许执行以下操作:
using(Transaction tx = BeginTransaction())
{
// code that does things without touching the tx variable, such as SQL connections and stuff
}
Run Code Online (Sandbox Code Playgroud)
事实上它甚至可以缩短为
using(BeginTransaction())
{
// code that does things without touching the tx variable, such as SQL connections and stuff
}
Run Code Online (Sandbox Code Playgroud)
静态编译器和JIT编译器将保持BeginTransaction
调用,并且在运行时它将始终发生.
然而,在Java似乎是一个很大的问题和消极周围使用try-与资源用于其他的东西,是资源.
我需要构建一个ASP.NET Core 2.0 Web API应用程序,该应用程序将能够完成自定义XML输入和输出格式。
我已经成功设置了一个自定义输出格式化程序,但是没有一个自定义输入格式化程序。
更准确地说,这是启动配置:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc(opt =>
{
opt.ReturnHttpNotAcceptable = true;
opt.OutputFormatters.Clear();
opt.InputFormatters.Clear();
opt.InputFormatters.Add(new SoapInputFormatter());
opt.OutputFormatters.Add(new SoapOutputFormatter());
});
}
Run Code Online (Sandbox Code Playgroud)
这个想法是具有定制的SOAP输入和输出格式。不,现有的XmlDataContractSerializerInputFormatter
不会。
本SoapOutputFormatter
类:
public class SoapOutputFormatter : IOutputFormatter
{
public bool CanWriteResult(OutputFormatterCanWriteContext context)
{
return true;
}
public async Task WriteAsync(OutputFormatterWriteContext context)
{
var bytes = Encoding.UTF8.GetBytes(context.Object.ToString());
await context.HttpContext.Response.Body.WriteAsync(bytes, 0, bytes.Length);
}
}
Run Code Online (Sandbox Code Playgroud)
和SoapInputFormatter
班级:
public class SoapInputFormatter : InputFormatter
{
public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
{
throw new …
Run Code Online (Sandbox Code Playgroud) c# asp.net-web-api asp.net-core asp.net-core-2.0 inputformatter
直到我的salesforce res api都运行良好。突然我开始收到身份验证错误。重试您的请求。 Salesforce.Common.AuthenticationClient.d__1.MoveNext()。
salesforce通知它将从现在开始使用TLS .1.2。如何在Startup.cs中强制我的asp.net core 2.0使用TLS 1.2。下面是我的登录代码。
private async Task<AuthenticationClient> GetValidateAuthentication()
{
RestApiSetting data = new RestApiSetting(Configuration);
var auth = new AuthenticationClient();
var url = data.IsSandBoxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
? "https://test.salesforce.com/services/oauth2/token"
: "https://login.salesforce.com/services/oauth2/token";
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
await auth.UsernamePasswordAsync(data.ConsumerKey,
data.ConsumerSecret, data.Username, data.Password, url);
return auth;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
Run Code Online (Sandbox Code Playgroud) 我有时会用
if (this._currentToolForeColor.HasValue)
return this._currentToolForeColor.Value;
else
throw new InvalidOperationException();
Run Code Online (Sandbox Code Playgroud)
其他时候我用
if (this._currentToolForeColor.HasValue)
return this._currentToolForeColor.Value;
throw new InvalidOperationException();
Run Code Online (Sandbox Code Playgroud)
我知道,这两个是等价的,但我不确定哪个是最好的,为什么.
这更进一步,因为您可以使用其他执行控制语句,如刹车或继续:
while(something)
{
if(condition)
{
DoThis();
continue;
}
else
break;
}
Run Code Online (Sandbox Code Playgroud)
与
while(something)
{
if(condition)
{
DoThis();
continue;
}
break;
}
Run Code Online (Sandbox Code Playgroud)
编辑1:是的循环示例很糟糕,因为它们是合成的(即:弥补这个问题)不同于第一个实际的.
c# ×3
optimization ×2
.net ×1
asp.net-core ×1
assemblies ×1
checkbox ×1
data-binding ×1
if-statement ×1
java ×1
java-8 ×1
javacompiler ×1
jit ×1
load ×1
preferences ×1
reference ×1
salesforce ×1
silverlight ×1