Skip to content

Commit 8c4c56b

Browse files
committed
Add System.ComponentModel.EditorBrowsableAttribute
1 parent 6df459f commit 8c4c56b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,25 @@ bool Run(DirectoryAssemblyResolver res)
103103
} else {
104104
// Add the InternalsVisibleToAttribute so the app can access ResourceConstant
105105
if (!string.IsNullOrEmpty (AssemblyName)) {
106-
MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule);
106+
MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule, argCount: 1);
107107
var ar = new CustomAttribute (internalsVisibleToAttributeConstructor);
108108
ar.ConstructorArguments.Add (new CustomAttributeArgument (module.TypeSystem.String, AssemblyName));
109109
module.Assembly.CustomAttributes.Add (ar);
110110
}
111111
}
112112

113-
MethodReference targetFrameworkConstructor = ImportCustomAttributeConstructor ("System.Runtime.Versioning.TargetFrameworkAttribute", module, netstandardDef.MainModule);
113+
MethodReference targetFrameworkConstructor = ImportCustomAttributeConstructor ("System.Runtime.Versioning.TargetFrameworkAttribute", module, netstandardDef.MainModule, argCount: 1);
114114

115115
var attr = new CustomAttribute (targetFrameworkConstructor);
116116
attr.ConstructorArguments.Add (new CustomAttributeArgument (module.TypeSystem.String, $".NETStandard,Version=v2.1"));
117117
attr.Properties.Add (new CustomAttributeNamedArgument ("FrameworkDisplayName", new CustomAttributeArgument (module.TypeSystem.String, "")));
118118
module.Assembly.CustomAttributes.Add (attr);
119119

120+
MethodReference editorBrowserConstructor = ImportCustomAttributeConstructor ("System.ComponentModel.EditorBrowsableAttribute", module, netstandardDef.MainModule, argCount: 1);
121+
TypeReference e = ImportType ("System.ComponentModel.EditorBrowsableState", module, netstandardDef.MainModule);
122+
var editorBrowserAttr = new CustomAttribute (editorBrowserConstructor);
123+
editorBrowserAttr.ConstructorArguments.Add (new CustomAttributeArgument (e, System.ComponentModel.EditorBrowsableState.Never));
124+
120125
var att = TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
121126

122127
intArray = new ArrayType (module.TypeSystem.Int32);
@@ -131,6 +136,7 @@ bool Run(DirectoryAssemblyResolver res)
131136
objectRef
132137
);
133138
CreateCtor (resourceDesigner, module);
139+
resourceDesigner.CustomAttributes.Add (editorBrowserAttr);
134140
module.Types.Add (resourceDesigner);
135141
TypeDefinition constDesigner = null;
136142
if (IsApplication) {
@@ -143,6 +149,7 @@ bool Run(DirectoryAssemblyResolver res)
143149
objectRef
144150
);
145151
CreateCtor (constDesigner, module);
152+
constDesigner.CustomAttributes.Add (editorBrowserAttr);
146153
module.Types.Add (constDesigner);
147154
}
148155

@@ -196,11 +203,16 @@ bool Run(DirectoryAssemblyResolver res)
196203
return !Log.HasLoggedErrors;
197204
}
198205

199-
MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
206+
MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null, int argCount = 0)
200207
{
201208
var tr = module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
202209
var tv = tr.Resolve();
203-
return module.ImportReference (tv.Methods.First(x => x.IsConstructor));
210+
return module.ImportReference (tv.Methods.First(x => x.IsConstructor && (x.Parameters?.Count ?? 0) == argCount));
211+
}
212+
213+
TypeReference ImportType (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
214+
{
215+
return module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
204216
}
205217

206218
void CreateIntProperty (string resourceClass, string propertyName, int value, TypeDefinition resourceDesigner, ModuleDefinition module,

0 commit comments

Comments
 (0)