using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Serein.Library.Utils.SereinExpression { internal class SereinExpressionExtension { /// /// 尝试获取类型 /// /// /// /// /// public static bool TryGetType(string context, out string elementName , out Type type) { int startIndex = context.IndexOf('<'); int endIndex = context.IndexOf('>'); if (startIndex < 0 || endIndex < 0 || startIndex > endIndex) { type = null; elementName = null; return false; } elementName = context.Substring(0,startIndex); type = context.Substring(startIndex + 1, endIndex - startIndex - 1).ToTypeOfString(); return true; } /// /// 尝试获取下标 /// /// /// 文本形式的key/索引 /// public static bool TryGetIndex(string context,out string elementName, out string strIndexKey) { int startIndex = context.IndexOf('['); int endIndex = context.IndexOf(']'); if (startIndex < 0 || endIndex < 0 || startIndex > endIndex) { strIndexKey = null; elementName = null; return false; } elementName = context.Substring(0,startIndex); strIndexKey = context.Substring(startIndex + 1, endIndex - startIndex - 1); return true; } } }