/// <summary> /// Find custom type /// </summary> /// <param name="t"></param> /// <returns></returns> public static Type FindCustomTypeOrDefault(Type t, out bool isCollection) { Type tfound = null; isCollection = false; if ((t.IsPublic || t.IsNestedPublic) && (t.IsClass || t.IsInterface) && !t.Name.Contains("<")) { if (TypeHelper.GetElementTypeOfCollection(t, out tfound)) { /*-- t is collection. */ isCollection = true; } else { Type t_temp; if (TypeHelper.GetElementTypeOfTask(t, out t_temp)) { if (TypeHelper.GetElementTypeOfCollection(t_temp, out tfound)) { isCollection = true; } else { tfound = t_temp; } } else { tfound = t; } } } return(tfound); }
/// <summary> /// Get element type of collection if 't' is collection other else return 't'. /// </summary> /// <param name="t"></param> /// <returns></returns> public static Type GetElementTypeOfCollectionOrDefault(Type t) { Type t_work; //-- If it's collection, we use type of element. if (!TypeHelper.GetElementTypeOfCollection(t, out t_work)) { t_work = t; } return(t_work); }
/// <summary> /// Name of t. /// </summary> /// <param name="t"></param> /// <returns></returns> public static string GetName(Type t) { string name; string separator = "_$gen$_"; if (t.IsGenericType) { Type[] targs = t.GetGenericArguments(); List <string> tnamesArray = new List <string>(); for (int idx = 0; idx < targs.Length; idx++) { Type targ = targs[idx]; if (targ != null) { Type telem_of_targ; bool isCollection = TypeHelper.GetElementTypeOfCollection(targ, out telem_of_targ); if (isCollection) { tnamesArray.Add("ICollection" + separator + telem_of_targ.FullName.Replace(".", null)); } else { if (targ.FullName == null) { tnamesArray.Add(targ.Name.Replace(".", null)); } else { tnamesArray.Add(targ.FullName.Replace(".", null)); } } } } if (tnamesArray.Count > 0) { name = t.Name.Split(new string[] { "`" + tnamesArray.Count }, StringSplitOptions.None)[0] + separator + string.Join(separator, tnamesArray); } else { name = t.Name; } } else { name = t.Name; } return(name.Replace("+", ".")); }
/// <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> /// 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); }