text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : Could someone please help enlighten me ? I went to check-in some changes to TFS and my check-in was rejected . It prompted me to take a look at a switch statement I had edited . What I 've found is that Visual Studio 2017 claims there is no compile time issue and allows me to build and deploy the application ...
Invalid Switch syntax builds successfully ?
C_sharp : What I 'm doing is looking up a value for a particular field in the hashtable . The object can be a handful of primitive types who 's value is destined to be put inside XML but it comes out of the hashtable as an object . So I have the problem of needing to decide what the type is , cast it up and then use th...
A clean way to cast to an objects actual type
C_sharp : In the following code : ... what is the meaning of ( i & 1 ) == 1 ? <code> Expression < Func < int , bool > > isOdd = i = > ( i & 1 ) == 1 ;
What is the meaning of the & operator ?
C_sharp : I have been reading a book called Clean Code A Handbook of Agile Software Craftsmanship . The author in the book motivates that a switch statement should be avoided and if it can not be avoided it should be relegated to factory methods . I have a connection object which is receiving various PDUs ( protocol da...
How can a switch statement be avoided if the return type is unknown by the calling method ?
C_sharp : I have viewed similar SO questions but can not figure out why mine wo n't work.I need to convert my Func < string , bool > value to an Expression to be used in the Moq framework but I can not get passed an error when trying to convert the Func to an Expression.This is the error : Static method requires null i...
Expression.Call causes `` Static method requires null instance , non-static method requires non-null instance ''
C_sharp : I was trying to find information about transforming an index that has been converted from a 2 dimensional index , to a single one . Then turn the single index back to a 2 dimensional one . I do n't even know what this method is called.formula to single indexSo my question is how do I turn it back into two dim...
Two dimension array to single dimension and back again
C_sharp : Let cls be of type XmlNodeFollowing statement allows me to access child nodes : Now when I try to use var : then the type of child is not XmlNode , only object . I can not use child.NodeType , compiler says : object ' does not contain a definition for 'NodeTypeWhy is this ? <code> foreach ( XmlNode child in c...
Why var used in foreach for XmlNode does not deduce real type , only object ?
C_sharp : If I save this string to a text file ; Hello this \n is a test messageThe \n character is saved as HEX [ 5C 6E ] I would like to have it saved as [ 0A ] .I believe this is an encoding issue ? I am using ; All this is inside a FileStream scope and uses fs.Write to write the encodedBytes into the file.I have tr...
C # '\n ' saved in different bytes than expected
C_sharp : Suppose I want to implement a functional composition , like this : Now in practice , I can use this Compose ( ) fn like this : And the result is FREDFRED . Is there a way to use a simpler syntax to invoke Compose ? I tried like this : ... but I get a compile error : error CS0411 : The type arguments for metho...
Inferring generic types with functional composition
C_sharp : How can I take advantage of the content negotiation pipeline when assigning to NancyContext.Response ? Currently my IStatusCodeHandler.Handle method returns JSON regardless of any content negotiation . I want this method to use JSON or XML according on any content negotiation ( preferably using the content ne...
Automatic Content Negotation When Assigning To Response
C_sharp : I am encountering what seems to be a very weird bug in ImmutableArray < > ( with BCL Immutable collections v1.0.12.0 , runtime .NET 4.5 ) : I have the following two identical structs exactly in the same source file under the same namespace : The following will throw an exception : If I project elements1 into ...
ImmutableArray < > behaves differently than Array < > for nested Select with index
C_sharp : Given a type , a name and a signature , how can I do a member lookup of the member with name name and signature signature using the C # rules of 7.4 ( the 7.4 is the chapter number from the C # Language Specification ) ( or at least part of them ... Let 's say I can live with an exact match , without conversi...
Resolving a member name at runtime
C_sharp : Looking to the implementation of the method in the List < > class ( .NET Framework 4.5.2 ) , I can see an iteration over a collection like thisI am wondering what could be the reason to prefer that syntax over this oneI have created an assembly with two methods each one using a different approach . Then , loo...
Iterating an IEnumerable < T > . Best way ?
C_sharp : in all ( Agile ) articles i read about this : keep your code and functions small and easy to test.How should i do this with the 'controller ' or 'coordinator ' class ? In my situation , i have to import data . In the end i have one object who coordinates this , and i was wondering if there is a way of keeping...
How to keep my functions ( objects/methods ) 'lean and mean '
C_sharp : My motivation for chaining my class constructors here is so that I have a default constructor for mainstream use by my application and a second that allows me to inject a mock and a stub . It just seems a bit ugly 'new'-ing things in the `` : this ( ... ) '' call and counter-intuitive calling a parametrized c...
Is this a good or bad way to use constructor chaining ? ( ... to allow for testing )
C_sharp : I am trying to put a mocked Range ( which contains cells with values ) inside the rows of a new Range . But when I try to access a specific element from the Range , a exception is thrown.I 've tried everything , does anyone have a idea what I am doing wrong here ? Exception Message : Test method xxx.MockUtils...
How to mock rows in a Excel VSTO plugin ?
C_sharp : Is there a way to Define a default constructor for all classes in a given assembly . For example I have classes like this in an assembly -These classes all require a default constructor but I do n't want to have to riddle all of these classes with a default constructor so how do I do this using reflection or ...
Define Default Constructor for existing classes in assembly
C_sharp : Does anybody see any drawbacks ? It should be noted that you ca n't remove anonymous methods from an event delegate list , I 'm aware of that ( actually that was the conceptual motivation for this ) .The goal here is an alternative to : And the code : } <code> if ( onFoo ! = null ) onFoo.Invoke ( this , null ...
C # Events and Lambdas , alternative to null check ?
C_sharp : I have two libraries written in C # that I 'd like to use in an F # application . Both libraries use the same type , however , I am unable to convince F # 's type checker of this fact.Here 's a simple example using the Office interop types . F # seems particularly sensitive to these type issues . Casting on t...
The type 'T ' is not compatible with the type 'T '
C_sharp : I 'm using NuGetVersion from the NuGet.Versioning package in LinqPad . I 'm trying to Dump ( ) it to inspect it 's properties , but instead of the usual dump I just get the string representation.For example , this : Shows the following in the output window : Does anyone know why LinqPad runs ToString ( ) when...
Why does LinqPad run ToString ( ) on some types when they are dumped ?
C_sharp : This question is particularly pointed at other C # devs coming over to TypeScript in VS Code.I fell in love with the code completion in VS C # . To illustrate , say I 'm trying to write : Using C # , I would have : type `` con '' a list of suggestions would appear , probably starting with `` console '' since ...
Can VS Code code completion be configured to accept a suggestion on punctuation ?
C_sharp : I am querying built-in TimeoutData entity in RavenDB using Raven.Client.Lightweight 2.5 library to get specific timeout document . It is possible that TimeoutData does not exist in the database because no document is stored there yet . In that case NotSupportedException is thrown when you try to query it.Curr...
How to check if table ( entity ) exists in RavenDB
C_sharp : Can I unit test my multi-threaded code using CHESS & MSTest in VS 2010 . I tried this but I get the following error <code> [ TestMethod ] [ HostType ( `` Chess '' ) ] [ TestProperty ( `` ChessExpectedResult '' , `` deadlock '' ) ] public void TestMyMethod ( ) { ... } The host type 'Chess ' can not be loaded f...
MSTest + CHESS in VS 2010
C_sharp : As I understand it , each language can have it 's own dynamic handler , so that the appropriate rules are applied . I 'm unsure if the following is correct/incorrect ; thoughts ? Scenario : two interfaces ( one implements the other ) with some methods : and a basic implementation : Now , with normal C # ( no ...
Should an interface-based method invoke that uses `` dynamic '' still obey C # method resolution rules ?
C_sharp : If I create a simple class like the following : and examine it within NDepend , it shows that the TestMethod taking a bool and being async Task has a struct generated for it with an enumerator , the enumerator state machine and some additional stuff.Why does the compiler generate a struct called TestClass+ < ...
Why does the async keyword generate an enumerator & additional struct when compiled ?
C_sharp : Using the silverlight Windows Phone 8.1 ProjectI 'm trying to load data from a website . I have to authenticate at that site first however.So I do a post to the Website , using a lightly modified version of the CookieAwareWebClient from here.Now I make a WebClient send a POST with Username and Password and co...
How can I retrieve multiple websites asynchronously ?
C_sharp : I 'm using events as part of a game model , and for extensibility and code `` locality 's '' sake I need to be able to veto most actions.More clearly , nearly every method that has a side effect takes this form : What I 'd like is for TryingToDoSomething ( ... ) to be able to indicate that a registered event ...
Is there a standard way to implement `` Vetoable '' events ?
C_sharp : A little background : I 'm a WPF to WinForms convertee and for some time I 've been migrating my application.I was reported by a friend that my code does n't work on Windows XP ( it generates a stack overflow at startup ) even though it works fine on Windows 7 ( which I develop in ) .After a little research ,...
Why does this code work on Windows 7 , but does n't on Windows XP ?
C_sharp : Imagine someone coding the following : We all know that in the example above , the call to the “ ToUpper ( ) ” method is meaningless because the returned string is not handled at all . But yet , many people make that mistake and spend time trying to troubleshoot what the problem is by asking themselves “ Why ...
C # Compiler Enhancement Suggestion
C_sharp : When I write a value into a field , what guarantees do I get regarding when the new value will be saved in the main memory ? For example , how do I know that the processor do n't keep the new value in it 's private cache , but updated the main memory ? Another example : Is there a possibility that after Write...
When do writes/reads affect main memory ?
C_sharp : I have to rotate JPG images lossless in .net ( 90°|180°|270° ) . The following articles show how to do it : https : //docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.encoder.transformation ? view=netframework-4.7.2https : //www.codeproject.com/tips/64116/Using-GDIplus-code-in-a-WPF-application-for-...
Lossless rotation of a JPG image with Image.Save and EncoderParameters fails
C_sharp : I have a program on .NET 4 for Windows . I 'm trying to port it for Mac computers with mono and Xamarin studio.I have third-part library EmguCV ( it 's a wrapper for OpenCV library ) . I 'm using official manual to install it . It installs both OpenCV and EmguCV to Library/Python/2.7/site-packages/emgucv/libW...
How to attach third-part libraries in release version
C_sharp : I ca n't get this to work for font names that are 16 characters or longer , but the console itself obviously does n't have this limitation . Does anyone know a programmatic way to set the font that will work with the built-in `` Lucida Sans Typewriter '' or the open source `` Fira Code Retina '' ? This follow...
SetCurrentConsoleFontEx is n't working for long font names
C_sharp : I have a case where I have the name of an object , and a bunch of file names . I need to match the correct file name with the object . The file name can contain numbers and words , separated by either hyphen ( - ) or underscore ( _ ) . I have no control of either file name or object name . For example : The o...
How to combine items in List < string > to make new items efficiently
C_sharp : With a setup like this , I can show a singular list containing books , authors , and bookmarks . I can drill down into a book , and see that specific books authors and bookmarks.Problem # 1 : I 'd like to drill down into an author , and see all of the authors books . On top of that , I 'd like to see all the ...
Architecting a collection of related items of different types
C_sharp : I have an Item that contains a list of Product 's which are mapped to their respective ViewModel objects using AutoMapper.In my MVC project I have an Action method that displays an Item with a selected Product . For this i have a ViewModel called ItemDetailsViewModel that contains the flattened Item object , ...
How to flatten a conditional object in a list in automapper
C_sharp : There are multiple related questions , but I 'm looking for a solution specific to my case . There is an array of ( usually ) 14 integers , each in the range of 1 to 34 . How can I quickly tell if each int in a specific , static list appears at least once in this array ? For reference , I 'm currently using t...
How can I quickly tell if a list contains a list ?
C_sharp : First of all , I want to say that I 'm new to C # , so this question may seem completely off track.I have a set of enumerables called ShapeType : And a method to return a random value from the enumerables : Every enumerable has a corresponding concrete class . And the question I 'm wondering about is if you c...
Use variable as type and instantiate it
C_sharp : I have an application which takes a string value of the form % programfiles % \directory\tool.exe from its application config file.I want to make this into a useable filename so that I can call and have it execute the application . I 'm curently getting a System.ComponentModel.Win32Exception - The system can ...
How do I convert a string of the form % programfiles % \directory\tool.exe to a useable Filename in C # /.net ?
C_sharp : I 'm trying to create a class that takes a lambda and stores it internally . The syntax would be something like : Usage : But I 'm having some trouble figuring out the details . I know that a lambda is an anon type until it 's assigned to either an expression or a delegate and that I would ( I believe ) have ...
Implicit Operators and lambdas
C_sharp : I 'm trying to write a VBA parser ; in order to create a ConstantNode , I need to be able to match all possible variations of a Const declaration.These work beautifully : Const foo = 123Const foo $ = `` 123 '' Const foo As String = `` 123 '' Private Const foo = 123Public Const foo As Integer = 123Global Const...
Parsing VBA Const declarations ... with regex
C_sharp : I am working on an application in which have different repositories for different entities and now i have to put search logic , hence i am confused where should i put my search logic , should i create a new repository for search or should i put the logic in the existing repository , and if i should put in som...
Best Practices | Where to put search logic if we have different repository for each entity
C_sharp : I was working with some C # code today in the morning and I had something like : So , as I dont have a full understanding of the language framework I would like to know if GetDataTable ( ) gets called each time an iteration is done or if it just gets called once and the resulting data ( which would be Rows ) ...
Does a method that returns a collection get called in every iteration in a foreach statement in C # ?
C_sharp : I have some code that is meant to get files in a directory , which is simple enoughThe files are named as follows : My issue is that it is not picking up the last file.I have fixed the code by putting this instead : Saying get any files that contains both Totals and .csv , with anything after the .csv.What I ...
Directory.GetFiles does n't pick up all files
C_sharp : allI have searched this question , and I found so many answers to it was not difficult to find a solution for my question.BUT , I have strange experience and I do n't know the reason that 's why I ask people to give me some advice.Here are my codes : Yes , they are ordinary thread codes.I expect all the threa...
How to pass arguments to thread in C #
C_sharp : I have a data object with three fields , A , B and C. The problem is that the user can set any of them because : A * B = CSo if a user starts off by setting A & B , C will be calculated . but then if a user set C , A gets recalculated , so there is an implicit anchoring that is happening based off the last fi...
3 way calculation
C_sharp : I 'm thinking of something along the lines of the `` Inline Task '' in MsBuild . For reference : http : //msdn.microsoft.com/en-us/library/dd722601.aspxI 'd like to find or create a framework which allows me to override a method via configuration . For example if I have a well known base class which has a met...
How best to create and execute a method in a .NET ( C # ) class dynamically through configuration
C_sharp : Can somebody explain why the .Net framework team decided that a delegate without subscribers should be null instead of an object with an empty InvocationList ? I 'd like to know the rationale that led to this decision.Thanks <code> void DoSomething ( ) { EventHandler handler = SomeEvent ; if ( handler ! = nul...
Why are delegates null rather than an empty list when there is no subscriber ?
C_sharp : Consider this function , which you can think of as a truth table : The compiler insists on that last else clause . But from a truth table 's perspective , that is an impossible state.Yes , it works , and yes , I can live with it . But I 'm wondering if there is some mechanism in c # to avoid this sort of code...
How can I avoid an impossible boolean state in c # ?
C_sharp : I 'm trying to determine how AsParallel ( ) splits it 's 'source ' , and indeed what is meant by 'source ' ... For example ... Then put 500k varying CSVItem 's into CSVItemList.Then use : Will it only split the 'source ' ( meaning for example 250k records onto each of two threads ) onto multiple asynch thread...
How does AsParallel ( ) split it 's 'source ' ?
C_sharp : Modern unit tests frameworks support awaiting the results of an asychronous unit test , like this : Is there any advantage of using this async approach over simply blocking ? Does the async only provide a benefit when running tests in parallel ? <code> public async Task SomeTest ( ) { var result = await SomeM...
Advantage of async/await over blocking in unit tests
C_sharp : The following two C # functions differ only in swapping the left/right order of arguments to the equals operator , == . ( The type of IsInitialized is bool ) . Using C # 7.1 and .NET 4.7.But the IL code for the second one seems much more complex . For example , B is:36 bytes longer ( IL code ) ; calls additio...
Argument order for '== ' with Nullable < T >
C_sharp : I must be doing something dumb : So why when i = 7 is ans coming out at 2.0 ? i is an int <code> float ans = ( i/3 ) ;
Simple division
C_sharp : Consider the following ( VS 16.8.0 Preview 2.1 C # 9.0 preview ) code : I am having a hard time understanding/addressing the errors in F3 , Seems like the compiler thinks johnAge there is long not long ? ( as I verified by hovering over it in VS ) despite the return of Archive < T > .GetAt being T ? Is there ...
C # 9 Nullable types issues
C_sharp : I was under the impression that in .NET casting ( not converting ) is very cheap and fast . However , this does not seem to be the case for array . I 'm trying to do a very simple cast here , take a T1 [ ] and cast as T2 [ ] . where T1 : T2.There are 3 ways to do this and I 'm calling them the following : :An...
Why is casting arrays ( vectors ) so slow ?
C_sharp : I have a Silverlight 5 application trying establish a socket connection to a server as follows : I have the following clientaccesspolicy.xml file at https : //subdomain.maindomain.com/clientaccesspolicy.xml : I am able to run a local instance of the Silverlight application from visual studio and can establish...
Silverlight 5 Opening Socket AccessDenied
C_sharp : We have implemented a localized version of an ASP.NET MVC website which has a URL structure as following : url : // { language } - { culture } / { controller } / { action } / { id } In this way we can generate URLs by language which are properly crawled by Google bot : http : //localhost/en-US/Homehttp : //lo...
Pre-Append Route if not available
C_sharp : I have been looking for a way of splitting a foreach loop into multiple parts and came across the following code : Would items.Skip ( currentPage * itemsPerPage ) .Take ( itemsPerPage ) be processed in every iteration , or would it be processed once , and have a temporary result used with the foreach loop aut...
Linq optimisation within a foreach
C_sharp : I noticed something strange when trying to pass a StringBuilder 's Append method to a function that took an Action < string > .For testing purposes , I just want to write the data into a StringBuilder , so I tried to call it like this : However , this gives a compile error , because the Append method does not...
Why can ` s = > x.Append ( s ) ` can be passed as an Action < string > but ` x.Append ` ca n't ?
C_sharp : To keep my code cleaner I often try to break down parts of my data access code in LINQ to SQL into private sub-methods , just like with plain-old business logic code . Let me give a very simplistic example : I 'm sure no one 's imagination would be stretched by imagining more complex examples with deeper nest...
Rules for LINQ to SQL across method boundaries
C_sharp : Today I faced a problem and I 'm not able to get weather I understand something wrong about ASP.NET MVC ( and possibly MVC in general ) or I miss something about it 's implementation.So , I have a simple model hierarchy : Here is my HomeController 's Edit actions : Hese is my Edit.aspx view : The point is tha...
ASP.NET MVC rendering model not the way I expect
C_sharp : I am trying to get better with IoC , DI and OOD for better testability and looser coupling.So when we design classes with heavy use of IoC and DI we can endup with classes with multiple dependencies for exampleIm thinking what should be the usual approach here . We can leave constructor with 3 parameters , bu...
OOD using IoC containers - how to construct dependant objects ?
C_sharp : I need to connect my NET Framework 4 Client App , to a Webservice , deployed on a Apache CXF , with WS Security . That service is out of my control.The service is added to the project as a `` Service Reference '' .This is the proxy : Well . The server accepts my Request , and send the the response , in this w...
Apache CXF WS Security WebService from NET Client - Can not resolve KeyInfo for unwrapping key
C_sharp : I have a main application that loads up some plugins . These plugins are loaded and run in separate app domains using a class that inherits from `` MarshalByRefObject '' ; This all works fine.What I need now is a way to handle when the plugin wants the main app to do something and a way to dynamically handle ...
What ways can I send data from a plugin across an app domain that triggers an event in the main application in C # ?
C_sharp : I found this other stack overflow question about files and directories , and the answer included this statement : His question was about .net , and I was coding in C # .net in Visual Studio . Is the ability to have both an assignment operator and an equals operator in the same statement work for all .net lang...
How can a statement have both = and == ?
C_sharp : Quick question . I have a listbox being populated from a directory listing . Each file contains its name and ~ # # # # # . I 'm trying to read it all into a string and replace the ~ # # # # with nothing . The # # # # could be digits from length 1-6 and could be anything from 0-9 . Here 's the code I 'm using ...
C # string replacement question
C_sharp : I am using this iOS SegmentedControlRenderer on a page . But when I go to the page this way : Navigation.PushAsync ( new CFSPage ( ) ) and then click on the back arrow to go to the previous page , the OnElementChanged event in my customer iOS renderer is fired . The result with my renderer is that the followi...
Does a controls OnElementChanged ( ) get called when I leave a page ?
C_sharp : I 'm trying to open a thumbscache.db file , I 've tried to open it like any other database but no use . I 've also looked for any API or support in C # . Kindly suggest if there is another way.BTW below is my approach so far.1 . Open it like any other db.But this exception comes up.2 . Open it using ShellFile...
How to open Thumbscache.db
C_sharp : Every time we need a high decimal-precision , we use decimals to do the calculations . Is there any way to check if the precision did suffice for the calculation ? I would like to make the following code throw an exception : It does n't really matter in real code , but it would be nice to be safe . <code> dec...
How to get an exception on inaccurate calculation ?
C_sharp : I 've created a simple .NET Framework 4.7.2 WPF app with two controls - a text box and a button . Here is my code behind : After pressing StartTest button I see the following results in the Output text box : My question is why [ 7 ] Task delay has been cancelled . is executed in the same thread where token ca...
Unexpected task cancellation behaviour
C_sharp : I have these two statements : What I would like to do is to check if changes ( ) = 0 in the first statement before running the second statement . Can anyone tell me how I can group together these two statements in to one so I can check the value of changes ( ) ? <code> db2.Execute ( `` UPDATE CLICKHISTORY SET...
How to combine two SQLite statements running in C # ?
C_sharp : We 've been using EF 4.0 with a database-first approach using an .edmx model.We 're now upgrading to EF 6.1.3 , and we 're investigating whether to go with or without that .edmx model . We definitely still want to be in control of our database schema - so we 'll be creating new tables etc . with SQL script an...
Influencing how entity classes are created in EF 6 code-first from database
C_sharp : I 'm working on upgrading my .NET Core 2.2 MVC application to 3.0 . In this application I 'm authenticating to a controller using a JWT token . The token contains several claims , but when I try to access them through User.Claims the resulting list is always empty.In my Startup.cs I have the authentication se...
User.Claims Is Empty In MVC Application
C_sharp : I can calculate cluster membership with KMeans pretty easily : Can I calculate partial membership with the standard KMeans algorithm ? A coworker suggested using the mean and variances of the cluster members to determine proportional membership and today I 've been looking into fuzzy sets and their implementa...
Find partial membership with KMeans clustering algorithm
C_sharp : Let 's say I have a class that will be called from multiple threads , and am going to store some data in an ImmutableDictionary in a private field in this classCould this be called in such a way by multiple threads that you will get an error about the key already existing in the dictionary ? Thread1 checks di...
Using Bcl ImmutableDictionary in private field
C_sharp : I believe ( correct me if i am wrong ) , according to the C # rule for value types , there is no default constructor . The CLR will define the one for zeroing out the field values.For reference type : Will the default constructor be supplied by C # or the CLR ? <code> class Test { private string Name ; }
Does the C # Compiler supply a default constructor for reference types ( if one not specified ) or does the CLR ?
C_sharp : My class with an event : Derived event class : Some other class that register it to the event : What have I gained from following the .Net convention ? It would make more sense to have a contract like thisDoing it this way , I do n't need to create a new class and is easier to understand.I am not coding a .Ne...
Events convention - I do n't get it
C_sharp : I am pretty sure this was asked before but unfortunately the only thing I 've found was this that was not solution for me . In my current project I do something like : This code does not work of course because I 've not cast obj because its type changes dynamically.How can I cast it dynamically ? <code> priva...
How can I cast object dynamically ?
C_sharp : Using xUnit 's Assert.Throws , I stumbled upon this ( to me ) hard to explain overload resolution issue . In xUnit , this method is marked obsolete : The question is , why does an inline statement lambda ( or expression ) that simply throws an exception resolve to this overload ( and therefore does n't compil...
Why does this Assert.Throws call resolve this way ?
C_sharp : We have this code which serves a download : It works fine , except that the log download code runs as soon as the download starts seemingly , not when the download has fully completed as we expect.Can someone explain why this is , and how to change it so it only logs when it 's completed ? We do n't want to c...
Only count a download once it 's served
C_sharp : What is the best way in C # to get a collection of objects representing the changes between two XML texts , e.g . : First : Second : Changes : The point is to then pass the changes as a collection of objects onto a GUI which can appropriately display them.What is the best way to go about this , i.e . structur...
How to get a collection of objects representing the diff between two XML texts ?
C_sharp : What would be the way to call some method by name , like `` Method1 '' , if I 've got an Object and it 's Type ? I want to do something like this : Is this somehow possible ? I do realize that this would be slow , it 's inconvenient , but unfortunately I 've got no other ways to implement this in my case . <c...
How do you call a method by its `` name '' ?
C_sharp : I want to write a rule that will fail if an object allocation is made within any method called by a method marked with a particular attribute.I 've got this working so far , by iterating up all methods calling my method to check using CallGraph.CallersFor ( ) , to see if any of those parent methods have the a...
Determining if a method calls a method in another assembly containing a new statement and vice-versa
C_sharp : I 'm trying to build a code sample to show the optimization of code by the compiler when multiplying with a power of 2 number . Yet when I turn Optimize code on the IL remains mainly the same . Any ideas what I 'm doing wrong here ? The code : Non Optimized IL : Optimized IL : I thought the compiler would opt...
When does the compiler optimize my code
C_sharp : Areo Glass Effect and windowStyle set to none and AllowTransparency causes widow resize to not function properlyAfter adding the Areo Glass theme to my window and setting WindowState to None the window does not resize properly . I can go as large as I want but when resizing down smaller the glass effect stays...
Areo Glass Effect and windowStyle set to none causes window resize to not function properly
C_sharp : C # 6.0 in a Nutshell by Joseph Albahari and Ben Albahari ( O ’ Reilly ) . Copyright 2016 Joseph Albahari and Ben Albahari , 978-1-491-92706-9.states the following at page 96 , after introducing Implicit Calling of Parameterless Base-Class Constructor : If the base class has no accessible parameterless constr...
When are derived classes constructors forced to use base keyword ?
C_sharp : I 'm writing a program that is container for other , smaller programs . It loads it 's modules via Assembly.Load , finds types implementing IModule and makes instances of them.In WPF MainWindow I have a RoutedViewHost , which will display everything.In my AppBoostrapper , I have the following : Then , in my s...
`` Could n't find an IPlatformOperations . This should never happen , your dependency resolver is broken '' on WPF
C_sharp : For example I have the following flag enum : According to MS Guidelines : DO name flag enums with plural nouns or noun phrases and simple enums with singular nouns or noun phrases.So I 've used plural form here . Now , there is another guideline to name your collections in plural form : DO name collection pro...
How to name a collection of flags ?
C_sharp : I 'm looking at domain events , specifically at 2 possibilities : A . Using `` generic '' events like that : then the consumer would figure out the new state and do something . Since I 'm using Rx this would be not that hard ( and way better than a switch/case ) : B . Using specific events : this would lead t...
DDD generic vs. specific domain events
C_sharp : I was trying to create an example for deadlock . I tried the following code . But instead of creating deadlock , it worked like charm . Help me in understanding why it did n't create a deadlock . What change in this code would create a deadlock ? <code> using System ; using System.Collections.Generic ; using ...
Dead lock in Multithreading
C_sharp : I 'm working on obtaining RSS feeds like so : XmlReader.Create ( ) in this case can throw up to 4 exceptions related to things like the parameter being null , 404 error , etc.Should I try to validate the Uri ( make sure it 's not null , 404 , correct doctype , etc ) before I call that line or should I just ha...
Catch exception , validate input or both ?
C_sharp : Edit : It seems that by trying to provide some solutions to my own problem I blurred the whole problem . So I 'm modifying the question little bit.Suppose I have this class : It is actually not important what 's going on in these methods . The important is that I have multiple unit tests to cover GetProtocolH...
How to keep my unit tests DRY when mocking does n't work ?
C_sharp : Not sure if there 's a algorithm to describe this problem but are there any elegant methods to combine the list in a custom sequence . For example : I would like the contents of combined to contain a sequence as follows : The number of records in each list may not be equal . EDITWhen the number of records in ...
How to combine multiple lists with custom sequence
C_sharp : I have some code for strongly typing Includes ( ) 's in linq , like so ... My question is , is there anyway I can write a more generic function account for any level of successive includes ? Rather than having to rewrite it for say 3 , 4 , etc include types ? <code> public static ObjectQuery < T > Include < T...
Query Extension for LINQ
C_sharp : I 'm using Visual Studio 2012 Update 1 and .NET 4.5 here is the code.It appears the last function call is incorrectly resolving to Func instead of Action and it has something to do with unconditionally throwing an exception.Is this a BUG ? Thanks . <code> void Test ( Action a ) { } void Test ( Func < int > a ...
Resolving incorrect function at compile time BUG ?
C_sharp : I am currently working on an extension method that facilitates what the question 's title suggests.I could , of course . use the GetMetohd ( `` Invoke '' ) method call on the type and be done with it , But something tells me this is not the `` safest '' way to go.Classes and types may change , including those...
Safest way to get the Invoke MethodInfo from Action < T > 's Instance
C_sharp : I have a system in which the main form is the menu , and it pops up a login form on loading . Originally it loaded the login form below the menu , so I used this.topmost = true to make it come to the front . ( as bring to front and send to back did not work ) However , if the user then clicks on something els...
Login form not losing focus correctly
C_sharp : I 'm trying to read information from an SSL certificate ( in this case I 've saved a copy of StackOverflow 's via Chrome ) but for some reason the moment I build it and run it from within a Linux Docker container , it fails to output anything.On Windows the output is what I expect : But the output from the sa...
Ca n't read certificate when running in Linux Docker container - works on Windows
C_sharp : Here 's the setup : Having the following data : Now I 'm trying to get the following result in ONE linq statement : I 've tried grouping , using selectmany , joins and I ca n't seem to find the proper way.Any Linq wiz around ? P.S : Also , I want to traverse the master list only once ... ; ) <code> public cla...
Using Linq and C # , trying to get two lists from a list of master items grouped by two inner lists
C_sharp : I 'm try to parse this xml , but c # keeps throwing an exception saying it has invalid characters . I ca n't copy the text from the messagebox directly , so I 've screened it . http : //img29.imageshack.us/img29/694/xmler.jpgEdit : copied textHere 's the code to get the string <code> < ? xml version= '' 1.0 '...
XmlTextReader issue