I have a piece of code like this. I write this because I love extension methods and lambda expression:
public static class TuneingRules
{
public static Func<HtmlNode, bool> IsNodeHavingClearNone = (node) =>
{
if (node.HasAttributes)
{
// HtmlAttribute atr = item.Attributes.Where(at => at.Name == "id" && at.Value == "hello").FirstOrDefault();
HtmlAttribute atr = node.Attributes.Where(at => at.Name == "style").FirstOrDefault();
if (atr != null)
{
return Regex.Match(atr.Value, "clear\\s*:\\s*none;").Success;
}
}
return true;
};
}
and extension method like this.
public static class ExtensionMethods
{
#region Ignoring Rules
public static bool Ignore(this HtmlNode Node, Func<HtmlNode,bool> func) {
return func(Node);
}
#endregion
}
now I have two approaches to use this piece of code..
1 case
if (!htmlNode.Ignore(TuneingRules.IsNodeHavingClearNone)){
//then do somethings
}
// here i am open to write lambda expression like this.
if (!htmlNode.Ignore( node => node.innerText =="" ){
//then do somethings
}
2 case
if (!TuneingRules.IsNodeHavingClearNone(htmlNode)) {
//then do something
}
I'm afraid that there are any performance issues if TuneingRules
has many static Func<HtmlNode,bool>
objects. Do i need to refactor my code?
In the first case there is an extra call going through ignore function...
but in the second case i can call the function object directly.
Or is there another way to write this code in order to stick with lambda as well as extension methods?