Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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