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

[QUESTION] Is it safe to derive my type from BsonExpression? #1468

Closed
nightroman opened this issue Feb 11, 2020 · 2 comments
Closed

[QUESTION] Is it safe to derive my type from BsonExpression? #1468

nightroman opened this issue Feb 11, 2020 · 2 comments
Labels

Comments

@nightroman
Copy link
Contributor

nightroman commented Feb 11, 2020

LiteDB 5.0.2

Fact: The type LiteDB.BsonExpression is not sealed.
Question: Is this "accidental" or I may "safely" derive my type from it?

I have a use case for such inheritance in Ldbc, the PowerShell module based on LiteDB.

For the moment I use a not derived wrapper of BsonExpression, somewhat more PowerShell friendly. Of course, sooner or later it is supposed to be passed in LiteDB methods expecting BsonExpression and has to be unwrapped, sometimes with expensive type checks (because my command parameters accept native BsonExpression as well).

If I derive my wrapper from BsonExpression then some tedious type checks may be removed and performance may be better. But I am not sure if this design is safe. Looking forward to some advice.

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 12, 2020

My quick answer: I never thought about in a class that inherits BsonExpression. This class is like Expression in LINQ tree. But in LINQ, types of Expression are represented using another classes. In BsonExpression I simplify this using only Type.

I have no plans (yet) to create sub/super classes from BsonExpression. I had no needs for that. BsonExpression works nice for me now. If you prefer to inherits from BsonExpression I don't see any problem..... but, I will talk with @lbnascimento and @JensSchadron about this if they have another opinion about this.

@nightroman
Copy link
Contributor Author

nightroman commented Feb 21, 2020

It turns out it is practically impossible to derive from BsonExpression because it provides no public or protected constructors. Thus, see the PR, I suggest making BsonExpression explicitly sealed. This will avoid further similar questions and unsuccessful attempts to derive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants