mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 01:57:55 +08:00
Add helpers to SettingsDictionary
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.MetaData.Models {
|
namespace Orchard.ContentManagement.MetaData.Models {
|
||||||
@@ -6,11 +7,7 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
|||||||
public SettingsDictionary() { }
|
public SettingsDictionary() { }
|
||||||
public SettingsDictionary(IDictionary<string, string> dictionary) : base(dictionary) { }
|
public SettingsDictionary(IDictionary<string, string> dictionary) : base(dictionary) { }
|
||||||
|
|
||||||
public T GetModel<T>() where T : class, new() {
|
private T TryGetModel<T>(string key) where T : class {
|
||||||
return GetModel<T>(typeof(T).Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T GetModel<T>(string key) where T : class, new() {
|
|
||||||
var binder = new DefaultModelBinder();
|
var binder = new DefaultModelBinder();
|
||||||
var controllerContext = new ControllerContext();
|
var controllerContext = new ControllerContext();
|
||||||
var context = new ModelBindingContext {
|
var context = new ModelBindingContext {
|
||||||
@@ -18,7 +15,24 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
|||||||
ModelName = key,
|
ModelName = key,
|
||||||
ValueProvider = new DictionaryValueProvider<string>(this, null)
|
ValueProvider = new DictionaryValueProvider<string>(this, null)
|
||||||
};
|
};
|
||||||
return (T)binder.BindModel(controllerContext, context) ?? new T();
|
return (T)binder.BindModel(controllerContext, context);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetModel<T>() where T : class, new() {
|
||||||
|
return GetModel<T>(typeof(T).Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetModel<T>(string key) where T : class, new() {
|
||||||
|
return TryGetModel<T>(key) ?? new T();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsModel<T>() where T : class {
|
||||||
|
return TryGetModel<T>(typeof(T).Name) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsModel<T>(string key) where T : class {
|
||||||
|
return TryGetModel<T>(key) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user