Cleanup style issues in CoreAdapter and MshObject (#9190)

This commit is contained in:
Ilya 2019-03-23 09:52:30 +05:00 committed by GitHub
parent a47c1b3113
commit cc6540b614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 155 additions and 71 deletions

View File

@ -354,14 +354,16 @@ namespace System.Management.Automation
{
Exception inner = ex.InnerException ?? ex;
newParameters[0] = inner.Message;
return new ExtendedTypeSystemException(targetErrorId,
return new ExtendedTypeSystemException(
targetErrorId,
inner,
resourceString,
newParameters);
}
newParameters[0] = e.Message;
return new ExtendedTypeSystemException(errorId,
return new ExtendedTypeSystemException(
errorId,
e,
resourceString,
newParameters);
@ -380,8 +382,11 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetTypeNameHierarchy", "CatchFromBaseGetTypeNameHierarchyTI",
ExtendedTypeSystem.ExceptionRetrievingTypeNameHierarchy);
throw NewException(
e,
"CatchFromBaseGetTypeNameHierarchy",
"CatchFromBaseGetTypeNameHierarchyTI",
ExtendedTypeSystem.ExceptionRetrievingTypeNameHierarchy);
}
}
@ -394,8 +399,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMember", "CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember, memberName);
throw NewException(
e,
"CatchFromBaseGetMember",
"CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember,
memberName);
}
}
@ -408,8 +417,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMember", "CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember, nameof(predicate));
throw NewException(
e,
"CatchFromBaseGetMember",
"CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember,
nameof(predicate));
}
}
@ -422,7 +435,10 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMembers", "CatchFromBaseGetMembersTI",
throw NewException(
e,
"CatchFromBaseGetMembers",
"CatchFromBaseGetMembersTI",
ExtendedTypeSystem.ExceptionGettingMembers);
}
}
@ -440,7 +456,8 @@ namespace System.Management.Automation
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new GetValueInvocationException("CatchFromBaseAdapterGetValueTI",
throw new GetValueInvocationException(
"CatchFromBaseAdapterGetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, inner.Message);
@ -448,7 +465,8 @@ namespace System.Management.Automation
catch (GetValueException) { throw; }
catch (Exception e)
{
throw new GetValueInvocationException("CatchFromBaseAdapterGetValue",
throw new GetValueInvocationException(
"CatchFromBaseAdapterGetValue",
e,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, e.Message);
@ -464,7 +482,8 @@ namespace System.Management.Automation
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new SetValueInvocationException("CatchFromBaseAdapterSetValueTI",
throw new SetValueInvocationException(
"CatchFromBaseAdapterSetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, inner.Message);
@ -472,7 +491,8 @@ namespace System.Management.Automation
catch (SetValueException) { throw; }
catch (Exception e)
{
throw new SetValueInvocationException("CatchFromBaseAdapterSetValue",
throw new SetValueInvocationException(
"CatchFromBaseAdapterSetValue",
e,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, e.Message);
@ -488,8 +508,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyIsSettable", "CatchFromBasePropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyWriteState, property.Name);
throw NewException(
e,
"CatchFromBasePropertyIsSettable",
"CatchFromBasePropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyWriteState,
property.Name);
}
}
@ -502,8 +526,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyIsGettable", "CatchFromBasePropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyReadState, property.Name);
throw NewException(
e,
"CatchFromBasePropertyIsGettable",
"CatchFromBasePropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyReadState,
property.Name);
}
}
@ -516,8 +544,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyType", "CatchFromBasePropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyType, property.Name);
throw NewException(
e,
"CatchFromBasePropertyType",
"CatchFromBasePropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyType,
property.Name);
}
}
@ -530,8 +562,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyToString", "CatchFromBasePropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyString, property.Name);
throw NewException(
e,
"CatchFromBasePropertyToString",
"CatchFromBasePropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyString,
property.Name);
}
}
@ -544,8 +580,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyAttributes", "CatchFromBasePropertyAttributesTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyAttributes, property.Name);
throw NewException(
e,
"CatchFromBasePropertyAttributes",
"CatchFromBasePropertyAttributesTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyAttributes,
property.Name);
}
}
@ -561,10 +601,13 @@ namespace System.Management.Automation
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new MethodInvocationException("CatchFromBaseAdapterMethodInvokeTI",
throw new MethodInvocationException(
"CatchFromBaseAdapterMethodInvokeTI",
inner,
ExtendedTypeSystem.MethodInvocationException,
method.Name, arguments.Length, inner.Message);
method.Name,
arguments.Length,
inner.Message);
}
catch (FlowControlException) { throw; }
catch (ScriptCallDepthException) { throw; }
@ -580,10 +623,13 @@ namespace System.Management.Automation
throw;
}
throw new MethodInvocationException("CatchFromBaseAdapterMethodInvoke",
throw new MethodInvocationException(
"CatchFromBaseAdapterMethodInvoke",
e,
ExtendedTypeSystem.MethodInvocationException,
method.Name, arguments.Length, e.Message);
method.Name,
arguments.Length,
e.Message);
}
}
@ -596,8 +642,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseMethodDefinitions", "CatchFromBaseMethodDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingMethodDefinitions, method.Name);
throw NewException(
e,
"CatchFromBaseMethodDefinitions",
"CatchFromBaseMethodDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingMethodDefinitions,
method.Name);
}
}
@ -610,8 +660,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseMethodToString", "CatchFromBaseMethodToStringTI",
ExtendedTypeSystem.ExceptionRetrievingMethodString, method.Name);
throw NewException(
e,
"CatchFromBaseMethodToString",
"CatchFromBaseMethodToStringTI",
ExtendedTypeSystem.ExceptionRetrievingMethodString,
method.Name);
}
}
#endregion method
@ -626,8 +680,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyType", "CatchFromBaseParameterizedPropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertytype, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyType",
"CatchFromBaseParameterizedPropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertytype,
property.Name);
}
}
@ -640,8 +698,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyIsSettable", "CatchFromBaseParameterizedPropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyWriteState, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyIsSettable",
"CatchFromBaseParameterizedPropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyWriteState,
property.Name);
}
}
@ -654,8 +716,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyIsGettable", "CatchFromBaseParameterizedPropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyReadState, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyIsGettable",
"CatchFromBaseParameterizedPropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyReadState,
property.Name);
}
}
@ -668,8 +734,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyDefinitions", "CatchFromBaseParameterizedPropertyDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyDefinitions, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyDefinitions",
"CatchFromBaseParameterizedPropertyDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyDefinitions,
property.Name);
}
}
@ -682,18 +752,22 @@ namespace System.Management.Automation
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new GetValueInvocationException("CatchFromBaseAdapterParameterizedPropertyGetValueTI",
throw new GetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertyGetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, inner.Message);
property.Name,
inner.Message);
}
catch (GetValueException) { throw; }
catch (Exception e)
{
throw new GetValueInvocationException("CatchFromBaseParameterizedPropertyAdapterGetValue",
throw new GetValueInvocationException(
"CatchFromBaseParameterizedPropertyAdapterGetValue",
e,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, e.Message);
property.Name,
e.Message);
}
}
@ -706,18 +780,22 @@ namespace System.Management.Automation
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new SetValueInvocationException("CatchFromBaseAdapterParameterizedPropertySetValueTI",
throw new SetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertySetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, inner.Message);
property.Name,
inner.Message);
}
catch (SetValueException) { throw; }
catch (Exception e)
{
throw new SetValueInvocationException("CatchFromBaseAdapterParameterizedPropertySetValue",
throw new SetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertySetValue",
e,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, e.Message);
property.Name,
e.Message);
}
}
@ -730,8 +808,12 @@ namespace System.Management.Automation
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyToString", "CatchFromBaseParameterizedPropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyString, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyToString",
"CatchFromBaseParameterizedPropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyString,
property.Name);
}
}

View File

@ -2496,7 +2496,9 @@ namespace Microsoft.PowerShell
internal static string Type(Type type, bool dropNamespaces = false, string key = null)
{
if (type == null)
{
return string.Empty;
}
string result;
if (type.IsGenericType && !type.IsGenericTypeDefinition)

View File

@ -19,16 +19,16 @@ namespace PSTests.Parallel
[Fact]
public static void TestEmptyObjectHasNoProperty()
{
var psObject = new PSObject();
var actual = psObject.GetFirstPropertyOrDefault(name => true);
var pso = new PSObject();
var actual = pso.GetFirstPropertyOrDefault(name => true);
Assert.Null(actual);
}
[Fact]
public static void TestWrappedDateTimeHasReflectedMember()
{
var psObject = new PSObject(DateTime.Now);
var member = psObject.GetFirstPropertyOrDefault(name => name == "DayOfWeek");
var pso = new PSObject(DateTime.Now);
var member = pso.GetFirstPropertyOrDefault(name => name == "DayOfWeek");
Assert.NotNull(member);
Assert.Equal("DayOfWeek", member.Name);
}
@ -36,9 +36,9 @@ namespace PSTests.Parallel
[Fact]
public static void TestAdaptedMember()
{
var psObject = new PSObject(DateTime.Now);
psObject.Members.Add(new PSNoteProperty("NewMember", "AValue"));
var member = psObject.GetFirstPropertyOrDefault(name => name == "NewMember");
var pso = new PSObject(DateTime.Now);
pso.Members.Add(new PSNoteProperty("NewMember", "AValue"));
var member = pso.GetFirstPropertyOrDefault(name => name == "NewMember");
Assert.NotNull(member);
Assert.Equal("NewMember", member.Name);
}
@ -46,9 +46,9 @@ namespace PSTests.Parallel
[Fact]
public static void TestShadowedMember()
{
var psObject = new PSObject(DateTime.Now);
psObject.Members.Add(new PSNoteProperty("DayOfWeek", "AValue"));
var member = psObject.GetFirstPropertyOrDefault(name => name == "DayOfWeek");
var pso = new PSObject(DateTime.Now);
pso.Members.Add(new PSNoteProperty("DayOfWeek", "AValue"));
var member = pso.GetFirstPropertyOrDefault(name => name == "DayOfWeek");
Assert.NotNull(member);
Assert.Equal("DayOfWeek", member.Name);
Assert.Equal("AValue", member.Value);
@ -57,24 +57,24 @@ namespace PSTests.Parallel
[Fact]
public static void TestMemberSetIsNotProperty()
{
var psObject = new PSObject(DateTime.Now);
var pso = new PSObject(DateTime.Now);
var psNoteProperty = new PSNoteProperty("NewMember", "AValue");
psObject.Members.Add(psNoteProperty);
psObject.Members.Add(new PSMemberSet("NewMemberSet", new[] { psNoteProperty }));
pso.Members.Add(psNoteProperty);
pso.Members.Add(new PSMemberSet("NewMemberSet", new[] { psNoteProperty }));
var member = psObject.GetFirstPropertyOrDefault(name => name == "NewMemberSet");
var member = pso.GetFirstPropertyOrDefault(name => name == "NewMemberSet");
Assert.Null(member);
}
[Fact]
public static void TestMemberSet()
{
var psObject = new PSObject(DateTime.Now);
var pso = new PSObject(DateTime.Now);
var psNoteProperty = new PSNoteProperty("NewMember", "AValue");
psObject.Members.Add(psNoteProperty);
psObject.Members.Add(new PSMemberSet("NewMemberSet", new[] { psNoteProperty }));
pso.Members.Add(psNoteProperty);
pso.Members.Add(new PSMemberSet("NewMemberSet", new[] { psNoteProperty }));
var member = psObject.Members.FirstOrDefault(name => name == "NewMemberSet");
var member = pso.Members.FirstOrDefault(name => name == "NewMemberSet");
Assert.NotNull(member);
Assert.Equal("NewMemberSet", member.Name);
}
@ -89,8 +89,8 @@ namespace PSTests.Parallel
root.AppendChild(firstChild);
root.InsertAfter(doc.CreateElement("elem2"), firstChild);
var psObject = new PSObject(root);
var member = psObject.GetFirstPropertyOrDefault(name => name.StartsWith("elem"));
var pso = new PSObject(root);
var member = pso.GetFirstPropertyOrDefault(name => name.StartsWith("elem"));
Assert.Equal("elem1", member.Name);
}
@ -103,8 +103,8 @@ namespace PSTests.Parallel
root.SetAttribute("attr", "value");
root.AppendChild(doc.CreateElement("elem"));
var psObject = new PSObject(root);
var member = psObject.GetFirstPropertyOrDefault(name => name.StartsWith("attr"));
var pso = new PSObject(root);
var member = pso.GetFirstPropertyOrDefault(name => name.StartsWith("attr"));
Assert.Equal("attr", member.Name);
}