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

Add Rules from code #7685

Closed
wants to merge 1 commit into from

Conversation

tmeschter
Copy link
Contributor

@tmeschter tmeschter commented Oct 12, 2021

Define a type that defines Rule instances in code (rather than loading them from XAML) and dynamically adds and removes them from the project based on capabilities.

Microsoft Reviewers: Open in CodeFlow

Define a type that defines `Rule` instances in code (rather than loading them from XAML) and dynamically adds and removes them from the project based on capabilities.
@tmeschter
Copy link
Contributor Author

This PR is just for the purposes of discussion; this should never be merged.

<value>My In-Memory Page 😀</value>
</data>
<data name="MyPropertyPage_PropertyDescription" xml:space="preserve">
<value>🎉 Put anything you want here! It doesn't matter! 🎉</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we display emojis in the UI? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Though WPF doesn't color them.

Comment on lines +46 to +49
_additionalRuleDefinitionsService.AddRuleDefinition(_rule.Value, context: "Project");

return Task.CompletedTask;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were doing this for real, you'd want to setup a direct data flow relationship between the capability change and the resulting rules. Otherwise, this is going to result in situations where the project and the rules associated with it are out of sync. You would do that by exporting IAdditionalRuleDefinitionsService and have AdditionalRuleDefinitions property return a data source that changed based on the capabilities changing (you'd need to delegate/listen to underlying IAdditionalRuleDefinitionsService as there can only be one).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would want to create a new IAdditionalRuleDefinitionsService implementation anyway (or augment the existing one) in order to simplify the experience for anyone wishing to create Rules in this manner. Ideally, they would just associate a set of Rules with a capability condition, and the underlying service would handle capability changes and pushing information through the data flow.

Is it possible to replace the IAdditionalRuleDefinitionsService with a new one? The interface is defined as:

[ProjectSystemContract(ProjectSystemContractScope.UnconfiguredProject, ProjectSystemContractProvider.System)]
public interface IAdditionalRuleDefinitionsService : IProjectValueDataSource<IAdditionalRuleDefinitions>
{
    ...
}

So there's only supposed to be exactly one per unconfigured project. Would it be possible to MEF-export a different implementation that would replace it?

@tmeschter
Copy link
Contributor Author

This approach has been superceded by IRuleObjectProvider (see #7922 for an example of that). Please use that approach instead of what is demonstrated here.

@tmeschter tmeschter closed this Feb 17, 2022
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.

3 participants