Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Last active December 8, 2016 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfbjarne/a4103ebac349f899803d6d84fb5b5593 to your computer and use it in GitHub Desktop.
Save rolfbjarne/a4103ebac349f899803d6d84fb5b5593 to your computer and use it in GitHub Desktop.
diff --git a/tools/mtouch/Target.cs b/tools/mtouch/Target.cs
index cf522ba..af75c72 100644
--- a/tools/mtouch/Target.cs
+++ b/tools/mtouch/Target.cs
@@ -377,34 +377,8 @@ namespace Xamarin.Bundler
GetCustomAttributeReferences (assembly, assemblies, exceptions);
GetCustomAttributeReferences (main, assemblies, exceptions);
if (main.HasTypes) {
- foreach (var t in main.Types) {
- GetTypeReferences (t, assemblies, exceptions);
- }
- }
- }
-
- void GetTypeReferences (TypeDefinition type, HashSet<string> assemblies, List<Exception> exceptions)
- {
- GetCustomAttributeReferences (type, assemblies, exceptions);
- if (type.HasEvents) {
- foreach (var e in type.Events)
- GetCustomAttributeReferences (e, assemblies, exceptions);
- }
- if (type.HasFields) {
- foreach (var f in type.Fields)
- GetCustomAttributeReferences (f, assemblies, exceptions);
- }
- if (type.HasMethods) {
- foreach (var m in type.Methods)
- GetCustomAttributeReferences (m, assemblies, exceptions);
- }
- if (type.HasProperties) {
- foreach (var p in type.Properties)
- GetCustomAttributeReferences (p, assemblies, exceptions);
- }
- if (type.HasNestedTypes) {
- foreach (var nt in type.NestedTypes)
- GetTypeReferences (nt, assemblies, exceptions);
+ foreach (var ca in main.GetCustomAttributes ())
+ GetCustomAttributeReferences (ca, assemblies, exceptions);
}
}
@@ -412,24 +386,29 @@ namespace Xamarin.Bundler
{
if (!cap.HasCustomAttributes)
return;
- foreach (var ca in cap.CustomAttributes) {
- if (ca.HasConstructorArguments) {
- foreach (var arg in ca.ConstructorArguments)
- GetCustomAttributeArgumentReference (arg, assemblies, exceptions);
- }
- if (ca.HasFields) {
- foreach (var arg in ca.Fields)
- GetCustomAttributeArgumentReference (arg.Argument, assemblies, exceptions);
- }
- if (ca.HasProperties) {
- foreach (var arg in ca.Properties)
- GetCustomAttributeArgumentReference (arg.Argument, assemblies, exceptions);
- }
+ foreach (var ca in cap.CustomAttributes)
+ GetCustomAttributeReferences (ca, assemblies, exceptions);
+ }
+
+ void GetCustomAttributeReferences (CustomAttribute ca, HashSet<string> assemblies, List<Exception> exceptions)
+ {
+ if (ca.HasConstructorArguments) {
+ foreach (var arg in ca.ConstructorArguments)
+ GetCustomAttributeArgumentReference (arg, assemblies, exceptions);
+ }
+ if (ca.HasFields) {
+ foreach (var arg in ca.Fields)
+ GetCustomAttributeArgumentReference (arg.Argument, assemblies, exceptions);
+ }
+ if (ca.HasProperties) {
+ foreach (var arg in ca.Properties)
+ GetCustomAttributeArgumentReference (arg.Argument, assemblies, exceptions);
}
}
void GetCustomAttributeArgumentReference (CustomAttributeArgument arg, HashSet<string> assemblies, List<Exception> exceptions)
{
+ // FIXME: this doesn't handle arrays of Types.
if (!arg.Type.Is ("System", "Type"))
return;
var ar = (arg.Value as TypeReference)?.Scope as AssemblyNameReference;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment