Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace MonoDroid.Tuner
public class FixLegacyResourceDesignerStep : LinkDesignerBase
{
internal const string DesignerAssemblyName = "_Microsoft.Android.Resource.Designer";
internal const string DesignerAssemblyNamespace = "Microsoft.Android.Resource.Designer";
internal const string DesignerAssemblyNamespace = "_Microsoft.Android.Resource.Designer";

bool designerLoaded = false;
AssemblyDefinition designerAssembly = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,25 @@ bool Run(DirectoryAssemblyResolver res)
} else {
// Add the InternalsVisibleToAttribute so the app can access ResourceConstant
if (!string.IsNullOrEmpty (AssemblyName)) {
MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule);
MethodReference internalsVisibleToAttributeConstructor = ImportCustomAttributeConstructor ("System.Runtime.CompilerServices.InternalsVisibleToAttribute", module, netstandardDef.MainModule, argCount: 1);
var ar = new CustomAttribute (internalsVisibleToAttributeConstructor);
ar.ConstructorArguments.Add (new CustomAttributeArgument (module.TypeSystem.String, AssemblyName));
module.Assembly.CustomAttributes.Add (ar);
}
}

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

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

MethodReference editorBrowserConstructor = ImportCustomAttributeConstructor ("System.ComponentModel.EditorBrowsableAttribute", module, netstandardDef.MainModule, argCount: 1);
TypeReference e = ImportType ("System.ComponentModel.EditorBrowsableState", module, netstandardDef.MainModule);
var editorBrowserAttr = new CustomAttribute (editorBrowserConstructor);
editorBrowserAttr.ConstructorArguments.Add (new CustomAttributeArgument (e, System.ComponentModel.EditorBrowsableState.Never));

var att = TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.Public | TypeAttributes.BeforeFieldInit;

intArray = new ArrayType (module.TypeSystem.Int32);
Expand All @@ -131,6 +136,7 @@ bool Run(DirectoryAssemblyResolver res)
objectRef
);
CreateCtor (resourceDesigner, module);
resourceDesigner.CustomAttributes.Add (editorBrowserAttr);
module.Types.Add (resourceDesigner);
TypeDefinition constDesigner = null;
if (IsApplication) {
Expand All @@ -143,6 +149,7 @@ bool Run(DirectoryAssemblyResolver res)
objectRef
);
CreateCtor (constDesigner, module);
constDesigner.CustomAttributes.Add (editorBrowserAttr);
module.Types.Add (constDesigner);
}

Expand Down Expand Up @@ -196,11 +203,16 @@ bool Run(DirectoryAssemblyResolver res)
return !Log.HasLoggedErrors;
}

MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
MethodReference ImportCustomAttributeConstructor (string type, ModuleDefinition module, ModuleDefinition sourceModule = null, int argCount = 0)
{
var tr = module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
var tv = tr.Resolve();
return module.ImportReference (tv.Methods.First(x => x.IsConstructor));
return module.ImportReference (tv.Methods.First(x => x.IsConstructor && (x.Parameters?.Count ?? 0) == argCount));
}

TypeReference ImportType (string type, ModuleDefinition module, ModuleDefinition sourceModule = null)
{
return module.ImportReference ((sourceModule ?? module).ExportedTypes.First(x => x.FullName == type).Resolve ());
}

void CreateIntProperty (string resourceClass, string propertyName, int value, TypeDefinition resourceDesigner, ModuleDefinition module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@ public class GenerateResourceDesignerIntermediateClass : AndroidTask
private const string ResourceDesigner = $"{FixLegacyResourceDesignerStep.DesignerAssemblyNamespace}.Resource";
private const string ResourceDesignerConstants = $"{FixLegacyResourceDesignerStep.DesignerAssemblyNamespace}.ResourceConstant";

private const string CSharpTemplate = @"// This is an Auto Generated file DO NOT EDIT
private const string CSharpTemplate = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. DO NOT EDIT
// </auto-generated>
//------------------------------------------------------------------------------
using System;

namespace %NAMESPACE% {
#pragma warning disable IDE0002
public partial class Resource : %BASECLASS% {
}
#pragma warning restore IDE0002
}
";
private const string FSharpTemplate = @"// This is an Auto Generated file DO NOT EDIT
private const string FSharpTemplate = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. DO NOT EDIT
// </auto-generated>
//------------------------------------------------------------------------------
namespace %NAMESPACE%

type Resource = %BASECLASS%
Expand Down