Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Resource Manager fix for F# File Resources (Bugzilla 53515) (#825)
Browse files Browse the repository at this point in the history
* Resource Manager fix for F# File Resources (Bugzilla 53515)

* Changed spaces to tabs and changed the argument name in the ResourceManager.GetId() function.

* Improved the type checking in GetId().
  • Loading branch information
SpiegelSoft authored and rmarinho committed Apr 12, 2017
1 parent dfda41b commit b9a94f4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Xamarin.Forms.Platform.Android/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ public static int GetResourceByName(string name)

public static void Init(Assembly masterAssembly)
{
DrawableClass = masterAssembly.GetTypes().FirstOrDefault(x => x.Name == "Drawable");
ResourceClass = masterAssembly.GetTypes().FirstOrDefault(x => x.Name == "Id");
DrawableClass = masterAssembly.GetTypes().FirstOrDefault(x => x.Name == "Drawable" || x.Name == "Resource_Drawable");
ResourceClass = masterAssembly.GetTypes().FirstOrDefault(x => x.Name == "Id" || x.Name == "Resource_Id");
}

internal static int IdFromTitle(string title, Type type)
{
string name = Path.GetFileNameWithoutExtension(title);
int id = GetId(type, name);
return id; // Resources.System.GetDrawable (Resource.Drawable.dashboard);
return id;
}

static int GetId(Type type, string propertyName)
static int GetId(Type type, string memberName)
{
FieldInfo[] props = type.GetFields();
FieldInfo prop = props.Select(p => p).FirstOrDefault(p => p.Name == propertyName);
if (prop != null)
return (int)prop.GetValue(type);
object value = type.GetFields().FirstOrDefault(p => p.Name == memberName)?.GetValue(type)
?? type.GetProperties().FirstOrDefault(p => p.Name == memberName)?.GetValue(type);
if (value is int)
return (int)value;
return 0;
}
}
Expand Down

0 comments on commit b9a94f4

Please sign in to comment.