ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2; IBoundsProperties bounds = legend as IBoundsProperties; bounds.FixedAspectRatio = false;
CoClasses "implement" the behavior defined by the Interface.
Interfaces only define a contract, there is nothing between the curly braces, i.e. no implementation.
It is correct to use Interface types as reference variables, but what I was trying to tell the original poster is that you cannot expect to assign Interface types to Interface types and expect to call a method that is only implemented on one of the CoClasses. I was hoping that by reading this he would know how to fix his problem. He needs to instantiate an instance of whatever CoClass he wants and assign it to an Interface. He was trying to get a Legend by calling some method that returns an Interface and then assign that Interface to his IBoundsProperty Interface and then he didn't know why he couldn't call FixedAspectRatio.
What do you expect to happen here?
I don't know about "half the time". Do you have a specific example of on which Interface that happens?
ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2; IBoundsProperties bounds = legend as IBoundsProperties; bounds.FixedAspectRatio = false;
Your auto-properties example works on classes, not Interfaces. Interfaces are abstract and only define method signatures. You can't instantiate an Interface, so if there was some kind of functionality provided by an auto-property inside an Interface, you would be breaking the nature of an Interface.
Because the forums shouldn't be vending machines for code samples. Why can't I answer the question the way I want to?
But at the end, he got a NotImplementedException because he assigned an Interface type (ILegend) which does not implement or even define FixedAspectRatio to a reference variable type of IBoundsProperties which does. The compiler is going to check the actual type of the reference and tell you: "hey, FixedAspectRatio is not implemented on the object type you have currently".
I disagree with you on the IGeometryInterface. Why couldn't it be possible for someone to create their own special geometry class that wants to provide implementation for the methods defined in the IGeometryInterface? Just because you don't do it, doesn't mean someone else might not want to.
You can define constants in Java Interfaces now and people abuse them.
Every once in a while I get into conversations like these. It usually starts and ends the same way every time where someone wants to get in a word battle with me over what did you call it - academic meanings? I'm just using the standard language that is out there and I always run into people who what to use a different language (not programming language) in which to communicate. If you have a better word for my use of the word "implement" for classes that need to provide the guts to the method signatures in Interfaces, let me hear it. I'd be glad to consider to start using it.
I think if people "want" to add default methods to Interfaces, then maybe they should be looking at extending an Abstract Class for that instead. Abstract Classes can have "implementation" code in their methods. And, since you can re-declare and re-define the default methods in Interfaces, what would be the point? You would be breaking the intent of having a default method in Interfaces in the first place.
I just tested in 10.1 and had the same result as Robert: No exception was thrown, but FixedAspectRatio remained true even after setting it to false. However, I also found that the legend was able to adjust its width and height properties correctly without my intervention, so my solution of programmatically updating the size of the element containing the legend is no longer necessary in ArcGIS 10.1.
IWorkspaceFactory rasWkspFactory = new RasterWorkspaceFactory(); IWorkspace wksp = new RasterWorkspace(rasWkspFactory.openFromFile(aPath, 0));
>>Would you mind taking a look at tomalley23's question?
Can you help me find it in this new forum? I don't remember the title of that post.