Ejemplo n.º 1
0
        public int CompareTo(object obj)
        {
            SBObject _obj = (SBObject)obj;

            if (extension == _obj.extension)
            {
                return(name.CompareTo(_obj.name));
            }
            else
            {
                return(extension.CompareTo(_obj.extension));
            }
        }
Ejemplo n.º 2
0
        private void LoadExtensions(bool bLoadExtensions)
        {
            try
            {
                extensions.Clear();
                SBObjects.objects.Clear();
                extensions.Add("\\SmallBasicLibrary");
                string   path  = MainWindow.InstallDir + "\\lib\\";
                string[] files = Directory.GetFiles(path, "*.dll");
                foreach (string file in files)
                {
                    if (file.EndsWith("SBDebugger.dll") || File.Exists(path + Path.GetFileNameWithoutExtension(file) + ".xml") || File.Exists(path + Path.GetFileNameWithoutExtension(file) + "." + Language + ".xml"))
                    {
                        extensions.Add("\\lib\\" + Path.GetFileNameWithoutExtension(file));
                    }
                }

                Assembly assembly = Assembly.LoadFrom(MainWindow.InstallDir + extensions[0] + ".dll");
                Type     SmallBasicTypeAttribute       = assembly.GetType("Microsoft.SmallBasic.Library.SmallBasicTypeAttribute");
                Type     HideFromIntellisenseAttribute = assembly.GetType("Microsoft.SmallBasic.Library.HideFromIntellisenseAttribute");
                Type     Primitive = assembly.GetType("Microsoft.SmallBasic.Library.Primitive");

                foreach (string extension in extensions)
                {
                    if (extension.Contains("SBDebugger"))
                    {
                        continue;
                    }
                    if (!bLoadExtensions && !extension.Contains("SmallBasicLibrary"))
                    {
                        continue;
                    }

                    XmlDocument doc = new XmlDocument();
                    SBObject    obj = null;
                    if (File.Exists(MainWindow.InstallDir + extension + "." + Language + ".xml"))
                    {
                        doc.Load(MainWindow.InstallDir + extension + "." + Language + ".xml");
                    }
                    else
                    {
                        doc.Load(MainWindow.InstallDir + extension + ".xml");
                    }

                    if (extension.Contains("SmallBasicLibrary"))
                    {
                        foreach (XmlNode xmlNode in doc.SelectNodes("/doc/members/member"))
                        {
                            if (xmlNode.Attributes["name"].InnerText.StartsWith("M:Microsoft.SmallBasic.Library.Keywords."))
                            {
                                Member member = new Member();
                                SBObjects.keywords.Add(member);
                                member.name    = xmlNode.Attributes["name"].InnerText.Substring(40);
                                member.type    = MemberTypes.Custom;
                                member.summary = "";

                                foreach (XmlNode node in xmlNode.ChildNodes)
                                {
                                    switch (node.Name)
                                    {
                                    case "summary":
                                        member.summary = node.InnerText.Trim();
                                        break;

                                    case "param":
                                        member.arguments[node.Attributes["name"].Value] = node.InnerText.Trim();
                                        break;

                                    case "returns":
                                        member.returns = node.InnerText.Trim();
                                        break;

                                    case "example":
                                        member.other[node.Name] = node.InnerText.Trim();
                                        break;

                                    case "remarks":
                                        member.arguments[node.Name] = node.InnerText.Trim();
                                        break;

                                    case "value":
                                        member.arguments[node.Name] = node.InnerText.Trim();
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    try
                    {
                        assembly = Assembly.LoadFrom(MainWindow.InstallDir + extension + ".dll");
                        Type[] types = assembly.GetTypes();
                        foreach (Type type in types)
                        {
                            if (type.IsPublic && type.IsDefined(SmallBasicTypeAttribute, false))
                            {
                                obj = new SBObject();
                                SBObjects.objects.Add(obj);
                                obj.extension = extension.Split('\\').Last();
                                obj.name      = type.Name;

                                MemberInfo[] memberInfos = type.GetMembers();
                                foreach (MemberInfo memberInfo in memberInfos)
                                {
                                    if (memberInfo.Name.StartsWith("add_") || memberInfo.Name.StartsWith("set_") || memberInfo.Name.StartsWith("get_"))
                                    {
                                        continue;
                                    }

                                    if (memberInfo.MemberType == MemberTypes.Method)
                                    {
                                        MethodInfo methodInfo = (MethodInfo)memberInfo;
                                        if (!methodInfo.IsPublic || !methodInfo.IsStatic || methodInfo.IsDefined(HideFromIntellisenseAttribute, false))
                                        {
                                            continue;
                                        }
                                        if (methodInfo.ReturnType != Primitive && methodInfo.ReturnType != typeof(void))
                                        {
                                            continue;
                                        }
                                        bool parmOK = true;
                                        foreach (ParameterInfo parameterInfo in methodInfo.GetParameters())
                                        {
                                            if (parameterInfo.ParameterType != Primitive)
                                            {
                                                parmOK = false;
                                            }
                                        }
                                        if (!parmOK)
                                        {
                                            continue;
                                        }
                                    }
                                    else if (memberInfo.MemberType == MemberTypes.Property)
                                    {
                                        if (((PropertyInfo)memberInfo).IsDefined(HideFromIntellisenseAttribute, false))
                                        {
                                            continue;
                                        }
                                    }
                                    else if (memberInfo.MemberType == MemberTypes.Event)
                                    {
                                        if (((EventInfo)memberInfo).IsDefined(HideFromIntellisenseAttribute, false))
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        continue;
                                    }

                                    Member member = new Member();
                                    obj.members.Add(member);
                                    member.name    = memberInfo.Name;
                                    member.type    = memberInfo.MemberType;
                                    member.summary = "";

                                    string[] array   = memberInfo.ToString().Split(new char[] { ' ' });
                                    string   dllName = memberInfo.DeclaringType.FullName + ".";
                                    for (int i = 1; i < array.Length; i++)
                                    {
                                        dllName += array[i];
                                    }
                                    if (dllName.EndsWith("()"))
                                    {
                                        dllName = dllName.Substring(0, dllName.Length - 2);
                                    }

                                    XmlNode node1 = null;
                                    foreach (XmlNode xmlNode in doc.SelectNodes("/doc/members/member"))
                                    {
                                        if (xmlNode.Attributes["name"].InnerText == "T:" + type.FullName)
                                        {
                                            node1 = xmlNode.FirstChild;
                                            if (node1.Name == "summary")
                                            {
                                                obj.summary = node1.InnerText.Trim();
                                            }
                                        }
                                        else if (null != node1 && xmlNode.Attributes["name"].InnerText.EndsWith(dllName))
                                        {
                                            foreach (XmlNode node in xmlNode.ChildNodes)
                                            {
                                                switch (node.Name)
                                                {
                                                case "summary":
                                                    member.summary = node.InnerText.Trim();
                                                    break;

                                                case "param":
                                                    member.arguments[node.Attributes["name"].Value] = node.InnerText.Trim();
                                                    break;

                                                case "returns":
                                                    member.returns = node.InnerText.Trim();
                                                    break;

                                                case "example":
                                                    member.other[node.Name] = node.InnerText.Trim();
                                                    break;

                                                case "remarks":
                                                    member.arguments[node.Name] = node.InnerText.Trim();
                                                    break;

                                                case "value":
                                                    member.arguments[node.Name] = node.InnerText.Trim();
                                                    break;

                                                default:
                                                    break;
                                                }
                                            }
                                        }
                                        else if (null != node1 && !xmlNode.Attributes["name"].InnerText.Contains(type.FullName))
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            if (null != obj)
                            {
                                obj.members.Sort();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //MainWindow.Errors.Add("Load Extensions : " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MainWindow.Errors.Add(new Error("Load Extensions : " + ex.Message));
            }
            SBObjects.objects.Sort();
        }