Created
April 30, 2013 15:28
-
-
Save TimGeyssens/5489463 to your computer and use it in GitHub Desktop.
Custom value injection classes (for use with http://valueinjecter.codeplex.com/) to map from a umbraco's IPublishedContent to a view model and from a view model to IContent (first rough version)
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
public class InjectionToIContent : ValueInjection | |
{ | |
protected override void Inject(object source, object target) | |
{ | |
var content = target as IContent; | |
var type = source.GetType(); | |
if (type.GetProperty("Name") != null) | |
content.Name = type.GetProperty("Name").GetValue(source).ToString(); | |
foreach (var prop in content.Properties.Where | |
(prop => type.GetProperty(prop.Alias, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null)) | |
{ | |
content.SetValue(prop.Alias, type.GetProperty(prop.Alias, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance).GetValue(source)); | |
} | |
} | |
} |
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
public class InjectionToIContent : ValueInjection | |
{ | |
protected override void Inject(object source, object target) | |
{ | |
var content = target as IContent; | |
var type = source.GetType(); | |
if (type.GetProperty("Name") != null) | |
content.Name = type.GetProperty("Name").GetValue(source).ToString(); | |
foreach (var prop in content.Properties.Where | |
(prop => type.GetProperty(prop.Alias, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null)) | |
{ | |
content.SetValue(prop.Alias, type.GetProperty(prop.Alias, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance).GetValue(source)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment