.net-4.0

Default for generic type? [duplicate]

筅森魡賤 提交于 2019-12-04 23:36:56
This question already has answers here : Is there a reasonable approach to “default” type parameters in C# Generics? (5 answers) Closed 5 years ago . Is it possible to do something like public class PriorityQueue<TValue, TPriority=int> where TPriority : IComparable (note the =int ) ? Before you suggest it, yes, I know I can just add another line: public class PriorityQueue<TValue> : PriorityQueue<TValue, int> { } But I'm wondering if it's possible to do it as a param. No. There is no option for default types on generic types in C#. Your second example is often the "best" option available, if

Changing Socket Options on WCF net.tcp binding

社会主义新天地 提交于 2019-12-04 23:06:18
I have a .net 4.0 WCF application that uses the net.tcp binding and implements some service. I would like to set a TCP socket option for that binding ( ReuseAddress option. A related question explains why I want to do that). If I was working with Raw Sockets I could use the Socket.SetSocketOption Method. Is there a way to somehow extract the underlying Raw Socket from the net.tcp binding in order to change its options? Or some other way to set this option? Alicial Amir, Thank you for your suggestion of adding ReuseAddress option. However, we need understand better what was your concrete

A List<> of Func<>s, compile error with generic return type, but why?

霸气de小男生 提交于 2019-12-04 22:56:32
This is a bit of a lengthy question, so please bear with me. I need to create a mapping between a set of strings and corresponding generic method calls for each string. However I've run into a compile issue, explained lower down. In my scenario I am using a Dictionary<> , but the issue exists equally for a List<> . For simplicity I'm using a List<> in the example below. Consider these three classes: public abstract class MyBase { /* body omitted */ } public class MyDerived1 : MyBase { /* body omitted */ } public class MyDerived2 : MyBase { /* body omitted */ } And a method in some other class:

Cast List of Anonymous type to List of Dynamic Objects

守給你的承諾、 提交于 2019-12-04 22:56:18
Why can't I cast a List<AnonymousObject> to a List<dynamic> ? I have this following code: var datasource = someList.Select(o => new { x = o.A, y = o.B }); dgvSomeGridView.DataSource = datasource.ToList(); dgvSomeGridView.DataBind(); Then I access the GridView.DataSource with the following code: var ds = ((List<dynamic>)dgvSomeGridView.DataSource); .... But it throws an error on the line where I cast it to List<dynamic> , it says: Unable to cast object of type System.Collections.Generic.List'1[<>f__AnonymousType0'8[System.Int32,System.String]] to type System.Collections.Generic.List'1[System

Alternatives to SmartAssembly for exception handling and reporting?

不羁的心 提交于 2019-12-04 22:42:50
问题 I was happy with the SmartAssembly solution for exception handling, but I reported an issue on Red Gate forum and is not being solved yet. What alternatives exists to SA? I mean with similar features (hosting your reports, sending you e-malis, etc)? 回答1: SmartAssembly has two main features - obfuscation and error reporting. If you are using obfuscation, there are several free and commercial alternatives. The list linked to by TrueWill shows a good selection. For exception handling, the only

Repercussions of enabling useLegacyV2RuntimeActivationPolicy?

拜拜、爱过 提交于 2019-12-04 22:33:49
For my current project, we're using some CLR 2 based mixed mode assemblies. In order to use these from within a .NET 4 targetted assembly, I know you have to add useLegacyV2RuntimeActivationPolicy=true to the <startup> element within app.config . I understand that this changes the activation policy, causing these mixed-mode assemblies to be loaded using the highest supported version of the CLR. However, are there any side effects to doing this? What potential issues should I watch for when enabling the non-default activation policy? Well, sure, you'll be running the app with a CLR version it

Where is CorFlags.exe? (.NET Framework Tools)

徘徊边缘 提交于 2019-12-04 22:21:54
Where can I find the CorFlags.exe tool ? I made full search of my hard disk drive, but it was not found. I have: .NET Framework 4.0, Visual C# 2010 Express, Visual C++ 2010 Express. The OS is Windows 7 Ultimate 32 bit. It should be part of the Windows SDK , version 6 or higher, located somewhere like... %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\Bin\CorFlags.exe %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\Bin\x64\CorFlags.exe %ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\CorFlags.exe %ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\x64\CorFlags.exe %ProgramFiles%\Microsoft SDKs\Windows\v7.1

Break inner foreach loop and continue outer foreach loop

。_饼干妹妹 提交于 2019-12-04 22:20:49
If I have a nested foreach loop how do I do break the inner loop and tell the outer to continue at that point without doing any other code below the inner loop? foreach(var item in items) { foreach(var otheritem in otheritems) { if (!double.TryParse(otheritem)) { //break inner loop //continue outer loop so we never get to DoStuff() } } DoStuff(); } How about using a flag? foreach(var item in items) { bool flag = false; foreach(var otheritem in otheritems) { if (!double.TryParse(otheritem)) { flag = true; break; } } if(flag) continue; DoStuff(); } foreach(var item in items) { foreach(var

Add Reference in Framework 4 Application is not showing assemblies in GAC registered with GACUtil V 4

回眸只為那壹抹淺笑 提交于 2019-12-04 20:50:00
I've registered a dll in my local GAC using the GACUtil which comes with VS2010 (version 4ish) I can perform gacutil /l xxx and it finds the dll I am aware from various other posts that Framework 4 has it's own GAC and sure enough the file can be located in the directories within C:\WINDOWS\Microsoft.NET\assembly The problem for me, is that the .NET tab on the Add Reference dialogbox does not show my "GAC'ed" assembly. I've made sure that the projects properties are using the same version of the 4.0 framework, but I am currently at a loss. Has anyone else had this problem? Cheers in advance

Access the voting buttons extended property through Exchange Web Services

让人想犯罪 __ 提交于 2019-12-04 20:23:18
I'm using the Exchange Web Services (Exchange server 2007) to try to send an email with voting buttons in. I read this question/answer: Send Voting Email I have had a colleague using Outlook 2007 send me an email with simple yes/no voting buttons (the buttons display in Outlook, I have not sent an answer) and I can confirm that it is the first email in my Inbox. I've then used the EWS to get that email and try to get the extended properties relating to the email, so I can get the binary related to the voting buttons and thus send my own email with voting buttons. Here is my code.