background preloader

Grundlagen

Facebook Twitter

Func and Action Delegates (Page 1 of 2) Generic Delegates The .NET framework version 3.5 introduced two new sets of generic, parameterised delegates named Func and Action.

Func and Action Delegates (Page 1 of 2)

The Func delegate can be used to encapsulate a method that accepts between zero and four arguments and returns a value. The Action delegate also represents methods with zero to four parameters but differs from Func in that the method must return void. The new delegates can be used to reduce the number of delegates that you define explicitly. In situations where you would need a delegate that matches one of the predefined Func or Action signatures, you may decide to use the built-in version.

One of the key reasons for the introduction of Func and Action is their relationship with lambda expressions. Func Delegate There are five variations upon the Func delegate, each allowing a different number of parameters to be represented. Using Func<TResult> The most basic variant of Func is Func<TResult>. We can create the same functionality using a lambda expression.

Reflection

Knigge für Softwarearchitekten. Verhaltensspektrum zwischen Sonne und Finsternis In unserem Berufsleben durften wir Projekte unterschiedlicher Branchen und bei vielen verschiedenen Kunden begleiten und beobachten, von Embedded Systems, Informationssystemen, der Anlagen- und Produktionssteuerung, Web- und Data-Warehouse-Projekten, über Mainframe-, Client-/Server- und Standalone-Anwendungen.

Knigge für Softwarearchitekten

Dabei haben wir Licht und Schatten erlebt, sowohl hervorragend produktive als auch grausig schlechte Projekte. In dieser Kolumne möchten wir uns auf unsere Beobachtungen von SoftwarearchitektInnen beschränken und deren Verhalten in Form von “Mustern” darstellen. Organisationsmuster für andere Bereiche der IT finden Sie bei Coplien und Harrison: “Organizational Patterns of Agile Software Development” (Prentice-Hall 2004) und DeMarco/Hruschka; The Atlantic Systems Guild: “Adrenalin-Junkies und Formular-Zombies”. (Hanser 2009). Gute Architekten bauen gute Systeme Gutes Verhalten macht gute Architekten Was Sie erwartet Auf andere zugehen. Asynchrone Programmierung in .NET 4.5 mit async und await. In der Vergangenheit war asynchrones, nicht blockierendes Programmieren unter .NET-Entwicklern nicht beliebt, denn Microsoft hatte dafür Verfahren in das .NET Framework eingebaut, die allesamt den Programmcode wesentlich verkomplizierten.

Asynchrone Programmierung in .NET 4.5 mit async und await

Mit den Schlüsselwörtern async und await in C# 5.0 sowie Visual Basic 11.0 unterscheidet sich nun asynchroner Programmcode nicht mehr wesentlich von der stringenten synchronen Vorgehensweise. Heute wird von Software erwartet, dass sie jederzeit auf Benutzereingaben reagiert, also auch dann, wenn sie gerade mit anderen Aufgaben beschäftigt ist. Diese Forderung ist nicht neu, aber gerade in Zeiten von Wischgesten und stagnierender Prozessorgeschwindigkeiten wichtiger denn je. Microsoft hatte in .NET 1.0 Möglichkeiten implementiert, Multithreading (mit den Klassen im Namensraum System.Threading) und asynchrone Aufrufe (mit BeginInvoke() und EndInvoke() in der Delegate Klasse) zu nutzen. Nach langer Zeit angekommen public int DoWorkAsync(int p)

Serializing Exceptions to XML «  foreach(bill) paywith(skill); Exceptions are fundamental to languages like Java and C#.

Serializing Exceptions to XML «  foreach(bill) paywith(skill);

They’re suppose to make error-handling easier than dealing with return codes, which is more common in earlier languages like C or C++. But many times, Exceptions will arise that were unanticipated, and will need to be reviewed by a developer to possibly make changes to the responsible code. It is therefore common practice to instrument some logging mechanism to record Exceptions where necessary.

Since XML has become so ubiquitous, XML is an obvious choice to represent the data structure of an Exception in. Any other format like JSON may work just fine, but more people are familiar with XML. But what’s the easiest way to serialize an Exception into XML? And you’ll see: An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Xml.dll Additional information: There was an error reflecting type ‘System.Exception’.

(Why isn’t IDictionary serializable? And serialize it using XmlSerializer. Next, the StackTrace: .net - How to serialize an Exception object in C#