Tag: .net

将值类型捕获到lambda中时是否执行复制?

struct SomeStruct { public int Num { get; set; } } class Program { static Action action; static void Foo() { SomeStruct someStruct = new SomeStruct { Num = 5 }; action = () => Console.WriteLine(someStruct.Num); } static void Main() { Foo(); action.Invoke(); } } 是否创建了lambda时创建的someStruct的副本? Foo返回时是否创建了someStruct的副本? 我可以validation没有发生复制吗? 在C ++中,我实现了复制构造函数并从中进行打印。 该标准的引文将不胜感激。 任何相关的在线文章也是如此。

数据库中的数据发生更改时,LINQ to SQL不会更新

我有这个问题,在数据库上更新字段(比如表MyTable中的Field3)后, MyTable.Field3 (在C#中)仍然返回旧值。 我怀疑有一些缓存……? 我如何强制它: 从数据库中读取值? 要么 更新MyTable类中的值? 或者有什么我想念的吗? 我是LINQ的新手 先感谢您。

SpeechSynthesizer无法获得所有已安装的声音

我在我的Windows 7 64位操作系统中安装了一个新的32位Scansoft语音(Jennifer),以便能够在我正在开发的一个.NET应用程序中使用。 问题是我在调用方法时: List allInstalledVoices = new SpeechSynthesizer().GetInstalledVoices(); 我只收到一个声音,默认的Microsoft Anna Voice。 但是我可以在其他文本到语音应用程序中看到所有已安装的声音。

自定义PowerShell主机并将PSObject转换回基本类型

托管PowerShell运行时是否可以将PSObject转换回其原始类型? 例如: 我有一个cmdlet调用WriteObject并在管道中推送一个ClassXzy集合。 当我从主机端调用PowerShell.Invoke时,我检索了一个带有BaseObject属性的PSObject集合。 将BaseObject为ClassXyz失败。 有没有办法将每个属性值映射到其对应的原始对象? 我假设PowerShell以某种方式执行此操作,因为您可以将PSObject传递给cmdlet并将它们转换为参数类型。 但是怎么样? 我花时间用reflection器撕裂了PS组件,但还没有真正确定这种魔法是如何发生的。 有任何想法吗? 编辑:我忘记了一个非常重要的细节。 我正在测试的PSObject是一个远程对象,因此BaseObject类型被命名为Deserialized.ClassXyz 。 这就是为什么我看到这种奇怪的行为。

启动和停止(强制)线程作业

我想知道一种正确的方法来启动和停止强制和非强制的线程作业。 这是停止线程的正确方法吗? public class ProcessDataJob : IJob { private ConcurrentQueue _dataQueue = new ConcurrentQueue(); private volatile bool _stop = false; private volatile bool _forceStop = false; private Thread _thread; private int _timeOut = 1000; public void Start() { _stop = false; _forceStop = false; _thread = new Thread(ProcessData); _thread.Start(); } private void ProcessData() { while […]

将vcards转换为Windows-1252

我正在尝试用C#编写一个程序,它将带有多个联系人的vCard(VCF)文件拆分为每个联系人的单个文件。 据我所知,vCard需要保存为ANSI(1252),大多数手机才能读取它们。 但是,如果我使用StreamReader打开VCF文件,然后使用StreamWriter将其写回(将1252设置为编码格式),则所有特殊字符(如å , æ和ø被写为? 。 当然ANSI(1252)会支持这些字符。 我该如何解决? 编辑:这是我用来读写文件的代码片段。 private void ReadFile() { StreamReader sreader = new StreamReader(sourceVCFFile); string fullFileContents = sreader.ReadToEnd(); } private void WriteFile() { StreamWriter swriter = new StreamWriter(sourceVCFFile, false, Encoding.GetEncoding(1252)); swriter.Write(fullFileContents); }

在ASP.NET MVC中使用重定向传递复杂对象?

嗨, 我有一个看起来像这样的动作: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Register(AdRegister adRegister, IEnumerable files) AdRegister是一个复杂的类,我需要将其传递给Register操作中的一个重定向方法,如下所示: return this.RedirectToAction(“Validate”, adRegister); Validate操作如下所示: public ActionResult Validate(AdRegister adRegister) 我知道我可以传递简单的参数但在这种情况下它是一个复杂的对象。 此示例不起作用,adRegister的属性将为null。 这是可能的,如果是这样,怎么样? 最好的祝福 更多信息:注册操作将采用adRegister并对其执行魔术,然后将其发送到Validate操作。 Validate操作将向用户返回validation页面。 当用户点击授权按钮时,将从表单中填充adRgister,然后将其发送到vValidatepost,并在其中保存。 我已经查看过暂时将adRegister放在缓存或数据库中,但如果我可以简单地将它传递给下一个操作,那就更好了。

如何在XAML中设置DataGrid的左上角样式?

与此问题相关: 样式数据网格表 – 左上角 。 我有一个DataGrid (尚未完成,原谅样式)。 如何使用XAML更改左上角的背景颜色(与其他问题中的C#相反)? 这是我目前的XAML: 额外奖励:如何在当前只有1px边框的行/列标题上获得2px边框?

获取仅包含文件的所有子目录

我有一个路径,我想列出它下面的子目录,其中每个子目录不包含任何其他目录。 (仅限那些不包含文件夹但仅包含文件的子目录。) 有任何聪明的方法吗?

WCF元数据缺少操作

我有一个在Visual Studio中运行的简单Web服务。 如果我尝试查看元数据,则缺少有关操作的信息,因此svcutil会生成客户端代码,而无需任何方法。 我的设置有什么问题吗? 接口: [System.ServiceModel.ServiceContractAttribute(Namespace=”http://Test/Publish”, ConfigurationName=”IFCRPublish”)] public interface IFCRPublish { // CODEGEN: Generating message contract since the operation PublishNotification is neither RPC nor document wrapped. [System.ServiceModel.OperationContractAttribute(Action=”http://Test/PublishNotification”, ReplyAction=”*”)] PublishNotificationResponse1 PublishNotification(PublishNotificationRequest1 request); } 响应: [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute(“System.ServiceModel”, “3.0.0.0”)] [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] public partial class PublishNotificationResponse1 { [System.ServiceModel.MessageBodyMemberAttribute(Namespace=”http://Test/PublishTypes”, Order=0)] public PublishNotificationResponse PublishNotificationResponse; public PublishNotificationResponse1() { } public PublishNotificationResponse1(PublishNotificationResponse PublishNotificationResponse) { […]