Skip to content

Instantly share code, notes, and snippets.

View micklaw's full-sized avatar
🏴󠁧󠁢󠁳󠁣󠁴󠁿
In contract until Aug 25

Michael Law micklaw

🏴󠁧󠁢󠁳󠁣󠁴󠁿
In contract until Aug 25
View GitHub Profile
@micklaw
micklaw / gist:81a1d148eeae0b969cf6
Created June 4, 2015 21:38
Archetype in Ditto POCO
namespace Ditto.Resolvers.Sample.Models.DocTypes
{
public class Home : Page
{
public Home(IPublishedContent content) : base(content)
{
}
public string Title { get; set; }
@micklaw
micklaw / gist:d46143c4fc23f37158b4
Last active August 29, 2015 14:23
InvalidProgramException - 'Common Language Runtime detected an invalid program.' IIS Express only
/* Generating a proxy of a Type and overriding a virtual property with this method blows up in IIs Express, but works fine in unit tests (nunit, resharper) and
local IIS. This is using VS Community 2013 on Windows 8 */
public override T OverrideProperty<T>(string propertyName, Type attribute = null, Type [] constructorParams = null, object [] constructorValues = null)
{
// [ML] - Default to an empty instance
constructorParams = constructorParams ?? Type.EmptyTypes;
constructorValues = constructorValues ?? new object[] { null };
@micklaw
micklaw / gist:193cddcbf3e4d0e41941
Created June 23, 2015 14:09
Override property, Proxy class C#
/* Overriding makes sense when you look at the generated IL for overriden fields =) */
public override T OverrideProperty<T>(string propertyName, Type attribute = null, Type [] constructorParams = null, object [] constructorValues = null)
{
// [ML] - Default to an empty instance
constructorParams = constructorParams ?? Type.EmptyTypes;
constructorValues = constructorValues ?? new object[] { null };
var type = typeof(T);
public class TextPage : Page
{
public TextPage(IPublishedContent content) : base(content)
{
}
public string Title { get; set; }
public HtmlString Body { get; set; }
@micklaw
micklaw / gist:12e343076861a2956549
Created June 25, 2015 22:14
Grid Resolver Alias
[GridResolver("someOtherAlias")]
public GridModel Grid { get; set; }
@micklaw
micklaw / gist:6bc6c58da12ddc906d69
Created June 25, 2015 22:15
Control & Editor Grid
public class Control
{
public object value { get; set; }
public virtual object ConvertedValue { get; set; }
public Editor editor { get; set; }
}
public class Editor
@micklaw
micklaw / gist:688012240ab1c77a8b41
Created June 25, 2015 22:16
Register TyeConverters on startup
protected override void OnApplicationStarting(object sender, EventArgs e)
{
...
DittoResolverTypeLocator.Register<DittoHtmlStringConverter>("rte");
DittoResolverTypeLocator.Register<DittoHtmlStringConverter>("embed");
DittoResolverTypeLocator.Register<GridImageConverter>("media");
}
@micklaw
micklaw / gist:6eb58988c2b587bbdc7d
Last active September 14, 2022 19:15
Screengrab a website c#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace ScreenGrab.Core.Helpers
{
@micklaw
micklaw / gist:b543f42a98fc6f341de1
Created September 8, 2015 21:57
Registry DWORD for IE version in WebBrowser
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
Value Key: DWORD - YourApplication.exe
@micklaw
micklaw / gist:5e2c298c57e9e76fa1fc
Last active September 15, 2015 09:27
Controller for consuming WebsiteToImage
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using ScreenGrab.Core.Helpers;
namespace ScreenGrab.UI.Controllers
{
public class HomeController : Controller