Skip to content

Instantly share code, notes, and snippets.

@kimgunnarsson
Last active December 20, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimgunnarsson/b9c86497cb41bd2b0515 to your computer and use it in GitHub Desktop.
Save kimgunnarsson/b9c86497cb41bd2b0515 to your computer and use it in GitHub Desktop.
Custom SelectionFactory with generic EditorDescriptor
using System;
using System.Collections.Generic;
using System.Linq;
using EPiServer.Shell.ObjectEditing;
namespace Alloy.Business.Properties.CustomSelectionFactory
{
class CustomSelectionFactory<T> : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
var settings = Activator.CreateInstance<T>() as Dictionary<string, string>;
if (settings == null)
{
yield break;
}
foreach (var setting in settings.ToList())
{
yield return new SelectItem()
{
Value = setting.Key.ToLower(),
Text = setting.Value
};
}
}
}
}
using System;
using System.Collections.Generic;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
namespace Alloy.Business.Properties.CustomSelectionFactory
{
public class CustomSelectionFactoryEditorDescriptor<TSelectionFactory> : EditorDescriptor
{
public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
{
SelectionFactoryType = typeof(CustomSelectionFactory<TSelectionFactory>);
ClientEditingClass = "epi-cms/contentediting/editors/SelectionEditor";
base.ModifyMetadata(metadata, attributes);
}
}
}
namespace Alloy.Settings
{
public class SelectionSettings : Dictionary<string, string>
{
public SelectionSettings()
{
Add("key", "value");
Add("key1", "value");
Add("key2", "value");
Add("key3", "value");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment