Mastering C# and .NET Framework
Table of Contents
Mastering C# and .NET Framework
Credits
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Inside the CLR
An annotated reminder of some important computing terms
Context
The OS multitask execution model
Context types
Thread safety
State
Program state
Serialization
Process
Thread
SysInternals
Static versus dynamic memory
Garbage collector
Concurrent computing
Parallel computing
Imperative programming
Declarative programming
The evolution of .NET
.NET as a reaction to the Java World
The open source movement and .NET Core
Common Language Runtime
Common Intermediate Language
Managed execution
Components and languages
Structure of an assembly file
Program execution
Metadata
Introducing metadata with a basic Hello World
PreJIT, JIT, EconoJIT, and RyuJIT
Common Type System
Naming conventions, rules, and type access modes
Members of a type
A quick tip on the execution and memory analysis of an assembly in Visual Studio 2015
The stack and the heap
Garbage collection
Implementing algorithms with the CLR
Data structures, algorithms, and complexity
Big O Notation
An approach to performance in the most common sorting algorithms
Relevant features appearing in versions 4.5x, 4.6, and .NET Core 1.0 and 1.1
.NET 4.5.x
.NET 4.6 (aligned with Visual Studio 2015)
.NET Core 1.0
.NET Core 1.1
Summary
2. Core Concepts of C# and .NET
C# – what's different in the language?
Languages: strongly typed, weakly typed, dynamic, and static
The main differences
The true reason for delegates
The evolution in versions 2.0 and 3.0
Generics
Creating custom generic types and methods
Lambda expressions and anonymous types
Lambda expressions
It's all about signatures
The LINQ syntax
LINQ syntax is based on the SQL language
Deferred execution
Joining and grouping collections
Type projections
Extension methods
Summary
3. Advanced Concepts of C# and .NET
C# 4 and .NET framework 4.0
Covariance and contravariance
Covariance in interfaces
Covariance in generic types
Covariance in LINQ
Contravariance
Tuples: a remembrance
Tuples: implementation in C#
Tuples: support for structural equality
Tuples versus anonymous types
Lazy initialization and instantiation
Dynamic programming
Dynamic typing
The ExpandoObject object
Optional and named parameters
The Task object and asynchronous calls
C# 5.0: async/await declarations
What's new in C# 6.0
String interpolation
Exception filters
The nameof operator
The null-conditional operator
Auto-property initializers
Static using declarations
Expression bodied methods
Index initializers
What's new in C# 7.0
Binary literals and digit separators
Pattern matching and switch statements
Tuples
Decomposition
Local functions
Ref return values
Summary
4. Comparing Approaches for Programming
Functional languages
F# 4 and .NET Framework
The inevitable Hello World demo
Identifiers and scope
Lists
Function declarations
The pipeline operator
Pattern matching
Classes and types
Casting
The TypeScript language
The new JavaScript
TypeScript: a superset of JavaScript
So, what exactly is TypeScript?
Main features and coalitions
Installing the tools
Transpiling to different versions
Advantages in the IDE
A note on TypeScript's object-oriented syntax
More details and functionality
Summary
5. Reflection and Dynamic Programming
Reflection in the .NET Framework
Calling external assemblies
Generic Reflection
Emitting code at runtime
The System.CodeDOM namespace
The Reflection.Emit namespace
Interoperability
Primary Interop Assemblies
Formatting cells
Inserting multimedia in a sheet
Interop with Microsoft Word
Office apps
The Office app default project
Architectural differences
Summary
6. SQL Database Programming
The relational model
Properties of relational tables
The tools – SQL Server 2014
The SQL language
SQL Server from Visual Studio
Data access in Visual Studio
.NET data access
Using ADO.NET basic objects
Configuring the user interface
The Entity Framework data model
Summary
7. NoSQL Database Programming
A brief historical context
The NoSQL world
Architectural changes with respect to RDBMS
Querying multiple queries
The problem of nonnormalized data
Data nesting
About CRUD operations
MongoDB on Windows
File structure and default configuration
Some useful commands
Operators
Altering data – the rest of CRUD operations
Text indexes
MongoDB from Visual Studio
First demo: a simple query from Visual Studio
CRUD operations
Deletion
Insertion
Modifications and replacements
Summary
8. Open Source Programming
Historical open source movements
Other projects and initiatives
Open source code for the programmer
Other languages
The Roslyn project
Differences from traditional compilers
Getting started with Roslyn
A first look at Microsoft Code Analysis Services
Code Analyzers
An entire open source sample for you to check: ScriptCS
A basic project using Microsoft.CodeAnalysis
The first approach to code refactoring
Debugging and testing the demo
TypeScript
Debugging TypeScript
Debugging TypeScript with Chrome
Interfaces and strong typing
Implementing namespaces
Declarations, scope, and Intellisense
Scope and encapsulation
Classes and class inheritance
Functions
Arrays and interfaces
More TypeScript in action
The DOM connection
Summary
9. Architecture
The election of an architecture
The Microsoft platform
A universal platform
The MSF application model
The Team Model
The Governance Model
The Risk Model
Risk evaluation
Risk assessment
Risk action plans
CASE tools
The role of Visio
A first example
The database design
Creating the demo application in Visual Studio
Website design
Reports
Many other options
BPMN 2.0 (Business Process Model and Notation)
UML standard support
Visual Studio architecture, testing, and analysis tools
Application's architecture using Visual Studio
Class diagrams
Testing
Testing our application in Visual Studio
The Analyze menu
The end of the life cycle – publishing the solution
Summary
10. Design Patterns
The origins
The SOLID principles
Single Responsibility principle
An example
Open/Closed principle
Back to our sample
Liskov Substitution principle
Back to the code again
Other implementations of LSP in .NET (Generics)
Interface Segregation principle
Dependency Inversion principle
A final version of the sample
Design patterns
Singleton
The Factory pattern
The Adapter pattern
The Façade pattern
The Decora...