background preloader

Build cross platform desktop apps with JavaScript, HTML, and CSS.

Build cross platform desktop apps with JavaScript, HTML, and CSS.
Related:  .NET / C#

How generics save from boxing | {coding}Sight At the method input, we often perform a null test. Someone makes the test as a separate method, so that the code looks cleaner, and gets something like this: public void ThrowIfNull(object obj) { if(obj == null) { throw new ArgumentNullException(); } } The interesting thingabout this test is that I see a frequent use of the object attribute, though you can use generic. Before testing, you need to take into account another drawback of the object argument. Let’s start testing the performance and use the BenchmarkDotNet library. Our generic showed 2000 times faster performance on the nullable type! Thus, the generic argument is better than the object because it: Saves from boxingImproves the method signature by using constraints

Exemples de requête LINQ Cette documentation est archivée et n’est pas conservée. Date de publication : janvier 2017 S’applique à : Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online L’exemple suivant montre comment récupérer une liste de comptes où Name contient « Contoso ». using (ServiceContext svcContext = new ServiceContext(_serviceProxy)) { var query_where1 = from a in svcContext.AccountSet where a.Name.Contains("Contoso") select a; foreach (var a in query_where1) { System.Console.WriteLine(a.Name + " " + a.Address1_City); } } L’exemple suivant montre comment récupérer une liste de comptes où Name contient « Contoso » et Address1_City a la valeur « Redmond ». using (ServiceContext svcContext = new ServiceContext(_serviceProxy)) { var query_where2 = from a in svcContext.AccountSet where a.Name.Contains("Contoso") where a.Address1_City == "Redmond" select a; foreach (var a in query_where2) { System.Console.WriteLine(a.Name + " " + a.Address1_City); } } Microsoft Dynamics 365

ASP.NET Core Configuration - Reloading, Binding, Injecting - Coding Blast Introduction In the last post, we talked about ASP.NET Core Configuration in general. We will see how is it set up by default from ASP.NET Core. We also talked about sources and that order matters. This time we will talk about mapping configuration to classes. We will also talk about various ways of injecting configuration settings to our application code. Another useful thing is automatic reload of configuration. You can find the code with examples here. Binding to models – strongly typed configuration options Let’s say we have following object in our appsettings.json file: And that we want to get those values and map them to an object. We would first create a class that matches that structure (or matches only those keys we want to bind): public class MessagesOptions { public string AlertMessage { get; set; } public string RegularMessage { get; set; } public bool ShouldShowAlert { get; set; } } Now I can bind that object from JSON (section) to an instance of MessageOptions class.

5 Reasons You Should Use the Brand-New C# 7.0 in Your WebDriver Tests - CodeProject I believe that you need to always play with the latest technologies to be great in what you are doing. As I promised in my last article Enhanced Selenium WebDriver Tests with the New Improved C# 6.0, now I am going to share with you how you can utilize the power of the brand-new C# 7.0. I am not going to cover all of the features because I don't like some of them or I don't see how we can use them in the tests. You can find even more cool tips and tricks about automated testing in my WebDriver Series. Quick Navigation Digit Separator Prior C# 7.0 There are lots of times where we use number literals in our code. Hide Copy Code [TestInitialize]public void SetupTest() { driver = new FirefoxDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(30000); } Another example when we use digits in our tests is when we pass expected values. C# 7.0 Version You can put digit separator _ wherever you want between digits, to improve readability. Local Functions Throw Expressions

Cheat Sheets for Developers Exemples de requête LINQ Cette documentation est archivée et n’est pas conservée. Date de publication : janvier 2017 S’applique à : Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online L’exemple suivant montre comment récupérer une liste de comptes où Name contient « Contoso ». using (ServiceContext svcContext = new ServiceContext(_serviceProxy)) { var query_where1 = from a in svcContext.AccountSet where a.Name.Contains("Contoso") select a; foreach (var a in query_where1) { System.Console.WriteLine(a.Name + " " + a.Address1_City); } } L’exemple suivant montre comment récupérer une liste de comptes où Name contient « Contoso » et Address1_City a la valeur « Redmond ». using (ServiceContext svcContext = new ServiceContext(_serviceProxy)) { var query_where2 = from a in svcContext.AccountSet where a.Name.Contains("Contoso") where a.Address1_City == "Redmond" select a; foreach (var a in query_where2) { System.Console.WriteLine(a.Name + " " + a.Address1_City); } } Microsoft Dynamics 365

Présentation de la plateforme .Net et du langage C# Depuis la création du tout premier Windows, Microsoft a mis à disposition une API (Application Programming Interface) afin de permettre aux développeurs de concevoir des logiciels exploitant les fonctionnalités fournies par le système d'exploitation. Cette API, ou plutôt ces API, car il y en a eu plusieurs, ont marqué différentes générations et ont énormément évolué au fil des années. De nouvelles API ont fait leur apparition, tandis que d'autres se sont enrichies. Parmi les API les plus marquantes de l'histoire de Windows, nous pouvons citer : Win16 : la première API disponible sous Windows. Apparue avec Windows 3.1 sous le nom de « Windows API », elle était notamment destinée à un usage avec le langage C. Ainsi, au fil des années, les API disponibles pour les développeurs se sont multipliées et enrichies, formant une jungle de plus en plus complexe. Le framework .Net est constitué de plusieurs composants, chacun ayant un rôle bien défini : I-A. I-B. I-C. I-D. I-E. I-F. II-A. II-B. II-C.

Tips and Tricks for Visual Studio | Microsoft Docs You can navigate in Visual Studio 2013 more easily by using the shortcuts in this topic. This topic is only a subset of the available keyboard shortcuts. For a more complete list, see Default Keyboard Shortcuts in Visual Studio. For information about how to optimize Visual Studio for accessibility, see Accessibility Tips and Tricks. Window Management Window Shortcuts Visual Studio Search Editor Find Code Editor Toolbars Debugging Application Lifecycle Management See Keyboard shortcuts: Visual Studio Online, TFS web portal, and Team Explorer See Also Visual Studio Blog Visual Studio Tips and Tricks Blog Visual Studio Toolbox on Channel 9 Visual Studio UserVoice Visual Studio Connect Bugs+

c# - When to use ref vs out Comparing the Properties of Two Objects via Reflection and C# As part of the refactoring I was doing to the load code for crawler projects, I needed a way of verifying that new code was loading data correctly. As it would be extremely time consuming to manually compare the objects, I used Reflection to compare the different objects and their properties. This article briefly describes the process and provides a complete helper function you can use in your own projects. This code is loosely based on a StackOverflow question, but I have heavily modified and expanded the original concept. Obtaining a List of Properties The ability to analyze assemblies and their component pieces is directly built into the .NET Framework, and something I really appreciate - I remember the nightmares of trying to work with COM type libraries in Visual Basic many years ago! The Type class represents a type declaration in your project, such as a class or enumeration. Hide Copy Code Type typeA; Type typeB; int value; value = 1; typeA = value.GetType(); typeB = typeof(int);

Making ASP.NET MVC code more testable using a Service Layer. – Dhaval. Online. Common wisdom says regarding the Repository and Unit of Work patterns in ASP.NET MVC to implement it on top of Entity Framework. This is supposed to make your code more testable and more decoupled, which is always desirable. Doing this, however, can be complicated. The general architecture of an application implementing these patterns (as seen on MSDN) is shown below: Implementing all of these classes can of course be daunting. Trying to write testable, modular code and following best practices might lead to an explosion of classes, especially if you’re trying to follow the Repository pattern and what not. There is a simpler way to do this. Now, the standard architecture that ASP.NET MVC generates with scaffolding looks like this: The Model is used by the Controller to render into the View. Each model would have a service. For example, if you have a Student model and an Instructor model such that one Instructor has many Students and each model has it’s own controller. Like this:

Getting Started with NUnit in ASP.NET MVC Posted by: Suprotim Agarwal , on 2/12/2014, in Category ASP.NET MVC Abstract: Set up NUnit in ASP.NET MVC and use the integration points in Visual Studio to integrate NUnit Test Cases Visual Studio 2012 comes with a perfectly capable Unit Testing system in MS Test. However if your team’s skills require you to use alternate Testing frameworks like NUnit, Visual Studio is game to play along. Setting up NUnit in Visual Studio 2012 There are two parts to NUnit setup for use in Visual Studio. 1. 2. PM> install-package NUnit Second part is to setup the NUnit Test Adapter so that Visual Studio recognizes the Test Cases in our project and allows us to Run them from the Test Explorer. Setting up the NUnit Test Adapter 1. 2. 3. With that we are ready to write Test Cases using NUnit. Let’s create a new MVC4 project. Once the MVC Project has been created we add a simple Class Library project to the Solution and append the word ‘Test’ at the end to indicate it’s a Test project. 1. 2. 3. 4. 5. 6. 7. 8.

Related: