How to get the specialized type of an EStructuralFeature's getEType()? - eclipse

I have a method where an EStructuralFeature comes in as a parameter. I can get the type of the feature via the method getEType() and get the "real" Java class via the EType's getInstanceClass() method. So far so good. But what if this type is generic, and I want to know its special type? Unfortunately this information is gone due to Java's Type Erasure, but is there a way to achieve this by using EMF's functionality?

EStructuralFeature is an interface extends to ETypedElement
more details here:
[http://download.eclipse.org/modeling/emf/emf/javadoc/2.7.0/org/eclipse/emf/ecore/EStructuralFeature.html]

Related

Which is the difference beetwen implement a object of interface type or object of class type?

I have seen is possible to instantiate an object who implements an interface instead of a class. I´d like to know what are the benefits of this.
I attach an example :
Interface just tells the program, that this object it just received has these methods defined. So you can have multiple different classes implement the same interface. And when a method accepts a given interface, then it can accept all the classes that implement the interface.
By instansiating a class into interface, you are saying, that whatever following code does, it cares only about the methods stated in the interface.
If you instansiate into class type, you are saying you want only this spesific type and none else.

NDepend: Check if a type implements a generic interface

Is there a way to check if a type is implementing a generic type with certain generic parameters using NDepend?
The implemented interface property returns the generic type, but without specific generic parameters. So IList for example, instead I want to no if a certain type implements IList.
You can write a query like:
from t in Types where t.Implement("System.Collections.Generic.IList<T>")
select t
but you cannot write a query like:
from t in Types where t.Implement("System.Collections.Generic.IList<System.Int32>")
select t
So the answer is no to Is there a way to check if a type is implementing a generic type with certain generic parameters using NDepend?
This situation might evolve in the future, feel free to add request to the NDepend User Voice page.

Scala - Can implicitNotFound annotation be applied at the method level?

I have a method that takes type parameters with an implicit view bounds on them. Can I use the #implicitNotFound annotation to give nicer compiler errors when the method is called with invalid data types?
The documentation for the method is useless and even the source code doesn't help, and all the examples of use online are at the trait or class level.
No, you cannot directly do that. As you’ve noticed, #implicitNotFound annotates traits or classes. You could, however, make a special implicit type just for that method and annotate it if you really wanted to have a custom message.

TS Interface doesn't force functions signature on implementers

interface test{
foo(boo:string);
}
class coo implements test{
foo(){
}
}
In playGround
this doesn't generate and error although the function signature is not as the interface
says, the expected behavior of interface is to force the signature..
why is this behavior?
Thanks
This is interesting. The TypeScript team are quite clever chaps and they decided to do this deliberately.
The idea is that if your function can operate correctly without being passed an argument, it can safely ignore the argument and satisfy the interface. This means you can substitute your implementation without having to update all of the calling code.
The interface ensures that the argument is passed in all cases where you are consuming the interface - so you get type checking on the callers and it actually doesn't matter that your concrete class doesn't need any parameters.
Interface Function Parameter Not Enforced
I am not satisfied how Interface doesn't enforce the method signature too. I believe the explanations by Fenton are wrong. The real reason is that Typescript is using "duck typing". No erros with less parameters, but you do get errors if you use more parameters.The long answer can be found here Why duck typing is allowed for classes in TypeScript
In the end, Interface can't fit the role of an abstract class that is extended by an other class. I wouldn't recommend to use Interface with classes but instead better use the word "implements" on an actual class, it does the same without the extra Interface class.
Typescript uses structural typing. The implemented function can have fewer parameters than the function declaration in the interface but not more.

Autofac difference between Register and RegisterType

I have started to use Autofac following this tutorials:
http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html
Simple class with no parameter in the constructor
builder.RegisterType<ConsoleOutputService>().As<IOutputService>();
As explained in the tutorial, the code above can be read as: setup ConsoleOutputService as the implementation of IOutputService
Simple class with one parameter in the constructor
builder.Register(c => new MultipleOutputService(outputFilePath)).As<IOutputService>();
I don't understand why are we using a lambda expression to register this class (and what does this expression exactly does) and why we can't type this code
builder.RegisterType<MultipleOutputService(outputFilePath)>().As<IOutputService>();
Thanks in advance for your help
Btw there is a better solution to this Autofac introduced the .WithParameter() extension to their registration builder.
.RegisterType<MultipleOutputService>().As<IOutputService>().WithParameter("parameterName", "parameterValue");
This should cater for the event that you need to pass something other than an interface type to one of your constructors
You can't write that code because it doesn't make sense in C#.
RegisterType is a generic method; generic methods must take types as generic parameters.
You're trying to register a type with a custom way to create it (inyour case, a constructor parameter); the only way that C# supports to specify such a thing is a lambda expression (or other delegate).
The lambda variant enables us to do some logic when constructing the instance.