public void IgnoresCase() { // Given IShortcodeCollection shortcodes = new ShortcodeCollection(); shortcodes.Add <TestShortcode>("Foo"); // When IShortcode shortcode = shortcodes.CreateInstance("foo"); // Then shortcode.ShouldBeAssignableTo <TestShortcode>(); }
private void BindModel(IShortcode shortcode) { if (shortcode.Attributes != null) { var properties = shortcode.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var attribute in shortcode.Attributes) { var propertyInfo = properties.FirstOrDefault(p => p.Name.Equals(attribute.Key, StringComparison.InvariantCultureIgnoreCase)); if (propertyInfo != null) { var type = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; var safeValue = attribute.Value == null ? null : Convert.ChangeType(attribute.Value, type); propertyInfo.SetValue(shortcode, safeValue, null); } } } }
/// <summary> /// Add a dynamic module programmatically during runtime. /// </summary> /// <param name="shortTag"></param> /// <param name="module"></param> /// <returns>True on success, false on error (tyopically if already added or key exists in dictionary</returns> public bool AddDynamicModule(string shortTag, IShortcode module) { // Pre-populate the list if necessary var moduleList = GetDynamicModuleList(); // Replace the shortcode if it already exists if (moduleList.ContainsKey(shortTag)) { _dynamicModuleList[shortTag] = module; return true; } // Add the module if (module != null) { _dynamicModuleList.Add(shortTag, module); return true; } return false; }
public static void RegisterModule(string shortcode, IShortcode module) { DynamicModules.Instance.AddDynamicModule(shortcode, module); }