/// <summary> /// Calls the indicated custom Front-Matter field and returns the resulting value/object to be used into documents/templates /// </summary> /// <param name="sourceName">The name of the FM source to call. Case insensitive.</param> /// <param name="srcParams">a list of params in test form</param> /// <returns></returns> public static object GetFieldValueFromFMSource(string sourceName, MIISFile file, params string[] srcParams) { sourceName = sourceName.ToLowerInvariant(); if (_FMSources.ContainsKey(sourceName)) { //Instantiate a new class of this type IFMSource fms = (IFMSource)Activator.CreateInstance(_FMSources[sourceName]); return(fms.GetValue(file, srcParams)); } else { throw new Exception($"The custom Front-Matter source '{sourceName}' does not exist!!"); } }
//Registers all custom Front-Matter sources inside the assembly passed as a parameter private static void RegisterCustomFMSourcesInAssembly(Assembly assembly) { //Custom FM sources are obtained from classes in the FMSources namespace that implement the IFMSource interface var fmSources = from c in assembly.GetTypes() where c.IsClass && c.Namespace == CUSTOM_FMSOURCES_NAMESPACE && typeof(IFMSource).IsAssignableFrom(c) select c; //Register each FMSource globally using its factory method (GetFilterType) fmSources.ToList().ForEach(fmSourceClass => { IFMSource fms = (IFMSource)Activator.CreateInstance(fmSourceClass); //Register possible fields that will define different caches for the file if (fms is IQueryStringDependent) { MarkdownFile.AddCachingQueryStringFields( (fms as IQueryStringDependent).GetCachingQueryStringFields() ); } FieldValuesHelper.AddFrontMatterSource(fms.SourceName, fms.GetType()); }); }