Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prohibit reflection with Activator.CreateInstance #227

Merged
merged 2 commits into from
Sep 25, 2022

Conversation

SteveDunn
Copy link
Owner

@SteveDunn SteveDunn commented Sep 25, 2022

The purpose of this change is to phohibit creation using Activator.CreateInstance.

Creating Value Objects with Reflection evades the validation mechanism, allowing invalid Value Objects to be live in the domain of the application.

For instance, with this Value Object:

[ValueObject]
public partical struct CustomerId {{ }}

It disallows this:

// result in error VOG025: Type 'CustomerId' cannot be constructed via Reflection as it 
var c = Activator.CreateInstance<CustomerId>(); is prohibited.

and...

// result in error VOG025: Type 'CustomerId' cannot be constructed via Reflection as it 
var c = (CustomerId)Activator.CreateInstance(); 

@SteveDunn SteveDunn merged commit e076189 into main Sep 25, 2022
@SteveDunn SteveDunn deleted the prohibit-reflection branch September 25, 2022 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant