/// <summary> /// 获取参数描述 /// </summary> /// <param name="method"></param> /// <param name="parameter"></param> /// <returns></returns> public unsafe string Get(MethodInfo method, ParameterInfo parameter) { xmlNode xmlNode = get(method); if (xmlNode.Type == emit.xmlNode.type.Node) { string parameterName = parameter.Name; xmlParser.attributeIndex attribute = default(xmlParser.attributeIndex); fixed(char *nameFixed = "name", parameterFixed = parameterName) { foreach (keyValue <subString, xmlNode> node in xmlNode.Nodes) { if (node.Value.Type != emit.xmlNode.type.Node && node.Key.Equals("param") && node.Value.GetAttribute(nameFixed, 4, ref attribute) && attribute.Length == parameterName.Length) { fixed(char *attributeFixed = node.Key.value) { if (fastCSharp.unsafer.memory.SimpleEqual((byte *)parameterFixed, (byte *)(attributeFixed + attribute.StartIndex), parameterName.Length << 1)) { return(node.Value.String.Length == 0 ? string.Empty : node.Value.String.ToString()); } } } } } } return(string.Empty); }
/// <summary> /// 获取程序集信息 /// </summary> /// <param name="assembly"></param> /// <returns></returns> private unsafe static assembly get(Assembly assembly) { if (assembly != null) { assembly value; if (assemblyLock.TryGetValue(assembly, out value)) { return(value); } try { string fileName = assembly.Location; if (fileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { if (File.Exists(fileName = fileName.Substring(0, fileName.Length - 3) + "xml")) { xmlNode xmlNode = fastCSharp.emit.xmlParser.Parse <xmlNode>(File.ReadAllText(fileName, Encoding.UTF8), xmlParserConfig)["members"]; if (xmlNode.Type == emit.xmlNode.type.Node) { fixed(char *nameFixed = "name") { value = new assembly(); xmlParser.attributeIndex attribute = default(xmlParser.attributeIndex); foreach (keyValue <subString, xmlNode> node in xmlNode.Nodes) { if (node.Value.Type == emit.xmlNode.type.Node && node.Key.Equals("member")) { if (node.Value.GetAttribute(nameFixed, 4, ref attribute) && attribute.Length > 2) { value.LoadMember(subString.Unsafe(node.Key.value, attribute.StartIndex, attribute.Length), node.Value); } } } } } else { log.Error.Real("XML文档解析失败 " + fileName, new System.Diagnostics.StackFrame(), false); } } else { log.Default.Real("没有找到XML文档注释 " + fileName, new System.Diagnostics.StackFrame(), false); } } assemblyLock.Set(assembly, value); } finally { assemblyLock.Exit(); } return(value); } return(null); }
/// <summary> /// 获取属性索引位置 /// </summary> /// <param name="nameStart"></param> /// <param name="nameSize"></param> /// <param name="index"></param> /// <returns></returns> internal unsafe bool GetAttribute(char *nameStart, int nameSize, ref xmlParser.attributeIndex index) { if (attributes != null) { foreach (keyValue <xmlParser.attributeIndex, xmlParser.attributeIndex> attribute in attributes) { if (attribute.Key.Length == nameSize) { fixed(char *xmlFixed = String.value) { if (fastCSharp.unsafer.memory.SimpleEqual((byte *)(xmlFixed + attribute.Key.StartIndex), (byte *)nameStart, nameSize << 1)) { index = attribute.Value; return(true); } } } } } return(false); }