-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix dynamic class assembly name #5292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Using the assembly name to hint at the source of the classes was
problematic in multiple ways.
This change stores the actual filename in an attribute on the assembly.
So for a given type, one can get the assembly this way:
[SomeType].Assembly.GetCustomAttributes() |
? { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute] } |
% { $_.ScriptFile }
6a668b3 to
7ca8ac8
Compare
| typeof(DynamicClassImplementationAssemblyAttribute).GetProperty(nameof(DynamicClassImplementationAssemblyAttribute.ScriptFile)) }; | ||
| var propertyArgs = new object[] { scriptFile }; | ||
| var fieldInfoList = Utils.EmptyArray<FieldInfo>(); | ||
| var fieldArgs = Utils.EmptyArray<object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fieldInfoList and fieldArgs are not used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, cut and paste I guess.
| { | ||
| yield return new CustomAttributeBuilder(typeof(DynamicClassImplementationAssemblyAttribute).GetConstructor(Type.EmptyTypes), s_emptyArgArray); | ||
| var ctor = typeof(DynamicClassImplementationAssemblyAttribute).GetConstructor(Type.EmptyTypes); | ||
| var emptyArgs = Utils.EmptyArray<object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You call Utils.EmptyArray<object>() multiple times, why not just use s_emptyArgArray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove s_emptyArgArray - it's probably not better to store 2 references to the same array, Utils.EmptyArray already has a static reference.
|
|
||
| $a = [C].Assembly.GetCustomAttributes($false).Where{ | ||
| $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute]} | ||
| $a.ScriptFile | Should BeExactly (& { $MyInvocation.ScriptName }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace (& { $MyInvocation.ScriptName }) with $PSCommandPath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, sure. My excuse - I've never used it before and was too lazy to look for it. :)
|
This is great, but the usage seems too complex to remember. Can we use ETS to just add a ScriptFile property making it more discoverable? |
|
@SteveL-MSFT - I've only seen 1 request for this ability - from the author of ISESteroids - so ease of use doesn't seem too critical. I suppose we could use a |
|
@lzybkr we can wait for customer request before adding more. Thanks |
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment
Using the assembly name to hint at the source of the classes was
problematic in multiple ways.
This change stores the actual filename in an attribute on the assembly.
So for a given type, one can get the assembly this way:
[SomeType].Assembly.GetCustomAttributes() |
? { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute] } |
% { $_.ScriptFile }