clr

Project reference work-around .net 4.5 and .net 3.5

∥☆過路亽.° 提交于 2019-11-28 11:41:30
In continue for this thread: Mixing .NET 3.5 with 4/4.5 assemblies in the same solution/project I found a workaround: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/36b1a209-55d5-4323-91dc-0919ba2e1d03/ What it basically do, get my solution compile and determine each project under what CLR to run. Does anyone see disadvantage to this ? It builds the projects, on my 3rd party api that must run on .net 3.5, i explicity write on its App.config to run with CLR 2.0 and not 4.0 <startup> <supportedRuntime version="v2.0.50727"/> <!--<supportedRuntime version="v4.0"/>--> </startup> EDIT: My

Escape Catch-22 with extension attributes in .NET 2.0

怎甘沉沦 提交于 2019-11-28 11:11:55
How can a single .NET assembly, targeting 2.0, 3.0, 3.5, 4.0, and 4.5 concurrently, support extension methods for both C# and VB.NET consumers? The standard suggestion is to add this: namespace System.Runtime.CompilerServices { public sealed class ExtensionAttribute : Attribute { } } This the approach suggested by more than one Microsoft employee and was even featured in MSDN magazine . It's widely hailed by many bloggers as having 'no ill effects'. Oh, except it will cause a compiler error from a VB.NET project targeting .NET 3.5 or higher. The authors of Microsoft.Core.Scripting.dll figured

Load different version of assembly into separate AppDomain

﹥>﹥吖頭↗ 提交于 2019-11-28 10:32:05
I'm implementing application that supports plugins. Currently the problem arises when I try to load common assembly that is used both by host application and plugin: host application should use one version of that assembly, while plugin uses another version. This is dictated by application upgrade process - plugin can be updated separately from host application. Every assembly is signed, so I use strong names for loading assemblies. I created a test application which demonstrates the problem. Plugin assemblies are located in subfolder 'Plugin' of host application. Plugin folder contains the

MVVM binding to CLR Events

回眸只為那壹抹淺笑 提交于 2019-11-28 10:30:24
How do you go about binding to a CLR event using the mvvm pattern? For routed events I am using the EventToCommandTrigger from Cinch's framework and that is working great. I checked out the Behaviors and Effects from the Expression Blend Samples and it looks like the DataEventTrigger is what I should use, but the sample is a little confusing. I want the IsVisibleChanged event to fire my IsVisibleChangedCommand. I am also not sure what code needs to go in the ViewModel to support this. <i:Interaction.Triggers> <i:EventTrigger EventName="SelectedItemChanged"> <framework:EventToCommandTrigger

Array Bounds Check Elimination in the CLR?

断了今生、忘了曾经 提交于 2019-11-28 10:23:26
I was recently reading this article by Dave Detlefs in which he presents a few cases where the CLR performs array bounds check elimination. I decided to test this myself, so I did the following: Opened Visual Studio 2010 Ultimate SP1 Created a new C# project of type Console Application (targeting .NET 4 Client Profile by default) Added the following code (all sub-methods are taken directly from the article): class Program { static void Main(string[] args) { int[] array = new int[30]; Test_SimpleAscend(array); Test_SimpleRedundant(array, 3); foreach (int i in array) { Console.WriteLine(i); } }

Does C# inline properties?

扶醉桌前 提交于 2019-11-28 09:58:29
Does C# inline access to properties? I'm aware of the 32 byte (instruction?) limit on the JIT for inlining, but will it inline properties or just pure method calls? Jon Skeet It's up to the JIT (the C# compiler doesn't do any inlining as far as I'm aware), but I believe the JIT will inline trivial properties in most cases. Note that it won't inline members of types deriving from MarshalByRefObject which includes System.Windows.Forms.Control (via System.ComponentModel.Component ). I've also seen double fields end up being less efficient when accessed via properties - it could be that there are

String sorting performance degradation in VS2010 vs. VS2008

守給你的承諾、 提交于 2019-11-28 09:43:46
The following C# code seems to run slower when built with VS2010 than with VS2008: on a Core i5 Win7 x64 8 GB RAM PC, the VS2008 built version sorts strings in about 7.5 seconds, instead the VS2010 built version requires about 9 seconds. Why is that? Is there anything wrong with my code? Did the sorting algorithm change in VS2010? Is there anything different in the underlying CLR that makes the performance worse? using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; namespace StringSortCSharp { /// <summary> /// Console app to

What is the maximum number of parameters that a C# method can be defined as taking?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 09:34:45
I am trying to figure out what the maximum number of parameters a method in C# can have. I've checked everywhere for an answer, including the C# official documentation, MSDN, and a couple of CLR references and I can't find an answer. Does anyone have an answer to this question? Here is your theoretical answer: In order to push method arguments onto the stack, compiled code has the following MSIL opcodes to choose from: ldarg.0 ldarg.1 ldarg.2 ldarg.3 ldarg.S ldarg ldarg.0 to ldarg.3 is used to push the first 4 method arguments onto the stack (including this as the first argument for instance

Casting int[] to object[]

狂风中的少年 提交于 2019-11-28 09:11:00
问题 I encountered with question: why it's impossible cast int[] to object[] , e.g. object[] o = new int[] { 0, 1, 2 }; Meanwhile I can cast to just object and back to int[] . I'll be glad to hear deep answer. 回答1: Directly from the docs: Array covariance specifically does not extend to arrays of value-types. For example, no conversion exists that permits an int[] to be treated as an object[]. An array of ints or any other value-type is not an array of objects. Value types have different storage

Func<> with unknown number of parameters

依然范特西╮ 提交于 2019-11-28 09:09:36
Consider the following pseudo code: TResult Foo<TResult>(Func<T1, T2,...,Tn, TResult> f, params object[] args) { TResult result = f(args); return result; } The function accepts Func<> with unknown number of generic parameters and a list of the corresponding arguments. Is it possible to write it in C#? How to define and call Foo ? How do I pass args to f ? That's not possible. At best, you could have a delegate that also takes a variable number of arguments, and then have the delegate parse the arguments TResult Foo<TResult>(Func<object[], TResult> f, params object[] args) { TResult result = f