X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ dotnet_diagnostic.SA1312.severity = none
dotnet_diagnostic.SA1313.severity = none

# SA1314: Type parameter names should begin with T
dotnet_diagnostic.SA1314.severity = none
dotnet_diagnostic.SA1314.severity = warning

# SA1316: Tuple element names should use correct casing
dotnet_diagnostic.SA1316.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,17 +1066,21 @@ private List<T> RehydrateList<T>(string commandName, object deserializedList, Fu
return result;
}

private Dictionary<K, V> RehydrateDictionary<K, V>(string commandName, PSObject deserializedObject, string propertyName, Func<PSObject, V> valueRehydrator)
private Dictionary<TKey, TValue> RehydrateDictionary<TKey, TValue>(
string commandName,
PSObject deserializedObject,
string propertyName,
Func<PSObject, TValue> valueRehydrator)
{
Dbg.Assert(deserializedObject != null, "deserializedObject parameter != null");
Dbg.Assert(!string.IsNullOrEmpty(propertyName), "propertyName parameter != null");

if (valueRehydrator == null)
{
valueRehydrator = (PSObject pso) => ConvertTo<V>(commandName, pso);
valueRehydrator = (PSObject pso) => ConvertTo<TValue>(commandName, pso);
}

Dictionary<K, V> result = new();
Dictionary<TKey, TValue> result = new();
PSPropertyInfo deserializedDictionaryProperty = deserializedObject.Properties[propertyName];
if (deserializedDictionaryProperty != null)
{
Expand All @@ -1085,10 +1089,10 @@ private Dictionary<K, V> RehydrateDictionary<K, V>(string commandName, PSObject
{
foreach (DictionaryEntry deserializedItem in deserializedDictionary)
{
K itemKey = ConvertTo<K>(commandName, deserializedItem.Key);
TKey itemKey = ConvertTo<TKey>(commandName, deserializedItem.Key);

PSObject deserializedItemValue = ConvertTo<PSObject>(commandName, deserializedItem.Value);
V itemValue = valueRehydrator(deserializedItemValue);
TValue itemValue = valueRehydrator(deserializedItemValue);

result.Add(itemKey, itemValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public sealed class MeasureObjectCommand : PSCmdlet
/// Dictionary to be used by Measure-Object implementation.
/// Keys are strings. Keys are compared with OrdinalIgnoreCase.
/// </summary>
/// <typeparam name="V">Value type.</typeparam>
private class MeasureObjectDictionary<V> : Dictionary<string, V>
where V : new()
/// <typeparam name="TValue">Value type.</typeparam>
private class MeasureObjectDictionary<TValue> : Dictionary<string, TValue>
where TValue : new()
{
/// <summary>
/// Initializes a new instance of the <see cref="MeasureObjectDictionary{V}"/> class.
/// Initializes a new instance of the <see cref="MeasureObjectDictionary{TValue}"/> class.
/// Default ctor.
/// </summary>
internal MeasureObjectDictionary() : base(StringComparer.OrdinalIgnoreCase)
Expand All @@ -181,12 +181,12 @@ internal MeasureObjectDictionary() : base(StringComparer.OrdinalIgnoreCase)
/// <returns>
/// The existing value, or a newly-created value.
/// </returns>
public V EnsureEntry(string key)
public TValue EnsureEntry(string key)
{
V val;
TValue val;
if (!TryGetValue(key, out val))
{
val = new V();
val = new TValue();
this[key] = val;
}

Expand Down
16 changes: 8 additions & 8 deletions src/System.Management.Automation/engine/MshMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4974,7 +4974,7 @@ internal override ReadOnlyPSMemberInfoCollection<T> Match(string name, PSMemberT
/// <returns>The enumerator for this collection.</returns>
public override IEnumerator<T> GetEnumerator()
{
return new Enumerator<T>(this);
return new Enumerator(this);
}

internal override T FirstOrDefault(MemberNamePredicate predicate)
Expand Down Expand Up @@ -5028,17 +5028,17 @@ internal override T FirstOrDefault(MemberNamePredicate predicate)
/// <summary>
/// Enumerable for this class.
/// </summary>
internal struct Enumerator<S> : IEnumerator<S> where S : PSMemberInfo
internal struct Enumerator : IEnumerator<T>
{
private S _current;
private T _current;
private int _currentIndex;
private readonly PSMemberInfoInternalCollection<S> _allMembers;
private readonly PSMemberInfoInternalCollection<T> _allMembers;

/// <summary>
/// Constructs this instance to enumerate over members.
/// </summary>
/// <param name="integratingCollection">Members we are enumerating.</param>
internal Enumerator(PSMemberInfoIntegratingCollection<S> integratingCollection)
internal Enumerator(PSMemberInfoIntegratingCollection<T> integratingCollection)
{
using (PSObject.MemberResolution.TraceScope("Enumeration Start"))
{
Expand Down Expand Up @@ -5070,7 +5070,7 @@ public bool MoveNext()
{
_currentIndex++;

S member = null;
T member = null;
while (_currentIndex < _allMembers.Count)
{
member = _allMembers[_currentIndex];
Expand All @@ -5096,7 +5096,7 @@ public bool MoveNext()
/// Current PSMemberInfo in the enumeration.
/// </summary>
/// <exception cref="ArgumentException">For invalid arguments.</exception>
S IEnumerator<S>.Current
T IEnumerator<T>.Current
{
get
{
Expand All @@ -5109,7 +5109,7 @@ S IEnumerator<S>.Current
}
}

object IEnumerator.Current => ((IEnumerator<S>)this).Current;
object IEnumerator.Current => ((IEnumerator<T>)this).Current;

void IEnumerator.Reset()
{
Expand Down
15 changes: 8 additions & 7 deletions src/System.Management.Automation/engine/MshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,21 @@ private static T AdapterGetFirstMemberOrDefaultDelegate<T>(PSObject msjObj, Memb
return retValue;
}

internal static PSMemberInfoInternalCollection<U> TransformMemberInfoCollection<T, U>(PSMemberInfoCollection<T> source) where T : PSMemberInfo where U : PSMemberInfo
internal static PSMemberInfoInternalCollection<TResult> TransformMemberInfoCollection<TSource, TResult>(PSMemberInfoCollection<TSource> source)
where TSource : PSMemberInfo where TResult : PSMemberInfo
{
if (typeof(T) == typeof(U))
if (typeof(TSource) == typeof(TResult))
{
// If the types are the same, don't make a copy, return the cached collection.
return source as PSMemberInfoInternalCollection<U>;
return source as PSMemberInfoInternalCollection<TResult>;
}

PSMemberInfoInternalCollection<U> returnValue = new PSMemberInfoInternalCollection<U>();
foreach (T member in source)
PSMemberInfoInternalCollection<TResult> returnValue = new PSMemberInfoInternalCollection<TResult>();
foreach (TSource member in source)
{
if (member is U tAsU)
if (member is TResult result)
{
returnValue.Add(tAsU);
returnValue.Add(result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1809,8 +1809,8 @@ protected void Dispose(bool disposing)
/// Needed to provide a way to get to the non-blocking
/// MoveNext implementation.
/// </summary>
/// <typeparam name="W"></typeparam>
internal interface IBlockingEnumerator<out W> : IEnumerator<W>
/// <typeparam name="T"></typeparam>
internal interface IBlockingEnumerator<out T> : IEnumerator<T>
{
bool MoveNext(bool block);
}
Expand All @@ -1822,14 +1822,14 @@ internal interface IBlockingEnumerator<out W> : IEnumerator<W>
/// either all the PowerShell operations are completed or the
/// PSDataCollection is closed.
/// </summary>
/// <typeparam name="W"></typeparam>
internal sealed class PSDataCollectionEnumerator<W> : IBlockingEnumerator<W>
/// <typeparam name="T"></typeparam>
internal sealed class PSDataCollectionEnumerator<T> : IBlockingEnumerator<T>
{
#region Private Data

private W _currentElement;
private T _currentElement;
private int _index;
private readonly PSDataCollection<W> _collToEnumerate;
private readonly PSDataCollection<T> _collToEnumerate;
private readonly bool _neverBlock;

#endregion
Expand All @@ -1845,7 +1845,7 @@ internal sealed class PSDataCollectionEnumerator<W> : IBlockingEnumerator<W>
/// <param name="neverBlock">
/// Controls if the enumerator is blocking by default or not.
/// </param>
internal PSDataCollectionEnumerator(PSDataCollection<W> collection, bool neverBlock)
internal PSDataCollectionEnumerator(PSDataCollection<T> collection, bool neverBlock)
{
Dbg.Assert(collection != null,
"Collection cannot be null");
Expand All @@ -1854,7 +1854,7 @@ internal PSDataCollectionEnumerator(PSDataCollection<W> collection, bool neverBl

_collToEnumerate = collection;
_index = 0;
_currentElement = default(W);
_currentElement = default(T);
_collToEnumerate.IsEnumerated = true;
_neverBlock = neverBlock;
}
Expand All @@ -1872,7 +1872,7 @@ internal PSDataCollectionEnumerator(PSDataCollection<W> collection, bool neverBl
/// if the enumerator is positioned before the first element or after
/// the last element; the value of the property is undefined.
/// </remarks>
W IEnumerator<W>.Current
T IEnumerator<T>.Current
{
get
{
Expand Down Expand Up @@ -1933,7 +1933,7 @@ public bool MoveNext(bool block)
_currentElement = _collToEnumerate[_index];
if (_collToEnumerate.ReleaseOnEnumeration)
{
_collToEnumerate[_index] = default(W);
_collToEnumerate[_index] = default(T);
}

_index++;
Expand Down Expand Up @@ -1975,7 +1975,7 @@ public bool MoveNext(bool block)
/// </summary>
public void Reset()
{
_currentElement = default(W);
_currentElement = default(T);
_index = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,14 @@ internal static bool TrueForAll<T>(this IEnumerable<T> collection, Predicate<T>
return true;
}

internal static U[] Map<T, U>(this ICollection<T> collection, Func<T, U> select)
internal static TResult[] Map<TSource, TResult>(this ICollection<TSource> source, Func<TSource, TResult> selector)
{
int count = collection.Count;
U[] result = new U[count];
int count = source.Count;
TResult[] result = new TResult[count];
count = 0;
foreach (T t in collection)
foreach (TSource t in source)
{
result[count++] = select(t);
result[count++] = selector(t);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ internal static IEnumerable<T> EnumerateListProperty<T>(PSObject psObject, strin
}
}

internal static IEnumerable<KeyValuePair<KeyType, ValueType>> EnumerateHashtableProperty<KeyType, ValueType>(PSObject psObject, string propertyName)
internal static IEnumerable<KeyValuePair<TKey, TValue>> EnumerateHashtableProperty<TKey, TValue>(PSObject psObject, string propertyName)
{
if (psObject == null)
{
Expand All @@ -1820,9 +1820,9 @@ internal static IEnumerable<KeyValuePair<KeyType, ValueType>> EnumerateHashtable
{
foreach (DictionaryEntry e in h)
{
KeyType key = ConvertPropertyValueTo<KeyType>(propertyName, e.Key);
ValueType value = ConvertPropertyValueTo<ValueType>(propertyName, e.Value);
yield return new KeyValuePair<KeyType, ValueType>(key, value);
TKey key = ConvertPropertyValueTo<TKey>(propertyName, e.Key);
TValue value = ConvertPropertyValueTo<TValue>(propertyName, e.Value);
yield return new KeyValuePair<TKey, TValue>(key, value);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/System.Management.Automation/engine/serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6871,27 +6871,27 @@ internal static T GetPropertyValue<T>(PSObject pso, string propertyName, Rehydra
}
}

private static ListType RehydrateList<ListType, ItemType>(PSObject pso, string propertyName, RehydrationFlags flags)
where ListType : IList, new()
private static TList RehydrateList<TList, TItem>(PSObject pso, string propertyName, RehydrationFlags flags)
where TList : IList, new()
{
ArrayList deserializedList = GetPropertyValue<ArrayList>(pso, propertyName, flags);
if (deserializedList == null)
{
if ((flags & RehydrationFlags.NullValueMeansEmptyList) == RehydrationFlags.NullValueMeansEmptyList)
{
return new ListType();
return new TList();
}
else
{
return default(ListType);
return default(TList);
}
}
else
{
ListType newList = new ListType();
TList newList = new TList();
foreach (object deserializedItem in deserializedList)
{
ItemType item = (ItemType)LanguagePrimitives.ConvertTo(deserializedItem, typeof(ItemType), CultureInfo.InvariantCulture);
TItem item = (TItem)LanguagePrimitives.ConvertTo(deserializedItem, typeof(TItem), CultureInfo.InvariantCulture);
newList.Add(item);
}

Expand Down
Loading
X Tutup