Skip to content

Commit 19aee3b

Browse files
committed
Add IProvider and IProviderCollection interfaces and implementations
This change introduces a new provider model into PowerShell Editor Services so that feature components can have an arbitrary number of providers registered which are used in addition to any default implementations. This is intended to be used as an extensibility mechanism.
1 parent 8f5d11a commit 19aee3b

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace Microsoft.PowerShell.EditorServices
7+
{
8+
/// <summary>
9+
/// Defines the contract for a feature provider, particularly for provider identification.
10+
/// </summary>
11+
public interface IProvider
12+
{
13+
/// <summary>
14+
/// Specifies a unique identifier for a provider, typically a
15+
/// fully-qualified name like "Microsoft.PowerShell.EditorServices.MyProvider"
16+
/// </summary>
17+
string ProviderId { get; }
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.PowerShell.EditorServices
9+
{
10+
/// <summary>
11+
/// Defines the contract for a collection of provider implementations.
12+
/// </summary>
13+
public interface IProviderCollection<TProvider> : IEnumerable<TProvider>
14+
where TProvider : IProvider
15+
{
16+
/// <summary>
17+
/// Adds a provider to the collection.
18+
/// </summary>
19+
/// <param name="provider">The provider to be added.</param>
20+
void Add(TProvider provider);
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace Microsoft.PowerShell.EditorServices
7+
{
8+
/// <summary>
9+
/// Provides a base implementation of IProvider.
10+
/// </summary>
11+
public abstract class ProviderBase : IProvider
12+
{
13+
/// <summary>
14+
/// Gets the provider class type's FullName as the
15+
/// ProviderId.
16+
/// </summary>
17+
public string ProviderId => this.GetType().FullName;
18+
}
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
7+
using System.Collections;
8+
using System.Collections.Generic;
9+
10+
namespace Microsoft.PowerShell.EditorServices
11+
{
12+
/// <summary>
13+
/// Provides a default implementation of IProviderCollection.
14+
/// </summary>
15+
public class ProviderCollection<TProvider> : IProviderCollection<TProvider>
16+
where TProvider : IProvider
17+
{
18+
#region Private Fields
19+
20+
private List<TProvider> providerList = new List<TProvider>();
21+
22+
#endregion
23+
24+
#region IProviderCollection Implementation
25+
26+
void IProviderCollection<TProvider>.Add(TProvider provider)
27+
{
28+
if (!this.providerList.Contains(provider))
29+
{
30+
this.providerList.Add(provider);
31+
}
32+
}
33+
34+
IEnumerator<TProvider> IEnumerable<TProvider>.GetEnumerator()
35+
{
36+
return this.providerList.GetEnumerator();
37+
}
38+
39+
IEnumerator IEnumerable.GetEnumerator()
40+
{
41+
return this.providerList.GetEnumerator();
42+
}
43+
44+
#endregion
45+
}
46+
}

0 commit comments

Comments
 (0)