Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / App.config
Created September 22, 2020 15:24
Bare-bones WCF server
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
@smailliwcs
smailliwcs / App.config
Created September 22, 2020 15:24
Bare-bones WCF client
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<client>
<endpoint name="IMathService" address="net.pipe://localhost/MathService" binding="netNamedPipeBinding" contract="MathService.Server.IMathService" />
</client>
</system.serviceModel>
@smailliwcs
smailliwcs / EnumExtensions.cs
Created September 22, 2020 15:24
User-friendly names for enumerations
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
public static class EnumExtensions
{
public static string ToDescription(Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());
@smailliwcs
smailliwcs / EnumerableExtensions.cs
Created September 22, 2020 15:24
Helpful LINQ extensions
using System.Collections.Generic;
using System.Linq;
public static class EnumerableExtensions
{
public static IEnumerable<T> Yield<T>(T item)
{
yield return item;
}
@smailliwcs
smailliwcs / Program.cs
Created September 22, 2020 15:24
Scripting Microsoft Access
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.IO;
namespace AccessScripter
{
internal static class Program
{
private static IDictionary<string, string> providers = new Dictionary<string, string>
@smailliwcs
smailliwcs / dialog.html
Created September 22, 2020 15:24
TinyMCE 3 plugin: numalign
<!DOCTYPE html>
<html>
<head>
<title>Align Numbers</title>
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script type="text/javascript" src="dialog.js"></script>
</head>
<body>
<form>
<label>
@smailliwcs
smailliwcs / TrimmingModelBinder.cs
Created September 22, 2020 15:24
Trimmed string binding
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
public class TrimmingModelBinder : DefaultModelBinder
{
protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)
{
if (propertyDescriptor.PropertyType == typeof(string))
@smailliwcs
smailliwcs / Global.asax.cs
Created September 22, 2020 15:25
Custom property binding
using System;
using System.Web;
using System.Web.Mvc;
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
ModelBinders.Binders.DefaultBinder = new ModelBinderBase();
}
@smailliwcs
smailliwcs / LaterThanAttribute.cs
Created September 22, 2020 15:25
Relative date validation
using System;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class LaterThanAttribute : ValidationAttribute
{
public override bool RequiresValidationContext
{
get { return true; }
@smailliwcs
smailliwcs / HtmlTextWriter.cs
Created September 22, 2020 15:25
Handling CSS classes with HtmlTextWriter
using System.Collections.Generic;
using System.IO;
using System.Web.UI;
public class HtmlTextWriter : System.Web.UI.HtmlTextWriter
{
private ICollection<string> cssClasses;
public HtmlTextWriter(TextWriter writer)
: base(writer)