You are developing a .NET Framework application. You write the following code in your application:
public interface IShape
{
double GetArea();
double GetPerimeter();
}
public class Shape : IShape
{
public Shape()
{
}
public double GetArea()
{
double area = 0;
// Additional code goes here
return area;
}
public double GetPerimeter()
{
double perimeter = 0;
// Additional code goes here
return perimeter;
}
}
You must make sure that Component Object Model (COM) clients interact with the members of the Shape class exclusively by using an interface reference. The COM clients must only be able to early-bind to the types in the .NET assembly.
You must also make sure that adding or rearranging members to the IShape interface does not cause existing COM clients to fail.
What should you do? (Each correct answer presents part of the solution. Choose two.)
The ClassInterfaceType.None setting indicates that no class interface is automatically generated for the class. Any functionality of the class in this case must be exposed through the interface that is explicitly implemented by the class. Therefore, you should apply the following attribute to the Shape class:
[ClassInterface(ClassInterfaceType.None)]
The InterfaceType attribute indicates how an interface is exposed to COM. The ComInterfaceType.InterfaceIsIUnknown setting of the InterfaceType attribute only supports early-binding. Therefore, you should apply the following attribute to the IShape interface:
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
The default setting for the ClassInterface attribute is ClassInterfaceType.AutoDispatch, which indicates that an interface is automatically generated for the COM client on request at runtime. Therefore, you should not apply the following attribute to the Shape class:
[ClassInterface(ClassInterfaceType.AutoDispatch)]
The ClassInterfaceType.AutoDual setting binds to a specific interface layout. This may create problems when the order of members in an interface is changed in later versions. Because it can create versioning problems, the use of ClassInterfaceType.AutoDual setting is discouraged. Therefore, you should not apply the following attribute to the Shape class:
[ClassInterface(ClassInterfaceType.AutoDual)]
The default setting of the InterfaceType attribute is ComInterface.InterfaceIsDual, which means that the interface supports both early-binding and late-binding. The ComInterfaceType.InterfaceIsIDispatch setting of the InterfaceType attribute only supports late-binding. Therefore, you should not apply the following attribute to the IShape interface:
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
Objective:
List all questions for this objective
Implementing interoperability, reflection, and mailing functionality in a .NET Framework application
Sub-Objective:
6.1 Expose COM components to the .NET Framework and .NET Framework components to COM. (Refer System.Runtime.InteropServices namespace)
