using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseTypes.Interfaces;
namespace BaseTypes.CSharp
{
public class CSTypeCreator : ITypeCreator
{
#region Fields
static private readonly Dictionary<Type, string> dictionary =
new Dictionary<Type, string>()
{
{ typeof(double), "double" },
{ typeof(bool), "bool" },
};
static private readonly Dictionary<string, string> defaultValue = new Dictionary<string, string>()
{
{"False", "false"},
{"True", "true"},
};
#endregion
#region ITypeCreator Members
public string GetType(object o)
{
if (o is ArrayReturnType)
{
ArrayReturnType t = o as ArrayReturnType;
string st = "object";
if (!t.IsObjectType)
{
st = GetType(t.ElementType);
}
st += "[";
int[] n = t.Dimension;
for (int i = 0; i < n.Length - 1; i++)
{
st += ',';
}
st += ']';
return st;
}
Type type = o.GetType();
if (dictionary.ContainsKey(type))
{
return dictionary[type];
}
return "object";
}
public string GetDefaultValue(object o)
{
if (o is ArrayReturnType)
{
ArrayReturnType t = o as ArrayReturnType;
string st = "object";
if (!t.IsObjectType)
{
st = GetType(t.ElementType);
}
st = "new " + st + "[";
int[] n = t.Dimension;
for (int i = 0; i < n.Length; i++)
{
st += n[i];
if (i < n.Length - 1)
{
st += ',';
}
}
st += ']';
return st;
}
string s = o + "";
if (defaultValue.ContainsKey(s))
{
return defaultValue[s];
}
return s;
}
#endregion
}
}