[longomatch] Make sure to overwrite the template name
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Make sure to overwrite the template name
- Date: Fri, 17 Apr 2015 16:27:27 +0000 (UTC)
commit 6ad9b164a645788bed088621d30a087c76db728d
Author: Jorge Zapata <jorgeluis zapata gmail com>
Date: Wed Apr 15 16:40:42 2015 +0200
Make sure to overwrite the template name
This solves the problems about files having the same template
name as other templates but using different files. This is
transitional until we finally move to the IStorage interface
LongoMatch.Services/FileStorage.cs | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Services/FileStorage.cs b/LongoMatch.Services/FileStorage.cs
index 2307c62..fc63082 100644
--- a/LongoMatch.Services/FileStorage.cs
+++ b/LongoMatch.Services/FileStorage.cs
@@ -157,6 +157,15 @@ namespace LongoMatch.Services.Services
foreach (string path in Directory.GetFiles (typePath, "*" + extension)) {
T t = (T)Serializer.LoadSafe<T> (path);
Log.Information ("Retrieving " + path);
+
+ FieldInfo finfo = t.GetType ().GetField ("Name");
+ PropertyInfo pinfo = t.GetType ().GetProperty ("Name");
+
+ if (pinfo != null)
+ pinfo.SetValue (t, Path.GetFileNameWithoutExtension (path));
+ else
+ finfo.SetValue (t, Path.GetFileNameWithoutExtension (path));
+
l.Add (t);
}
return l;
@@ -178,6 +187,16 @@ namespace LongoMatch.Services.Services
if (File.Exists (path)) {
T t = Serializer.LoadSafe<T> (path);
Log.Information ("Retrieving by filename " + path);
+ // To avoid cases where the name of the file does not match the name
of the template
+ // overwrite the template name
+ FieldInfo finfo = t.GetType ().GetField ("Name");
+ PropertyInfo pinfo = t.GetType ().GetProperty ("Name");
+
+ if (pinfo != null)
+ pinfo.SetValue (t, dict["Name"]);
+ else
+ finfo.SetValue (t, dict["Name"]);
+
l.Add (t);
return l;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]