Skip to content

Conversation

@brendanzagaeski
Copy link
Contributor

Context: dotnet/android#2349

This commit introduces a new extension method GetAssemblyName() that
provides the assembly name portion of
GetPartialAssemblyQualifiedName() so that GenerateJavaStubs doesn't
have to do any string splitting to get the assembly name for warning
XA4214.

@brendanzagaeski
Copy link
Contributor Author

Cross-referencing note for the team

The pattern of calling Resolve() before getting the Module property dates back to non-public commit https://github.com/xamarin/monodroid/commit/632be1237663473fa37efcc9f0f0010621b9f2fd. If I understand correctly, the Module property on TypeReference returns the module where the field holding the TypeReference was defined rather than the module where the type itself was defined. Calling Resolve() on the TypeReference finds the TypeDefinition, and the Module property on that result then provides the correct module.

(def ?? type).Module.Assembly.Name.FullName);
}

public static string GetAssemblyName (this TypeReference type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per previous discussion, this should be named GetPartialAssemblyName(), to "mirror" GetPartialAssemblyQualifiedName() -- unless we can find a better/more conventional name -- and we should refactor ~all instances of .Module.Assembly.Name.Name within this repo to use GetPartialAssemblyName().

Context: dotnet/android#2349

This commit introduces a new extension method `GetPartialAssemblyName()`
that provides just the assembly name portion of
`GetPartialAssemblyQualifiedName()` so that `GenerateJavaStubs` doesn't
need to do any string splitting to get the assembly name for warning
XA4214.  It also makes a small replacement in `JavaNativeTypeManager` to
take advantage of the new extension method for readability.

This new extension method returns a partial assembly name that is
specifically just the *first* part of a fully qualified assembly name.
The documentation for [System.Reflection.AssemblyName][0] and
[`Type.GetType()`][1] refers to this first part as the *simple name* of
the assembly.

Another detail about terminology that might be useful to mention is that
a type name with no qualifiers is called the *simple name* of the type,
while a type name qualified with either a partial or full assembly name
is called *fully qualified*.  So for example, the
`GetPartialAssemblyQualifiedName()` extension method returns a fully
qualified type name, even though it is only qualified with a partial
assembly name.

[0]: https://docs.microsoft.com/dotnet/api/system.reflection.assemblyname?view=netframework-4.7.2#remarks
[1]: https://docs.microsoft.com/dotnet/api/system.type.gettype?view=netframework-4.7.2#remarks
@jonpryor jonpryor merged commit b72ee7a into dotnet:master Nov 8, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants