public static void RemoveService <T>(IPropertyOwner propertyOwner) where T : class { if (propertyOwner != null) { var sm = TryGetOrCreate(propertyOwner, null); sm?.RemoveService <T>(); } }
/// <summary> /// Add service to a service manager associated with a particular Property owner /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="serviceInstance">Service instance</param> /// <param name="propertyOwner">Property owner</param> /// <param name="shell"></param> public static void AddService <T>(T serviceInstance, IPropertyOwner propertyOwner, ICoreShell shell) where T : class { var sm = FromPropertyOwner(propertyOwner, shell); Debug.Assert(sm != null); sm.AddService(serviceInstance); }
public static void RemoveService <T>(IPropertyOwner propertyOwner, IContentType contentType) where T : class { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); sm.RemoveService <T>(contentType); }
/// <summary> /// Add service to a service manager associated with a particular property owner. /// Typically used to store services implemented in native code and identified by /// the interface GUID. /// </summary> /// <typeparam name="serviceGuid">Service GUID</typeparam> /// <param name="serviceInstance">Service instance</param> /// <param name="propertyOwner">Property owner</param> public static void AddService(ref Guid serviceGuid, object serviceInstance, IPropertyOwner propertyOwner) { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); sm.AddService(ref serviceGuid, serviceInstance); }
public static void RemoveService(IPropertyOwner propertyOwner, ref Guid guidService) { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); sm.RemoveService(ref guidService); }
/// <summary> /// Add content type specific service to a service manager associated with a particular Property owner /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="serviceInstance">Service instance</param> /// <param name="propertyOwner">Property owner</param> /// <param name="contentType">Content type of the service</param> public static void AddService <T>(T serviceInstance, IPropertyOwner propertyOwner, IContentType contentType) where T : class { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); sm.AddService <T>(serviceInstance, contentType); }
public PropertyChangeNotifier(IPropertyOwner owner) { if (activeNotifiers.ContainsKey(owner)) { throw new InvalidOperationException($"Cannot nest delayed notification for {owner}."); } activeNotifiers.Add(this.owner = owner, this); }
public IEditorOptions GetOptions(IPropertyOwner scope) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(scope.Properties.GetOrCreateSingletonProperty(typeof(IEditorOptions), () => new EditorOptions(this, GlobalOptions, scope))); }
private static void DisposeServiceManagerOnIdle(IPropertyOwner propertyOwner, ICoreShell shell) { var sm = FromPropertyOwner(propertyOwner, null); if (sm != null) { IdleTimeAction.Create(() => sm.Dispose(), 150, new object(), shell); } }
public EditorOptions(EditorOptionsFactoryService service, EditorOptions parent, IPropertyOwner scope) { this.service = service; this.parent = parent; dict = new Dictionary <string, object>(StringComparer.Ordinal); weakChildren = new List <WeakReference>(); this.scope = scope; UpdateOptions(null); }
public static T GetService <T>(IPropertyOwner propertyOwner) where T : class { try { var sm = TryGetOrCreate(propertyOwner, null); return(sm?.GetService <T>()); } catch (Exception) { return(null); } }
public IEditorOptions GetOptions(IPropertyOwner scope) { if (scope == null) { throw new ArgumentNullException("scope"); } return(scope.Properties.GetOrCreateSingletonProperty <IEditorOptions>(() => new EditorOptions(this.GlobalOptions as EditorOptions, scope, this))); }
public static void RemoveService <T>(IPropertyOwner propertyOwner) where T : class { if (propertyOwner != null) { var sm = FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); sm.RemoveService <T>(); } }
/// <inheritdoc /> public IFeatureService GetOrCreate(IPropertyOwner scope) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(scope.Properties.GetOrCreateSingletonProperty( () => new FeatureService(GlobalFeatureService, this))); }
public static T Get <T>(this IPropertyOwner owner) where T : class { T t; if (owner.Properties.TryGetProperty(typeof(T), out t)) { return(t); } return(null); }
public TextUndoHistory(IPropertyOwner propertyOwner) { State = TextUndoHistoryState.Idle; PropertyOwner = propertyOwner ?? throw new ArgumentNullException(nameof(propertyOwner)); Properties = new PropertyCollection(); redoList = new List <TextUndoTransaction>(); undoList = new List <TextUndoTransaction>(); readOnlyRedoList = new ReadOnlyCollection <TextUndoTransaction>(redoList); readOnlyUndoList = new ReadOnlyCollection <TextUndoTransaction>(undoList); }
static List <string> CreateItemPropertyNotificationLog(IPropertyOwner i) { List <string> log = new List <string>(); i.PropertyChanging += (s, e) => log.Add($"-{e.PropertyName}: {((IPropertyOwner)s)[e.PropertyName]}"); i.PropertyChanged += (s, e) => log.Add($"+{e.PropertyName}: {((IPropertyOwner)s)[e.PropertyName]}"); return(log); }
/// <summary> /// Retrieves service from a service manager for this Property owner given service type and content type /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="propertyOwner">Property owner</param> /// <param name="contentType">Content type</param> /// <returns>Service instance</returns> public static T GetService <T>(IPropertyOwner propertyOwner, IContentType contentType) where T : class { var sm = ServiceManager.FromPropertyOwner(propertyOwner); if (sm != null) { return(sm.GetService <T>(contentType)); } return(null); }
public static ICollection <T> GetAllServices <T>(IPropertyOwner propertyOwner) where T : class { var sm = ServiceManager.FromPropertyOwner(propertyOwner); if (sm != null) { return(sm.GetAllServices <T>()); } return(new List <T>()); }
public TextUndoHistory(IPropertyOwner propertyOwner) { if (propertyOwner == null) throw new ArgumentNullException(nameof(propertyOwner)); State = TextUndoHistoryState.Idle; PropertyOwner = propertyOwner; Properties = new PropertyCollection(); redoList = new List<TextUndoTransaction>(); undoList = new List<TextUndoTransaction>(); readOnlyRedoList = new ReadOnlyCollection<TextUndoTransaction>(redoList); readOnlyUndoList = new ReadOnlyCollection<TextUndoTransaction>(undoList); }
public static T GetService <T>(IPropertyOwner propertyOwner) where T : class { try { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); return(sm.GetService <T>()); } catch (Exception) { return(null); } }
public static object GetService(IPropertyOwner propertyOwner, ref Guid serviceGuid) { try { var sm = ServiceManager.FromPropertyOwner(propertyOwner); Debug.Assert(sm != null); return(sm.GetService(ref serviceGuid)); } catch (Exception) { return(null); } }
protected virtual void OnCacheContainerClosing(IPropertyOwner cacheContainer) { TPresenter presenter; if (cacheContainer.Properties.TryGetProperty <TPresenter>(typeof(TPresenter), out presenter)) { presenter.Dispose(); cacheContainer.Properties.RemoveProperty(typeof(TPresenter)); } }
public FakeEditorOptions(ExportProvider exportProvider, IPropertyOwner scope) { foreach (var optionDefinition in exportProvider.GetExportedValues <EditorOptionDefinition>()) { if (!optionDefinition.IsApplicableToScope(scope)) { continue; } _supportedOptions[optionDefinition.Name] = optionDefinition; } }
/// <summary> /// Returns service manager attached to a given Property owner /// </summary> /// <param name="propertyOwner">Property owner</param> /// <returns>Service manager instance</returns> public static ServiceManager FromPropertyOwner(IPropertyOwner propertyOwner) { ServiceManager sm = null; if (propertyOwner.Properties.ContainsProperty(ServiceManagerId)) { sm = propertyOwner.Properties.GetProperty(ServiceManagerId) as ServiceManager; return(sm); } return(new ServiceManager(propertyOwner)); }
public ThemeProperty( IPropertyOwner owner, int index, long offset, TMT propertyId, TMT primitiveType, PropertyOrigin origin, object value) { Owner = owner; Index = index; Offset = offset; PropertyId = propertyId; PrimitiveType = primitiveType; Origin = origin; Value = value; }
public void Dispose() { if (this._propertyOwner != null) { this._propertyOwner.Properties.RemoveProperty(ServiceManagerId); this._servicesByGuid.Clear(); this._servicesByType.Clear(); this._servicesByContentType.Clear(); this._propertyOwner = null; } }
/// <summary>Alias to <c>owner.Properties.GetOrCreateSingletonProperty<T>(creator)</c>.</summary> /// <remarks>Do not use it in a cycle due to performance issue.</remarks> public static T ObtainOrAttachProperty <T>(this IPropertyOwner owner, Func <T> creator) where T : class { if (owner is null) { throw new ArgumentNullException(nameof(owner)); } if (creator is null) { throw new ArgumentNullException(nameof(creator)); } return(owner.Properties.GetOrCreateSingletonProperty(creator)); }
/// <summary>Alias to <c>(T)owner.Properties.GetProperty(typeof(T))</c>.</summary> /// <remarks>Do not use it in a cycle due to performance issue.</remarks> public static T ObtainProperty <T>(this IPropertyOwner owner) { if (owner is null) { throw new ArgumentNullException(nameof(owner)); } if (owner.Properties.TryGetProperty <T>(typeof(T), out var result)) { return(result); } throw new InvalidOperationException("The specified type could not be found inside the property bag"); }
public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent) { if (pEvent == null) { throw new ArgumentNullException("pEvent"); } if (!(pEvent is DebugEvent)) { return(VSConstants.E_INVALIDARG); } if (pEvent is IDebugEngineCreateEvent2) { return(VSConstants.S_OK); } IPropertyOwner propertyOwner = pEvent as IPropertyOwner; if (propertyOwner != null) { bool manualResume; propertyOwner.Properties.TryGetProperty("ManualResume", out manualResume); SuspendPolicy suspendPolicy; if (!manualResume && propertyOwner.Properties.TryGetProperty(typeof(SuspendPolicy), out suspendPolicy)) { IThreadReference thread = propertyOwner.Properties.GetProperty <IThreadReference>(typeof(IThreadReference)); switch (suspendPolicy) { case SuspendPolicy.All: JavaDebugProgram program = propertyOwner.Properties.GetProperty <JavaDebugProgram>(typeof(JavaDebugProgram)); JavaDebugThread debugThread; program.Threads.TryGetValue(thread.GetUniqueId(), out debugThread); program.Continue(debugThread); break; case SuspendPolicy.EventThread: Task.Factory.StartNew(thread.Resume).HandleNonCriticalExceptions(); break; case SuspendPolicy.None: break; } } } return(VSConstants.S_OK); }
public static ServiceManagerBase TryGetOrCreate(IPropertyOwner propertyOwner, Func <IPropertyOwner, ServiceManagerBase> factory) { ServiceManagerBase sm = null; if (propertyOwner.Properties.ContainsProperty(typeof(ServiceManagerBase))) { sm = propertyOwner.Properties.GetProperty(typeof(ServiceManagerBase)) as ServiceManagerBase; } else if (factory != null) { sm = factory(propertyOwner); } return(sm); }
private bool NotReadyRockAndRoll(IPropertyOwner view) { return view == null || Dte.ActiveDocument == null; }
public IEditorOptions GetOptions(IPropertyOwner scope) { if (scope == null) throw new ArgumentNullException(nameof(scope)); return scope.Properties.GetOrCreateSingletonProperty(typeof(IEditorOptions), () => new EditorOptions(this, GlobalOptions, scope)); }