using System;
using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Microsoft.Build.Framework;
namespace Microsoft.Build.BuildEngine {
internal class ChangeType {
-
- private static string TemporaryTransform (object o, Type type)
+ //removed Type type
+ // FIXME throw exception here
+ static string ToString (object o)
{
- string output = String.Empty;
- if (type == typeof (bool)) {
- bool t = (bool) o;
- output = t.ToString ();
- } else if (type == typeof (string)) {
- string t = (string) o;
- output = t.ToString ();
- } else if (type == typeof (DateTime)) {
- DateTime t = (DateTime) o;
- output = t.ToString ();
- } else if (type == typeof (int)) {
- int t = (int) o;
- output = t.ToString ();
- } else if (type == typeof (uint)) {
- uint t = (uint) o;
- output = t.ToString ();
- } else {
- }
+ string output = null;
+ Type type = o.GetType ();
+
+ // FIXME: there are more types
+ if (type == typeof (string))
+ output = (string) o;
+ else if (type == typeof (bool) ||
+ type == typeof (int) ||
+ type == typeof (uint) ||
+ type == typeof (float) ||
+ type == typeof (double) ||
+ type == typeof (DateTime) ||
+ type.IsEnum)
+ output = o.ToString ();
+ else
+ throw new Exception (String.Format ("Unsupported type : {0}", type));
return output;
}
-
- public static string TransformToString (object o, Type type)
- {
- return TemporaryTransform (o, type);
- }
-
- public static string TransformToString (object[] o, Type type)
+
+ static string ToString (object [] o, Type type)
{
+ /*
ArrayList al = new ArrayList ();
foreach (object obj in o ) {
if (type == typeof (bool[])) {
foreach (string s in al)
output [i++] = s;
return String.Join (";", output);
+ */
+
+ List <string> list = new List <string> ();
+ foreach (object obj in o)
+ list.Add (ToString (obj));
+ return String.Join (";", list.ToArray ());
}
-
- public static BuildProperty TransformToBuildProperty (string name, string items)
- {
- return new BuildProperty (name, items);
- }
-
- public static BuildProperty TransformToBuildProperty (string name, ITaskItem[] items)
- {
- BuildProperty buildProperty;
- buildProperty = new BuildProperty (name, TransformToString (items));
- return buildProperty;
- }
-
- public static BuildProperty TransformToBuildProperty (string name, ITaskItem item)
- {
- BuildProperty buildProperty;
- buildProperty = new BuildProperty (name, TransformToString (item));
- return buildProperty;
- }
-
- public static BuildItemGroup TransformToBuildItemGroup (string name, string items)
+
+ public static BuildProperty ToBuildProperty (object o, Type t, string name)
{
- string[] splittedItems = items.Split (';');
- BuildItemGroup big = new BuildItemGroup ();
- foreach (string item in splittedItems)
- big.AddItem (name, new TaskItem (item));
- return big;
+ if (t == typeof (ITaskItem)) {
+ return new BuildProperty (name, ((ITaskItem) o).ItemSpec);
+ } else if (t == typeof (ITaskItem [])) {
+ // FIXME move Tostring here
+ return new BuildProperty (name, ToString ((ITaskItem []) o));
+ } else if (t.IsArray) {
+ return new BuildProperty (name, ToString ((object []) o, t));
+ } else {
+ return new BuildProperty (name, ToString (o));
+ }
}
-
- public static BuildItemGroup TransformToBuildItemGroup (string name, ITaskItem[] items)
+
+ public static BuildItemGroup ToBuildItemGroup (object o, Type t, string name)
{
BuildItemGroup big = new BuildItemGroup ();
- foreach (ITaskItem item in items) {
- big.AddItem (name, item);
+
+ if (t == typeof (ITaskItem)) {
+ big.AddItem (name, (ITaskItem) o);
+ } else if (t == typeof (ITaskItem [])) {
+ foreach (ITaskItem i in (ITaskItem []) o)
+ big.AddItem (name, i);
+ } else if (t.IsArray) {
+ return ToBuildItemGroup (name, ToString ((object []) o, t), true);
+ } else {
+ return ToBuildItemGroup (name, ToString (o), false);
}
+
return big;
}
- public static BuildItemGroup TransformToBuildItemGroup (string name, ITaskItem item)
+ static BuildItemGroup ToBuildItemGroup (string name, string items, bool split)
{
BuildItemGroup big = new BuildItemGroup ();
- big.AddItem (name, item);
+ if (split) {
+ string [] splitItems = items.Split (';');
+ foreach (string item in splitItems)
+ big.AddItem (name, new TaskItem (item));
+ } else {
+ big.AddItem (name, new TaskItem (items));
+ }
+
return big;
}
- private static string TransformToString (ITaskItem[] items)
+ static string ToString (ITaskItem [] items)
{
- string[] text = new string [items.Length];
+ string [] text = new string [items.Length];
int i = 0;
foreach (ITaskItem item in items)
text [i++] = item.ItemSpec;
return String.Join (";", text);
}
-
- private static string TransformToString (ITaskItem item)
- {
- return item.ItemSpec;
- }
}
}