-
-
Save warrenbuckley/a6adc536924c8528331450b929aba877 to your computer and use it in GitHub Desktop.
| public class MyComposer : IUserComposer | |
| { | |
| public void Compose(Composition composition) | |
| { | |
| // Register service into the container | |
| composition.RegisterUnique<PaletteService>(); | |
| composition.RegisterUnique<ThemeService>(); | |
| // Add our PVC to the collection of stuff | |
| composition.PropertyValueConverters().Append<ThemePickerPropertyConvertor>(); | |
| composition.Components().Append<ColorUpdateComponent>(); | |
| var otherPackageComponentType = AppDomain.CurrentDomain.GetAssemblies() | |
| .SelectMany(t => t.GetTypes()) | |
| .FirstOrDefault(x => x.FullName == "SomePackage.Components.TheirComponent"); | |
| if (composition.Components().Has(otherPackageComponentType)) | |
| { | |
| composition.Components().Remove(otherPackageComponentType); | |
| } | |
| } | |
| } | |
| } |
OK, questions:
- Do you have access to
otherPackageComposerType? - Do you have access to
otherPackageComponentType?
I can't do the following though @zpqrtbnk as my package does not directly reference the other package I am trying to disable so I don't have their type in my project so cant do [ComposeAfter(typeof(SomePackage.Components.TheirComponent))]
Would it be OK to entirely disable the otherPackageComposerType? The whole composer?
If so... mark your composer with:
[DisableOtherPackage]
With:
public class DisableOtherComposerAttribute : DisableAttribute
{
public DisableOtherComposerAttribute ()
{
var field = typeof(DisableAttribute).GetField("<DisabledType>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance);
if (field == null) throw new Exception("panic: cannot get DisableAttribute.DisableType backing field.");
var type = Type.GetType("Namespace.Of.OtherComposer,OtherComposerAssembly", false);
field.SetValue(this, type);
}
}
Replace "Namespace.Of.OtherComposer,OtherComposerAssembly" with the full name of the composer type you want to disable.
Should you want to only remove the component but not disable the entire composer... you would need to iterate over the types in composition.Components() (not sure that can be done) and find the one you want to remove, by comparing names.
Interesting... but note that Type.GetType will only find types already loaded by the AppDomain. If this works then great, but if it doesn't work, then you'll need to do Assembly.Load("OtherComposerAssembly").GetType("Namespace.Of.OtherComposer")
Assuming
otherPackageComponentTypeis added byotherPackageComposerType, mark your composer with[ComposeAfter(otherPackageComposerType)]and it will execute after that composer, letting you remove the component.