The goal of this series is to show you an example how you could design a system. It’s kind of a reference architecture that I like to use (I have used it – a number of times in middle-sized projects, and I’m still quite happy about it), but it’s up to you to decide if you find some ideas to be usable in your specific environment.
Category: C#
.NET C# to SQL Server Data Types Mapping table
SQL Server and the .NET Framework are based on different type systems. For example, the .NET Framework Decimal structure has a maximum scale of 28, whereas the SQL Server decimal and numeric data types have a maximum scale of 38.
Source: SQL Server Data Type Mappings
LINQ to CSV library – CodeProject
Fluent Assertions
Fluentassertions : Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.
Source: Fluentassertions
Non CLS-Compliant Code in C# – CodeProject
c# – Log4Net: Programmatically specify multiple loggers with multiple file appenders – Stack Overflow
NET C# Common I/O Tasks
The System.IO namespace provides several classes that allow for various actions, such as reading and writing, to be performed on files, directories, and streams
via Common I/O Tasks.
c# – Check if ‘T’ inherits or implements a class/interface – Stack Overflow
typeof(IEmployee).IsAssignableFrom(typeof(T))
via c# – Check if ‘T’ inherits or implements a class/interface – Stack Overflow.
ide – Visual Studio 2013 Update 2 – C# navigation bar drop down menus not working – Stack Overflow
The dropdown menus in the code editor stopped working in Visual Studio 2013 for me.
The problem is a bug when using multiple monitors and a “leftmost” monitor that is not the “main” display…
The solution is quite simple for now: make your leftmost monitor the main monitor.
A bugfix is coming, included in next Visual Studio update.
More info:
ide – Visual Studio 2013 Update 2 – C# navigation bar drop down menus not working – Stack Overflow.
Simple validation of properties in EPiServer 6 using DataAnnotations with PageTypeBuilder
In EPiServer 7 you can easily add validation to pagetype properties with DataAnnotations attribute, like this:
[RegularExpression(@"^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,9})$" , ErrorMessage = "Must be valid email address")]
In EPiServer 6 you can create a custom property (involves creating some classes and messing up the db sometimes), or hook up onto global page save validation event and check if property x is valid and return e.message. (http://blog.bigfinger.se/2010/4/26/simple-validation-of-propertyvalues-in-episerver-cms-6.aspx)
Or, you can combine the usage of hooking up onto global pagedata validation with DataAnnotaions support, then you in fact
have something similar to the EPiServer 7 way with DataAnnotations support. Just go here: Validating page data with Data Annotations.
Thank you Stefan Forsberg.
PS:
the GlobalPageValidation_Validators event can be hooked onto through Global.asax.cs like this:
public class Global : EPiServer.Global { protected void Application_Start(Object sender, EventArgs e) { //Enables validation for pagetype properties with DataAnnotations GlobalPageValidation.Validators += GlobalPageValidation_Validators; } void GlobalPageValidation_Validators(object sender, PageValidateEventArgs e) { PageDataValidator validator = new PageDataValidator(); var errors = validator.GetErrors(e.Page).ToList(); if (errors.Any()) { e.IsValid = false; foreach (var error in errors) { e.ErrorMessage += string.Format("{0} <br />", error); } } }
Also added an <br /> in case of several errors.
Validation Error message looks like this in EPiServer edit mode:
Its a bit on the simple side; remember to include which field its connected to in the errortext, no indication is shown next to the particular field.
Now you can just use DataAnnotations validation attributes, like these:
[RegularExpression]
[Required]
[StringLength]
[Range]
Inherit System.ComponentModel.DataAnnotations and override IsValid to do something more complicated with your validations.