Last active
December 20, 2015 20:35
-
-
Save kimgunnarsson/b9c86497cb41bd2b0515 to your computer and use it in GitHub Desktop.
Custom SelectionFactory with generic EditorDescriptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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