You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some situations (like #383) could be resolved by allowing a developer to create a child class of a ConverterBase (or any existing converter) and implementing their own logic or doing some post/pre processing on the value. However, the current Converter does not support creating instances of anything that is outside of the ReverseMarkdown.Converters assembly. It also doesn't support changing the loading behavior, nor modifying the loaded converters.
I propose the following:
Add/Update a constructor in the Converter class to include a parameter where additional assemblies can be searched for ConverterBase classes.
ex: params Assembly[] additionalAssemblies
Could also be passed into the Config object, but may want to consider separation between loading and behavior settings.
Update the constructor to stores types before activating them.
If a new type is a child class of an existing type, the new type replaces the existing type.
If a new type is a parent of an existing type, it is ignored.
Make fields from private to protected.
Change Config { get; } to Config { get; init; } (or protected set if init is not supported)
Additionally, some other changes can be made to make inheritance better:
I'm using the most recent C# syntax here, but it shouldn't be hard to convert to the syntax the package requires
publicConverter(Config config, params Assembly[] additionalAssemblies){Config=config;
Assembly[]assemblies=[typeof(IConverter).GetTypeInfo().Assembly, .. additionalAssemblies];List<Type>types=[];// instantiate all converters excluding the unknown tags convertersforeach(var assembly in assemblies){foreach(var ctype in assembly.GetTypes().Where(t => t.GetTypeInfo().GetInterfaces().Contains(typeof(IConverter))&&!t.GetTypeInfo().IsAbstract&&t!=typeof(PassThrough)&&t!=typeof(Drop)&&t!=typeof(ByPass))){// Check to see if any existing types are children/equal to// the type to add.if(types.Any(e => e.IsAssignableTo(ctype)))// If they are, ignore the type.continue;// See if there is a type that is a parent of the// current type.Type?toRemove= types.FirstOrDefault(ctype.IsAssignableTo);// if there is ...if(toRemove is not null)// ... remove the parent.
types.Remove(toRemove);// finally, add the type.
types.Add(ctype);}}// For each type to register ...foreach(var ctype in types)// ... activate them
Activator.CreateInstance(ctype,this);// register the unknown tags converters_passThroughTagsConverter=new PassThrough(this);_dropTagsConverter=new Drop(this);_byPassTagsConverter=new ByPass(this);}
If you are willing to support this in the project - let me know. It shouldn't be hard for me to throw together the changes in a PR and test them. Might need some help creating a valid test for this, though (check the _converters prop after init maybe?).
Created a draft PR: #385 - I expanded on the mockup and made sure the changes worked with all the tests. Waiting on if I will need to make changes due to design decision (using Config or not, etc.).
The text was updated successfully, but these errors were encountered:
Some situations (like #383) could be resolved by allowing a developer to create a child class of a
ConverterBase
(or any existing converter) and implementing their own logic or doing some post/pre processing on the value. However, the currentConverter
does not support creating instances of anything that is outside of theReverseMarkdown.Converters
assembly. It also doesn't support changing the loading behavior, nor modifying the loaded converters.I propose the following:
Converter
class to include a parameter where additional assemblies can be searched forConverterBase
classes.params Assembly[] additionalAssemblies
Config
object, but may want to consider separation between loading and behavior settings.private
toprotected
.Config { get; }
toConfig { get; init; }
(orprotected set
ifinit
is not supported)Additionally, some other changes can be made to make inheritance better:
Converter
asvirtual
.Convert(string html)
,Register(string tagName, IConverter converter)
and/orLookup(string tagName)
Mockup Constructor
I'm using the most recent C# syntax here, but it shouldn't be hard to convert to the syntax the package requires
If you are willing to support this in the project - let me know. It shouldn't be hard for me to throw together the changes in a PR and test them. Might need some help creating a valid test for this, though (check the_converters
prop afterinit
maybe?).Created a draft PR: #385 - I expanded on the mockup and made sure the changes worked with all the tests. Waiting on if I will need to make changes due to design decision (using Config or not, etc.).
The text was updated successfully, but these errors were encountered: