コード例 #1
0
        internal void PopulateXamlTags()
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.XamlTags;

            foreach (string typeName in Intelli.XamlAutoCompleteTypes.Keys)
            {
                Type type = Intelli.XamlAutoCompleteTypes[typeName];
                AddType(type, typeName, false);
            }

            unFilteredItems.Sort();
            this.listBox.Items.AddRange(unFilteredItems.ToArray());

            if (this.listBox.Items.Contains(this.LastUsedNonMember))
            {
                this.listBox.SelectedItem = this.LastUsedNonMember;
            }
            else if (this.listBox.Items.Count > 0)
            {
                this.listBox.SelectedIndex = 0;
            }

            SetFilterButtonVisibility(Array.Empty <IntelliType>());
        }
コード例 #2
0
        internal void PopulateSuggestions(Type type)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.Suggestions;
            bool plural    = false;
            Type iEnumType = type.GetInterface("IEnumerable`1") ?? ((type.IsInterface && type.Name.Equals("IEnumerable`1", StringComparison.Ordinal)) ? type : null);

            if (iEnumType != null && iEnumType.IsConstructedGenericType && iEnumType.GenericTypeArguments.Length == 1)
            {
                plural = true;
                type   = iEnumType.GenericTypeArguments[0];
            }

            string typeName = Regex.Replace(type.Name, @"`\d", string.Empty);

            unFilteredItems.AddRange(GenerateSuggestedNames(typeName)
                                     .Select(str =>
            {
                string suggestion = plural ? str.MakePlural() : str;
                return(new IntelliBoxItem(suggestion, suggestion, "(Suggested name)", IntelliType.Variable));
            })
                                     );

            this.listBox.Items.AddRange(unFilteredItems.ToArray());
            this.listBox.SelectedIndex = 0;

            SetFilterButtonVisibility(Array.Empty <IntelliType>());
        }
コード例 #3
0
        internal void PopulateSuggestions(Type type)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.Suggestions;

            bool plural    = false;
            Type iEnumType = type.GetInterface("IEnumerable`1");

            if (iEnumType != null && !iEnumType.IsGenericTypeDefinition)
            {
                plural = true;
                type   = iEnumType.GenericTypeArguments[0];
            }

            string typeName = Regex.Replace(type.Name, @"`\d", string.Empty);

            unFilteredItems.AddRange(SplitCamelCase(typeName)
                                     .Select(str =>
            {
                string suggestion = plural ? str.MakePlural() : str;
                return(new IntelliBoxItem(suggestion, suggestion, "(Suggested name)", IntelliType.Variable));
            })
                                     );

            this.Items.AddRange(unFilteredItems.ToArray());
            this.SelectedIndex = 0;
        }
コード例 #4
0
        internal void PopulateXamlAttributes(Type tagType)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.XamlAttributes;

            PropertyInfo[] properties    = tagType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            bool           isSelfClosing = true;

            foreach (PropertyInfo property in properties)
            {
                if (!property.ReflectedType.IsVisible || !property.CanWrite || property.ReflectedType.IsSpecialName || property.IsObsolete() || property.IsIndexer())
                {
                    continue;
                }

                if (typeof(System.Collections.IList).IsAssignableFrom(property.PropertyType))
                {
                    isSelfClosing = false;
                    continue;
                }

                AddProperty(property);
            }

            unFilteredItems.Sort();
            if (isSelfClosing)
            {
                unFilteredItems.Add(new IntelliBoxItem("/> Close Tag", "/>", "/> Close Tag", IntelliType.None));
            }

            this.listBox.Items.AddRange(unFilteredItems.ToArray());

            if (this.listBox.Items.Contains(this.LastUsedMember))
            {
                this.listBox.SelectedItem = this.LastUsedMember;
            }
            else if (this.listBox.Items.Count > 0)
            {
                this.listBox.SelectedIndex = 0;
            }

            SetFilterButtonVisibility(Array.Empty <IntelliType>());
        }
コード例 #5
0
        /// <summary>
        /// Fills the iBox with all the Constructors of the given Type.
        /// </summary>
        internal void PopulateConstructors(Type type)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.Constructors;

            if (type.IsValueType)
            {
                unFilteredItems.Add(new IntelliBoxItem($"{type.Name}()", string.Empty, $"{type.Name}()", IntelliType.Constructor));
            }

            foreach (ConstructorInfo constructor in type.GetConstructors())
            {
                string toolTip = $"{type.Name}({constructor.Params()})";
                unFilteredItems.Add(new IntelliBoxItem(toolTip, string.Empty, toolTip + "\nConstructor", IntelliType.Constructor));
            }

            this.Items.AddRange(unFilteredItems.ToArray());
            if (unFilteredItems.Count > 0)
            {
                this.SelectedIndex = 0;
            }
        }
コード例 #6
0
        /// <summary>
        /// Fills the iBox with all non-member objects, and then filters them with the given char.
        /// </summary>
        internal void PopulateNonMembers(char startChar, bool inClassRoot)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.NonMembers;

            foreach (string key in Intelli.Keywords)
            {
                string toolTip = $"{key}\nKeyword";
                unFilteredItems.Add(new IntelliBoxItem(key, key, toolTip, IntelliType.Keyword));
            }

            foreach (string snip in Intelli.Snippets.Keys)
            {
                string toolTip = $"{snip}\nSnippet - Tab Twice";
                unFilteredItems.Add(new IntelliBoxItem(snip, snip, toolTip, IntelliType.Snippet));
            }

            foreach (string typeName in Intelli.AutoCompleteTypes.Keys)
            {
                Type type = Intelli.AutoCompleteTypes[typeName];
                AddType(type, typeName, false);
            }

            foreach (string typeName in Intelli.UserDefinedTypes.Keys)
            {
                Type type = Intelli.UserDefinedTypes[typeName];
                AddType(type, typeName, null);
            }

            if (!inClassRoot)
            {
                foreach (string var in Intelli.Variables.Keys)
                {
                    string type    = Intelli.Variables[var].GetDisplayName();
                    string toolTip = $"{type} - {var}\nLocal Variable";
                    unFilteredItems.Add(new IntelliBoxItem(var, var, toolTip, IntelliType.Variable));
                }

                foreach (string para in Intelli.Parameters.Keys)
                {
                    string type    = Intelli.Parameters[para].GetDisplayName();
                    string toolTip = $"{type} - {para}\nParameter";
                    unFilteredItems.Add(new IntelliBoxItem(para, para, toolTip, IntelliType.Parameter));
                }

                MemberInfo[] members = Intelli.UserScript.GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                foreach (MemberInfo memberInfo in members)
                {
                    if (memberInfo.IsObsolete())
                    {
                        continue;
                    }

                    switch (memberInfo.MemberType)
                    {
                    case MemberTypes.Method:
                        MethodInfo methodInfo = (MethodInfo)memberInfo;
                        if (methodInfo.IsSpecialName || methodInfo.DeclaringType != Intelli.UserScript ||
                            methodInfo.Name.Equals("Render", StringComparison.Ordinal) || methodInfo.Name.Equals("PreRender", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        AddMethod(methodInfo, false);
                        break;

                    case MemberTypes.Property:
                        PropertyInfo property = (PropertyInfo)memberInfo;
                        if (property.Name.Equals("SetRenderInfoCalled", StringComparison.Ordinal) || property.Name.Equals("__DebugMsgs", StringComparison.Ordinal) ||
                            property.IsIndexer())
                        {
                            continue;
                        }

                        AddProperty(property);
                        break;

                    case MemberTypes.Event:
                        EventInfo eventInfo = (EventInfo)memberInfo;

                        AddEvent(eventInfo);
                        break;

                    case MemberTypes.Field:
                        if (memberInfo.Name.Equals("RandomNumber", StringComparison.Ordinal) || memberInfo.Name.Equals("instanceSeed", StringComparison.Ordinal) ||
                            memberInfo.Name.EndsWith("_BackingField", StringComparison.Ordinal) ||
                            memberInfo.Name.Equals("__listener", StringComparison.Ordinal) || memberInfo.Name.Equals("__debugWriter", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        FieldInfo field = (FieldInfo)memberInfo;

                        AddField(field);
                        break;
                    }
                }
            }

            IReadOnlyCollection <IntelliType> matchingTypes = unFilteredItems.Select(item => item.IntelliType).Distinct().ToArray();

            SetFilterButtonVisibility(matchingTypes);

            unFilteredItems.Sort();
            Filter(startChar.ToString().Trim());
        }
コード例 #7
0
        /// <summary>
        /// Fills the iBox with members of the given Type.
        /// </summary>
        internal void PopulateMembers(Type type, bool isStatic)
        {
            Clear();
            this.intelliBoxContents = IntelliBoxContents.Members;

            BindingFlags bindingFlags = isStatic ?
                                        BindingFlags.Static | BindingFlags.Public :
                                        BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.CreateInstance | BindingFlags.Public;

            MemberInfo[] members = type.GetMembers(bindingFlags);
            foreach (MemberInfo memberInfo in members)
            {
                if ((!memberInfo.ReflectedType.IsVisible && memberInfo.ReflectedType?.DeclaringType?.FullName != Intelli.UserScriptFullName) ||
                    memberInfo.ReflectedType.IsSpecialName || memberInfo.IsObsolete())
                {
                    continue;
                }

                switch (memberInfo.MemberType)
                {
                case MemberTypes.Method:
                    MethodInfo methodInfo = (MethodInfo)memberInfo;
                    if (methodInfo.IsSpecialName || (type.IsArray && methodInfo.DeclaringType == type))
                    {
                        continue;
                    }

                    AddMethod(methodInfo, false);
                    break;

                case MemberTypes.Property:
                    PropertyInfo property = (PropertyInfo)memberInfo;
                    if (property.IsIndexer())
                    {
                        continue;
                    }

                    AddProperty(property);
                    break;

                case MemberTypes.Event:
                    EventInfo eventInfo = (EventInfo)memberInfo;

                    AddEvent(eventInfo);
                    break;

                case MemberTypes.Field:
                    FieldInfo field = (FieldInfo)memberInfo;
                    if (field.IsSpecialName)
                    {
                        continue;
                    }

                    AddField(field);
                    break;

                case MemberTypes.NestedType:
                    if (!isStatic)
                    {
                        continue;
                    }

                    Type nestedType = (Type)memberInfo;

                    AddType(nestedType, nestedType.Name, true);
                    break;
                }
            }

            if (!isStatic)
            {
                foreach (MethodInfo methodInfo in type.GetExtensionMethods())
                {
                    AddMethod(methodInfo, true);
                }
            }

            unFilteredItems.Sort();
            this.listBox.Items.AddRange(unFilteredItems.ToArray());

            if (this.listBox.Items.Contains(this.LastUsedMember))
            {
                this.listBox.SelectedItem = this.LastUsedMember;
            }
            else if (this.listBox.Items.Count > 0)
            {
                this.listBox.SelectedIndex = 0;
            }

            IReadOnlyCollection <IntelliType> matchingTypes = unFilteredItems.Select(item => item.IntelliType).Distinct().ToArray();

            SetFilterButtonVisibility(matchingTypes);
        }