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
Transformation chain broken at transformation type CastToIntegerTransformation
started to debug the library and recognized that the CastToIntegerTransformation not inherits from ITransformationFromObject so i cannot use at the end of the parsing pipeline.
Yes, this problem can easily fixed with inheritance but i thought mention here.
Click to view my extended CastToIntegerTransformation class implementation
/// <summary>/// Class to cast selected XPath value to <see cref="int"/>./// </summary>publicclassCastToIntegerTransformation:ITransformationFromHtml,ITransformationFromObject{publicobjectTransform(Dictionary<string,object>settings,HtmlNodeNavigatornodeNavigator,List<HtmlAgilityPack.HtmlNode>logicalParents){vartext= nodeNavigator?.Value ??nodeNavigator?.CurrentNode?.InnerText;if(text!=null){intintVal;if(int.TryParse(text,out intVal)){returnintVal;}}returnnull;}/// <summary>/// Transforms the input to a valid <see cref="int"/>./// </summary>/// <param name="settings"><seealso cref="Config.TransformationConfig.ConfigAttributes"/>.</param>/// <param name="input">Parsed XPath value.</param>/// <returns><see cref="int"/>.</returns>/// <exception cref="FormatException">Occurs when the <paramref name="input" /> parameter/// is not a valid integer.</exception>publicobjectTransform(Dictionary<string,object>settings,objectinput){if(int.TryParse(input.ToString(),outint number)){returnnumber;}thrownew FormatException($"Input parameter {input} is not a valid integer!");}}
Thank You for this great library!
The text was updated successfully, but these errors were encountered:
My use case:
Given this URL: https://dev.test/index.php?PHPSESSID=a&action=profile;u=99 i wanted to extract the 99 user ID from the end of the string. My solution was to use a simple Regex and convert it to integer:
But after i got
started to debug the library and recognized that the
CastToIntegerTransformation
not inherits fromITransformationFromObject
so i cannot use at the end of the parsing pipeline.Yes, this problem can easily fixed with inheritance but i thought mention here.
Click to view my extended CastToIntegerTransformation class implementation
Thank You for this great library!
The text was updated successfully, but these errors were encountered: