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: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:12e343076861a2956549
Created June 25, 2015 22:14
Grid Resolver Alias
[GridResolver("someOtherAlias")]
public GridModel Grid { get; set; }
public class TextPage : Page
{
public TextPage(IPublishedContent content) : base(content)
{
}
public string Title { get; set; }
public HtmlString Body { get; set; }
@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);
@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: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; }
namespace Ditto.Resolvers.Sample.Models.Archetypes
{
public class PriceList : ArchetypeFieldsetModel
{
public string Title { get; set; }
public int Quantity { get; set; }
public string Price { get; set; }
@micklaw
micklaw / gist:c159c4d05d09dd4d341c
Last active August 29, 2015 14:22
Archetype Value Resolver
namespace Our.Umbraco.Ditto.Resolvers.Archetype.Resolvers
{
public class ArchetypeValueResolver : DittoValueResolver<ArchetypeResolverAttribute>
{
public override object ResolveValue(ITypeDescriptorContext context, ArchetypeResolverAttribute attribute, CultureInfo culture)
{
var content = context.Instance as IPublishedContent;
var descriptor = context.PropertyDescriptor;
if (content != null && descriptor != null)
@micklaw
micklaw / gist:198864d9bc9087b3f755
Created May 8, 2015 15:43
Save new Examine Fields Event
void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
// [ML] - Grab any properties that have been injected via IndexingNodeDataEventArgs 'node' and input them
if (e.IndexType == IndexTypes.Content)
{
foreach (var node in e.Node.Elements())
{
if (!e.Fields.ContainsKey(node.Name.LocalName))
{
@micklaw
micklaw / gist:bb9d2395e4598c3a73b7
Created May 8, 2015 15:40
Custom Examine Indexer
public class CustomIndexer : UmbracoContentIndexer
{
public override void ReIndexNode(XElement node, string type)
{
this.EnqueueIndexOperation(new IndexOperation
{
Operation = IndexOperationType.Add,
Item = new IndexItem(node, type, (string)node.Attribute("id"))
});