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

SupportsNewObjectCreation property doesn't do anything. #13

Closed
sekulicb opened this issue Nov 23, 2020 · 3 comments
Closed

SupportsNewObjectCreation property doesn't do anything. #13

sekulicb opened this issue Nov 23, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@sekulicb
Copy link

Describe the bug
I have some properties that will throw exception in get and set if some other dependent property is not properly set. For this reason, I have implemented custom LookUpContract and set SupportsNewObjectCreation to false, just to avoid creating objects, since they should only be created in backend and just filtered on the UI.

If you put the breakpoint on SupportsNewObjectCreation it will never be hit. At what point this property gets called ?

To Reproduce
1.Create object such as :

class Test
{
private int _num;
private string _text
public int Num {get; set;}
public string Text {get {if _num == 99 throw exception else return _text }; set {}
}
  1. Create collection and pass it to the UI
  2. Provide custom LookUpContract implementation setting public bool SupportsNewObjectCreation => false;
  3. Put breakpoint on this property
  4. Start the app, add one item, add another, then try to delete items
  5. Reaches get of the Text property, resulting in crash

Expected behavior
Not to call getter of this property, and don't create a new instance

BlackPearl 1.0.2.1
.net core 3.1 WPF app

@sekulicb sekulicb added the bug Something isn't working label Nov 23, 2020
@nilayjoshi89
Copy link
Owner

Hi Sekulicb,

I tried to reproduce scenario issue with steps you mentioned.
I figured there are two separate issue here-

1) Crash on clearing all items -
Are you getting serialization error in exception? If so, try making entity public. i.e. TestData

2) Property throwing exception -
This is highly not recommended doing so. Try creating new property which does not throw exception or wrapper object. However, if you don't control that entity (Third Party) or don't want to create wrapper one, handle property exception in Look-up contract. I was able to do so. Should work for you as well.

One suggestion, implement LookUpContract only if you need custom sorting or want to support new object creation on UI. Basic, filtering is by default provided by control on DisplayMemberPath.

Let me know if this helps!

Thanks,
Nilay Joshi

@sekulicb
Copy link
Author

Hi @nilayjoshi89

  1. No, sorry my bad, I forgot to include the public keyword at the beginning. Entity is public
  2. I actually considered creating wrapper object, and I think it should be a way to go. Catching exception for each object will not be performant, since ItemSource will contain right from the start ~4500 items.

Yes, "starts with" query will not work for me. I need to match cases not just check if the string starts with given input. I need to check if substring is found in string. So for example:

user starts typing "lay"

it will find the nilay as search result instead of typing "ni...." to get the same result.

Thanks

@nilayjoshi89
Copy link
Owner

Closing issue as all points are addressed.

Thanks,
Nilay Joshi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants