background preloader

.NET / C#

Facebook Twitter

Distributed .NET Core (DShop) - Teaser. A complete containerized .NET Core Application microservice that is as small as possible. Why You Should Use View Components in ASP.NET Core. Learn why you should use View Components — and not Partial Views — in your ASP.NET Core projects with this hands-on example. Why use View Components and not Partial Views? The biggest reason is that when inserting a Partial View into a Razor page, all the ViewData associated with the calling View is automatically associated with the Partial View. This means that a Partial View may behave very differently on one Razor page than on another.

With View Components, you control what gets shared to your View Components. View Components are new to ASP.NET Core and are designed to do everything that a Partial View in previous versions of ASP.NET did and more. View Components are completely self-contained objects that consistently render html from a Razor view. They are generated from a C# class derived from the base class ViewComponent and are typically associated with a Razor file to generate markup. ASP.NET MVC 5 Security And Creating User Role in C#, SQL, HTML, XML for Visual Studio 2015. Maartenba/MvcSiteMapProvider: An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework. TCP / IP Server Client Example Part 1 in C#, VB.NET for Visual Studio 2012. Friends Don’t Let Friends Swallow NullReferenceException.

If you are using ASP.NET MVC, Core or non-Core, chances are you are swallowing NullReferenceException without you even noticing. You can see the screenshot of this repro in my previous post (see: Sixth, fixed null model) But, let’s reproduce this using simple ASP.NET MVC Core program.First, just create a normal MVC application. Then, add the following action: public IActionResult Sample(){ return View();} Also, add this new ModelView class. public class PantsViewModel{ public string FancyPants { get; set; }} Yeah, fancy pants ala Scott Hanselman. Oh, back to the topic… Add a new View using Visual Studio dialog, use “Create” as Template, and then choose our newly created SampleViewModel as the Model class, like this: The result should be like this: Nothing special here. There is no exception. And also this one: Now, try to access the page again.

NullReferenceException occurred, but it’s swallowed by the framework silently. Restart the debugger by pressing Ctrl+Shift+F5.Here we go. Quick Benchmark. ASP.NET Core · TypeScript. Install ASP.NET Core and TypeScript First, install ASP.NET Core if you need it. This quick-start guide requires Visual Studio 2015 or 2017. Next, if your version of Visual Studio does not already have the latest TypeScript, you can install it. Create a new project Choose File Choose New Project (Ctrl + Shift + N) Choose Visual C# For VS2015, choose ASP.NET Web Application > ASP.NET 5 Empty, and let’s uncheck “Host in the cloud” since we’re going to run this locally.

For VS2017, choose ASP.NET Core Web Application (.NET Core) > ASP.NET Core 1.1 Empty instead. Run the application and make sure that it works. Set up the server In project.json add another entry in "dependencies": "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final" The resulting dependencies should look like this: Replace the body of Configure in Startup.cs with public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseDefaultFiles(); app.UseStaticFiles(); } The next step is to add a folder for TypeScript.

<! Born to Learn. Entity Framework in Depth: The Complete Guide. 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. In this article, we’ll see the how we can setup NUnit to work with Visual Studio’s Test Explorer and run Unit tests in our project. 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. Adding your first Test case 1. 2. 3. 4. 5. 6. 7. 8. 9. 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: Writing smarter cross-platform .NET Core apps with the API Analyzer and Windows Compatibility Pack. 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); 101 LINQ Samples in 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+

DevExpress

.NET Core. C# Essentials. 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. NETFX4 Poster. C# Development - Dzone Refcardz. Core .NET - Dzone Refcardz. Cheat Sheets for Developers.

XML

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. 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. We will see how we can have our configuration reloaded while our application is running. 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; } } 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.

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. Let’s try to replace our method with generic and compare performance.

Before testing, you need to take into account another drawback of the object argument. Value types can never be null (Nullable type is not counted). Calling a method like ThrowIfNull(5) is meaningless, but since the type of the argument is object, the compiler will call the method. 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.

Electron | Build cross platform desktop apps with JavaScript, HTML, and CSS. 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.

C# - When to use ref vs out. C# 7.0 and Beyond with Mads Torgersen – Jakub Chodounsky – Medium. New Zealand and Wellington especially are not exactly big so when the program manager of C# language comes into town for a meetup it would be a shame to stay at home. This Wednesday the amazing WelliDotNet meetup hosted Mads Torgersen; a guy responsible for the C# language design (and TypeScript and Visual Basic in the past); and he talked about the new features of C# 7.0 and where the next versions are heading.

Mads started with the results of Stack Overflow Developer Survey 2017 results where C# is 4th most used programming language. And it also made it to the top 10 most loved programming languages. He thinks the reasons behind that are C# now runs on every platform (not just Windows),Roslyn is an open compiler,you can use your favourite editor, not just Visual Studio andeverything is open source. Q: How hard was it to get more open? C# evolution is a balancing act as you want to New features in C# 7.0 Mads started with minor features and talked briefly about new binary literals. Tuples int?

.NET Framework Development Guide. This section explains how to create, configure, debug, secure, and deploy your .NET Framework apps. The section also provides information about technology areas such as dynamic programming, interoperability, extensibility, memory management, and threading. .NET Framework Class Library Supplies syntax, code examples, and usage information for each class that is contained in the .NET Framework namespaces. Multi-Targeting .NET Standard Class Libraries | Gigi Labs. .NET Architecture. Top 10 Unity best practices: Naming Conventions : gamedev. Share code between WPF and Universal Apps with PRISM.

How to implement a bindable progress indicator (loading dots) for MVVM Windows (8.1) Universal apps : csharp. Building a Mobile Cross-Platform App from a Shared C# Code Base with UI for Xamarin. Async/Await - Under the sheets. What Great .NET Developers Ought To Know (More .NET Interview Questions) Dot.Blog | De la bonne utilisation de Async/Await en C# Cours. Dot.Blog | MVVM : Gérer les données de Design de façon propre.