在这个答案中,https: //stackoverflow.com/a/8649429/1497 Eric Lippert说"我们很有可能在下一版本的C#中解决这个问题;对于开发人员而言,这是一个主要的痛点". foreach循环使用变量.
在下一个版本中,每次运行"foreach"循环时,我们将生成一个新的循环变量,而不是每次都关闭相同的变量.这是一个"突破"的变化,但在绝大多数情况下,"休息"将是修复而不是导致错误.
我无法找到任何表明此更改尚未完成的内容.有没有迹象表明这是foreach循环在C#5中的工作方式?
如何使用FormsAuthentication保存内容?我不想通过URL存储UserId.
例如,现在我有这个代码:
//UserController class:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (repository.ValidateUser(model.Login, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Login, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Project", "Index");
}
}
else
{
ModelState.AddModelError("", "Incorrect name or password.");
}
}
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
ProjectController 类:
public ViewResult Index()
{
return View(repository.GetUserProjects(
this.ControllerContext.HttpContext.User.Identity.Name));
}
Run Code Online (Sandbox Code Playgroud)
ProjectRepository:
ProjectsContext context = new ProjectsContext();
UsersContext uCnt = new UsersContext();
public IEnumerable<Project> GetUserProjects(String username)
{
if (String.IsNullOrEmpty(username))
throw new ArgumentNullException("username", "Login is …Run Code Online (Sandbox Code Playgroud) 我正在开发一个代码库,随着时间的推移,许多 React 组件都被重写和替换。其中一些组件是“功能性的”,向它们添加弃用标签会在我的 IDE 中触发警告和删除线样式。但对一个类执行相同的操作不会触发相同的视觉反馈。
如果没有 IDE 的反馈,并且JSDoc 文档稀疏,我不确定语法是否正确,或者@deprecated标记是否适用于类:
/**
* @deprecated
*/
class OldAndBusted extends React.Component
Run Code Online (Sandbox Code Playgroud)
相同的语法是否适用于类?您可以像函数一样将它们标记为已弃用吗?
在过去的几年里,我一直在混合模式的应用程序中使用WPF来显示各种各样的UI.C#程序集使用WPF生成UI - 它引用包含一些本机代码的C++/CLI构建的程序集.本机代码不会在少数printf之外调用OS; 这纯粹是计算机.
当附加调试器运行时,我看到关闭应用程序后,托管调试助手"RaceOnRCWCleanup"激活 - 表明存在一些带有多线程清理问题的COM组件.
我不是直接以任何方式使用COM,但可能是C++/CLI或WPF.关于应用程序关闭的警告并不是特别可怕 - 毕竟,应用程序仍在退出 - 但我很想知道出了什么问题.我能做些什么来避免这个警告吗?某个地方是否有一个隐藏的错误等着咬我,还是一个虚假的警告?
这是一个示例堆栈跟踪:
mscorlib.dll!System.Runtime.InteropServices.Marshal.ReleaseComObject(object o) Line 1826 + 0xc bytes C#
PresentationFramework.dll!System.Windows.Documents.TextServicesHost.DeactivateThreadManager() Line 465 + 0xd bytes C#
PresentationFramework.dll!System.Windows.Documents.TextServicesHost.OnUnregisterTextStore(object arg) Line 331 C#
PresentationFramework.dll!System.Windows.Documents.TextEditor.DetachTextStore(bool finalizer) Line 249 + 0x6b bytes C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(object state) Line 1363 + 0xfffffffc bytes C#
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) Line 484 + 0xce bytes C#
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过同样的问题?有人知道发生了什么吗?
我有一个软件产品,该数据库在SQLServer上创建数据库,并且表和列名由开发团队定义,然后使用Database First方法将模型导入到Visual Studio中,现在我们正在为其他公司开发相同类型的解决方案,使用ORACLE并为表和列请求命名约定,因此为了不更改现有代码并使用代码优先方法,我为所有类属性使用[Column]属性创建了具有正确命名约定的DbContext,但是现在,我正在尝试创建一个接口,以便我们可以注入不同的DbContext,并且在将来,我们将提供一个更加灵活的解决方案。
我是.Net的新手,但我的方法是为DbContext创建一个抽象类,并为表示表的每个类创建一个接口,因此在实现这些类中的每个类时,如有必要,我可以更改表和列的名称。我的问题是,可能吗?这是一个好方法吗?
using Microsoft.Graph
IMessageAttachmentsCollectionPage Message.Attachments
Run Code Online (Sandbox Code Playgroud)
我似乎无法得到它来获取 FileAttachment.ContentBytes 中的任何“ContentBytes”。
我的示例来自 Microsoft https://github.com/microsoftgraph/aspnet-snippets-sample。
// Create the message.
Message email = new Message
{
Body = new ItemBody
{
Content = Resource.Prop_Body + guid,
ContentType = BodyType.Text,
},
Subject = Resource.Prop_Subject + guid.Substring(0, 8),
ToRecipients = recipients,
HasAttachments = true,
Attachments = new[]
{
new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "testing",
Name = "tesing.png"
}
}
};
Run Code Online (Sandbox Code Playgroud) 我有一个使用透明度的PNG图像(它实际上是一个渐变效果的圆圈,从中间的黑色到边缘的透明).我正在使用这个表格TImage.我设置TForm1.Color和TForm1.TransparentColorValue相同的值和TForm1.TransparentColor:=true.
现在,当我运行程序时,图像的渐变部分将以表单的颜色显示.我正在寻找的是使用透明的表单效果启用PNG图像的透明度.
我究竟做错了什么?我正在使用Delphi 2010试用版.
我使用perl脚本替换数据文件中的某些字符串.从matlab程序中调用perl脚本,该程序在执行perl脚本之前和执行之后写入数据文件.
然后我的matlab程序将写入数据文件,但由于某种原因它不会.
这是一个最小的例子:Matlab代码:
f = fopen('output.txt','a');
fprintf(f,'This is written\n');
perl('replace.perl','output.txt');
fprintf(f,'This is not\n');
[fname perm] = fopen(f)
type('output.txt');
fclose(f);
Run Code Online (Sandbox Code Playgroud)
perl脚本:
#!/usr/bin/perl -i
while(<>){
s/This/This here/;
print;
}
close;
Run Code Online (Sandbox Code Playgroud)
变量fname和perm已正确分配.输出type只是"这里写的".
我对perl很新,所以我可能在剧本中犯了一些我无法找到的菜鸟错误.谢谢你的帮助.
我正在尝试使用“ 检测WPF验证错误”中的解决方案在WPF应用程序中执行验证。
public static bool IsValid(DependencyObject parent)
{
// Validate all the bindings on the parent
bool valid = true;
LocalValueEnumerator localValues = parent.GetLocalValueEnumerator();
while (localValues.MoveNext())
{
LocalValueEntry entry = localValues.Current;
if (BindingOperations.IsDataBound(parent, entry.Property))
{
Binding binding = BindingOperations.GetBinding(parent, entry.Property);
foreach (ValidationRule rule in binding.ValidationRules)
{
ValidationResult result = rule.Validate(parent.GetValue(entry.Property), null);
if (!result.IsValid)
{
BindingExpression expression = BindingOperations.GetBindingExpression(parent, entry.Property);
System.Windows.Controls.Validation.MarkInvalid(expression, new ValidationError(rule, expression, result.ErrorContent, null));
valid = false;
}
}
}
}
// Validate all the bindings on the …Run Code Online (Sandbox Code Playgroud) c# ×4
wpf ×3
.net ×2
.net-4.5 ×1
asp.net ×1
audio ×1
beep ×1
c#-5.0 ×1
clr ×1
data-binding ×1
delphi ×1
delphi-2010 ×1
foreach ×1
forms ×1
input ×1
io ×1
javascript ×1
jsdoc ×1
matlab ×1
perl ×1
png ×1
transparency ×1
uppercase ×1
validation ×1