Skip to content

Commit

Permalink
More compact implementation of Marshal.GenerateProgIdForType (dotnet#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Feb 4, 2019
1 parent 7253eab commit 9aa68da
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -847,21 +847,10 @@ public static string GenerateProgIdForType(Type type)
throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type));
}

foreach (CustomAttributeData cad in type.GetCustomAttributesData())
ProgIdAttribute progIdAttribute = type.GetCustomAttribute<ProgIdAttribute>();
if (progIdAttribute != null)
{
if (cad.Constructor.DeclaringType == typeof(ProgIdAttribute))
{
// Retrieve the PROGID string from the ProgIdAttribute.
IList<CustomAttributeTypedArgument> caConstructorArgs = cad.ConstructorArguments;
Debug.Assert(caConstructorArgs.Count == 1, "caConstructorArgs.Count == 1");

CustomAttributeTypedArgument progIdConstructorArg = caConstructorArgs[0];
Debug.Assert(progIdConstructorArg.ArgumentType == typeof(string), "progIdConstructorArg.ArgumentType == typeof(string)");

string strProgId = (string)progIdConstructorArg.Value;

return strProgId ?? string.Empty;
}
return progIdAttribute.Value ?? string.Empty;
}

// If there is no prog ID attribute then use the full name of the type as the prog id.
Expand Down

0 comments on commit 9aa68da

Please sign in to comment.