exclude specific sub-type while using isSubTypeOf - byte-buddy

I am trying to exclude specific subType of an interface using below expression. The CompositeAction extends Action interface. And there are other interfaces that extend Action interface. I want to include all sub types of Action interface except the classes that implement CompositeAction interface. I tried with below expression but its not excluded.
isSubTypeOf(Action.class)
.and(not(isSubTypeOf(named(CompositeAction.class.getName()))));
Also tried hasSuperType in place of isSubTypeOf, but that didn't work as well. Is it doable? Appreciate any help.

It should be as easy as:
isSubTypeOf(Action.class).and(not(isSubTypeOf(CompositeAction.class)))
In return, you get an ElementMatcher that you can supply a type to rather easily such that you can unit test this properly.

Related

What is the use of getWrappedElement() method which is declared in WrapsElement interface and why does only Select class implement it?

I am able to understand all the methods implemented in Select class except getWrappedElement() method. Can anyone please help me out on this?
This is used if you have your WebElement encapsulated in some other entity. There are two examples:
org.openqa.selenium.support.ui.Select that actually mimics the behavior of select control. It implements WrapsElement in order to provide the actual element it "decorates" (however it is not a decorator hence I put quotes here).
org.openqa.selenium.support.events.EventFiringWebDriver.EventFiringWebElement which works in pair with EventFiringWebDriver. It actually wraps the base element and allow to run actions before and after your element methods call. Hence you might want to obtain that base WebElement in some reason which is supported by implementation of WrapsElement
In the latter case there is also a code that "consumes" entities implementing WrapsElement. Such objects are expected for example in executeScript in order to unwrap objects you're passing as parameters for your script.
WrappedElement is also used in a number of internal Selenium classes where it tests if an element is the instance of WrappedElement and unwraps it before proceed to next steps.

What is a user case for creating an extension function as a method inside a class/interface?

I saw some examples of extension functions being defined inside a class/interface but I didn't understand the reason it would be done. Could someone show when it would be the proper way to implement some use case?
One particular example that I didn't understand very well:
interface Monoid<A> {
fun z(): A
fun A.add(other:A):A
}
When you only ever want to use this function inside your class/interface and its subtypes (or nearly so; you already know how to get out with with as per your previous question, but that shouldn't be a common case).
The specific example just seems like a bad idea once you need to work with more than one Monoid at once.

Is it possible to extend private Dart classes?

I am trying to expand upon the functionality of the Dismissible widget, which is a StatefulWidget, with its state being a private class.
Since I need to change the functionality inside of _DismissibleState, is it possible to somehow extend from it?
If not, is there an alternative or recommended way how to extend upon Flutter standard classes, apart from copying the whole source?
You can only extend a class that you can refer to. If _DismissibleState is declared in a different library, then you cannot refer to it, and so you can't extend it.
There is no workaround. That's what it means to be private.
You also cannot extend Dismissible to return a different state because its interface contains _DismissibleState createState(). There is no way you can return a state which satisfies that interface restriction, and you also cannot override it with a different return type unless that type also implements _DismissibleState, which was the original unsolvable problem.
I had to copy and paste the entire original file into a new one to make a simple change just in one line in a private class.

vb pass name of function using intellisense

I'm tying to implement a novel way of overriding functions based on which DLLs I have loaded. In this model, I have a list of class instances from First = Highest Priority to Last = Lowest priority.
Any of those classes may implement a Hook function or callback. I'm currently at the stage where I can pass a string to a function, and then call it - my library convention looks like this:
Dim hookclasses as HooksList
Dim callable as Object
hookclasses.Add(new ClassA)
hookclasses.Add(new ClassB)
'... etc.
if hookclasses.Has("MyHookFunction", callable) then
callable.MyHookFunction()
end if
This all works, but I'd like to reduce typos by leveraging Intellisense. I've already thought of popping the strings into a class containing constant strings, so I'm after something better than that.
Ideally I'd like to have a fallback class that implements all of the hook functions (even if it simply returns), and if the language supported it, I'd like to do the following:
if hookclasses.Has(NameOf(FallbackClass.MyHookFunction), callable) then ...
Clearly there is no 'NameOf' operator, and I don't know how to write a NameOf function.
Is this possible?
Thanks.
Check this article nameOf (C# and Visual Basic reference)
https://msdn.microsoft.com/en-us/library/dn986596.aspx
It does exactly what you want. And before that String Litterals were almost the only option.
Edit :
Question was : "Clearly there is no 'NameOf' operator, and I don't know how to write a NameOf function."
If I understand your problem right, you have a list of classes that you fetched from dynamically loaded DLL, point is you don't know if a class implements all of the hooks or only a few.
If you use an interface, like IHookable and put all the hook functions in there, it means all the DLL have to implement all the hook functions, which is not what you want.
And (if I understand it properly) if the first class in list does not implement the hook, you check the second one and so on. So with an interface you wouldn't know if the hook is implemented or not.

Instantiation of System.ServiceModel.Description.WsdlContractConversionContext class

For the case of a project requirement, I need to instantiate WsdlContractConversionContext which is not having a constructor for doing so.
Is there any work around to achieve this?
WsdlContractConversionContext is a member of the System.ServiceModel.Description namespace.
Note:
The requirement exactly is that, I am doing an implementation of IWsdlExportExtension.ExportContract and IWsdlImportExtension.ImportContract, and to unit test this implemetation I need the instance of WsdlContractConversionContext.
There are basically two ways to do that: you can either use reflection to call the non-public constructor of the class (making sure you're passing appropriate parameters to it); or you can let WCF create it for you, and use it wherever you need. The WsdlContractConversionContext is passed as one of the parameters to either IWsdlExportExtension.ExportContract or an IWsdlImportExtension.ImportContract, so you'd need to implement one of the two interfaces (exporting is usually easier, since you won't need to fiddle with WSDL-consuming tools), and force the interface to be called (you may need to hit the service metadata endpoint for that).
The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/10/06/wcf-extensibility-wsdl-export-extension.aspx has an example of an implementation of a WSDL export extension.
Update following edit in the question: many parts of WCF are notoriously hard to be unit tested. If you can't use WCF itself to create the instance, the only alternative you have is to use reflection. To create an instance of the conversion context class you need an instance of a ContractDescription (which you can create for your contract, but isn't easy), and a PortType, which is even harder. I'm afraid that unit testing your implementation of the WSDL export / import extension may not be worth the effort.