Exemple #1
0
 /// <summary>
 /// 获取参数描述
 /// </summary>
 /// <param name="method"></param>
 /// <param name="parameter"></param>
 /// <returns></returns>
 public unsafe string Get(MethodInfo method, ParameterInfo parameter)
 {
     Xml.Node xmlNode = get(method);
     if (xmlNode.Type == Xml.NodeType.Node)
     {
         string parameterName = parameter.Name;
         Range  attribute     = default(Range);
         fixed(char *nameFixed = "name", parameterFixed = parameterName)
         {
             foreach (KeyValue <SubString, Xml.Node> node in xmlNode.Nodes)
             {
                 if (node.Value.Type != Xml.NodeType.Node && node.Key.Equals("param") &&
                     node.Value.GetAttribute(nameFixed, 4, ref attribute) &&
                     attribute.Length == parameterName.Length)
                 {
                     fixed(char *attributeFixed = node.Key.String)
                     {
                         if (AutoCSer.Memory.SimpleEqualNotNull((byte *)parameterFixed, (byte *)(attributeFixed + attribute.StartIndex), parameterName.Length << 1))
                         {
                             return(node.Value.String.Length == 0 ? string.Empty : node.Value.String.ToString());
                         }
                     }
                 }
             }
         }
     }
     return(string.Empty);
 }
Exemple #2
0
        /// <summary>
        /// 获取程序集信息
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        private unsafe static XmlDocumentAssembly get(Assembly assembly)
        {
            if (assembly != null)
            {
                XmlDocumentAssembly 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"))
                        {
                            Xml.Node xmlNode = AutoCSer.Xml.Parser.Parse <Xml.Node>(File.ReadAllText(fileName, Encoding.UTF8), xmlParserConfig)["members"];
                            if (xmlNode.Type == Xml.NodeType.Node)
                            {
                                fixed(char *nameFixed = "name")
                                {
                                    value = new XmlDocumentAssembly();
                                    Range attribute = default(Range);

                                    foreach (KeyValue <SubString, Xml.Node> node in xmlNode.Nodes)
                                    {
                                        if (node.Value.Type == Xml.NodeType.Node && node.Key.Equals("member"))
                                        {
                                            if (node.Value.GetAttribute(nameFixed, 4, ref attribute) && attribute.Length > 2)
                                            {
                                                value.LoadMember(new SubString {
                                                    String = node.Key.String, Start = attribute.StartIndex, Length = attribute.Length
                                                }, node.Value);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                AutoCSer.Log.Pub.Log.wait(Log.LogType.All, "XML文档解析失败 " + fileName);
                            }
                        }
                        else
                        {
                            AutoCSer.Log.Pub.Log.wait(Log.LogType.All, "没有找到XML文档注释 " + fileName);
                        }
                    }
                    assemblyLock.Set(assembly, value);
                }
                finally { assemblyLock.Exit(); }
                return(value);
            }
            return(null);
        }
Exemple #3
0
        /// <summary>
        /// 加载数据记录
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="node"></param>
        internal void LoadMember(SubString name, Xml.Node node)
        {//https://msdn.microsoft.com/zh-cn/library/fsbx0t7x(v=vs.80).aspx
            //对于泛型类型,类型名称后跟反勾号,再跟一个数字,指示泛型类型参数的个数。例如,
            //<member name="T:SampleClass`2"> 是定义为 public class SampleClass<T, U> 的类型的标记。
            if (name[1] == ':')
            {
                char code = name[0];
                switch (code & 7)
                {
                case 'T' & 7:    //类型:类、接口、结构、枚举、委托
                    if (code == 'T')
                    {
                        types[name.GetSub(2)] = node;
                    }
                    break;

                case 'F' & 7:    //字段
                    if (code == 'F')
                    {
                        fields[name.GetSub(2)] = node;
                    }
                    break;

                case 'P' & 7:    //属性(包括索引程序或其他索引属性)
                    if (code == 'P')
                    {
                        properties[name.GetSub(2)] = node;
                    }
                    break;

                case 'M' & 7:    //方法(包括一些特殊方法,例如构造函数、运算符等)
                    if (code == 'M')
                    {
                        methods[name.GetSub(2)] = node;
                    }
                    break;
                    //case 'E' & 7://事件
                    //    break;
                    //case 'N' & 7://命名空间
                    //case '!' & 7://错误字符串
                    //break;
                }
            }
        }
Exemple #4
0
 private static string get(Xml.Node node, string name)
 {
     return((node = node[name]).String.Length != 0 ? node.String.ToString() : string.Empty);
 }