/// <summary> /// Primitive Type of member or Collection of primitive types . /// </summary> /// <param name="tmember"></param> /// <param name="jsValue"></param> /// <returns></returns> public bool GetPrimitiveEmptyValue(Type tmember, out string jsValue) { jsValue = ""; if (tmember == typeof(string)) { jsValue = GetScriptTypeInfo.TString; } else if (TypeHelper.IsNumber(tmember) || TypeHelper.IsEnum(tmember)) { jsValue = GetScriptTypeInfo.TNumber; } else if (TypeHelper.IsDateTime(tmember)) { jsValue = GetScriptTypeInfo.TDatetime; } else if (TypeHelper.IsBoolean(tmember)) { jsValue = GetScriptTypeInfo.TBoolean; } else if (TypeHelper.IsCollection(tmember)) { //-- member is collection Type telement; if (TypeHelper.GetElementTypeOfCollection(tmember, out telement)) { if (this.GetPrimitiveEmptyValue(telement, out jsValue) == false) { jsValue = ""; } else { jsValue = GetScriptTypeInfo.TArrayFactoryFunctionDefinitionCall(jsValue); } } else { jsValue = GetScriptTypeInfo.TArray; } } return(string.IsNullOrWhiteSpace(jsValue) == false); }
/// <summary> /// To Dictionnary /// </summary> /// <param name="t"></param> /// <returns></returns> private static Dictionary <string, int> ToDictionnary(Type t) { if (TypeHelper.IsEnum(t) == false) { throw new ArgumentException("It is not 'Enum'"); } Type tenum = TypeHelper.GetUnderlyingTypeOrDefault(t); string[] names = Enum.GetNames(tenum); Dictionary <string, int> dic = new System.Collections.Generic.Dictionary <string, int>(names.Length); foreach (string n in names) { int value = Convert.ToInt32((Enum.Parse(tenum, n))); dic.Add(n, value); } return(dic); }
/// <summary> /// Primitive Type of member or Collection of primitive types . /// </summary> /// <param name="tmember"></param> /// <returns></returns> static public EnumType GetCategoryType(Type tmember) { EnumType result = EnumType.tcomplex; if (tmember == typeof(string)) { result = EnumType.tstring; } else if (TypeHelper.IsNumber(tmember)) { result = EnumType.tnumber; } else if (TypeHelper.IsEnum(tmember)) { result = EnumType.tenum; } else if (TypeHelper.IsDateTime(tmember)) { result = EnumType.tdatetime; } else if (TypeHelper.IsBoolean(tmember)) { result = EnumType.tboolean; } else if (TypeHelper.IsCollection(tmember)) { //-- member is collection Type telement; if (TypeHelper.GetElementTypeOfCollection(tmember, out telement)) { result = ScriptHelper.GetCategoryType(telement); } else { result = EnumType.tpurecollection; } } return(result); }