2

When using interface + enum combination it should be possible to prevent InterfaceVariable := EnumVariable assignment in dependent apps.


For example:


codeunit CustomSecret implements Secret { Access = Internal; internal procedure GetMySecret(): SecretText begin ... end; }

enumextension CustomSecretType extends SecretType { value(9999; CustomSecret) { Implements = Secret = CustomSecret; } }


Currently, there is no way to prevent any dependent app from getting the custom secret using Secret := Enum::Secret::CustomSecret;


This effectively "removes" the Access = Internal on the implementation codeunit at least for procedures required by the interface.


There should be an option to prevent this - a property on the enum ImplementationAccess = Public or Internal for each possible interface. When ImplementationAccess is Public, any code should be able to get an instance of the implementation codeunit (current behavior). But when ImplementationAccess is Internal, only the code in the same app should be able to get instance of the implementation codeunit.


This behavior should only apply to enum value to interface assignments: so assignment statement, passing enum value to interface parameter in procedure and exit statement.


Example:


// in "main" app

enum MyEnum implements MyInterface { ImplementationAccess = MyInterface = Internal; ... }


// in "main" or dependent app

var MyInterface: Interface MyInterface; MyEnumValue: Enum MyEnum;

MyEnumValue := MyEnum.Ordinals().Get(123); // somehow get a particular enum value. does not matter how.

MyInterface := MyEnumValue; // allowed in the "main" app

MyInterface := MyEnumValue; // compilation error in the dependent app


The "main" app will still be able to provide a way to give interface implementations to dependent apps. Example:


procedure GetInterface(MyEnum: Enum MyEnum): Interface MyInterface

begin

// maybe some checks before

exit(MyEnum);

end;


so

MyInterface := MyConverter.GetInterface(MyEnumValue); // is ok from compiler's perspective

Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team