示例#1
0
        private static List <CustomCompletionData> GetFields(List <Type> types)
        {
            var data = new List <CustomCompletionData>();

            for (int i = 0; i < types.Count; i++)
            {
                Type type   = types[i];
                var  fields = type.GetFields();

                foreach (var field in fields)
                {
                    if (!field.Name.Contains("_"))
                    {
                        var onedata = new CustomCompletionData()
                        {
                            name        = field.Name,
                            actualText  = field.Name,
                            priority    = types.Count() - i,
                            description = type.Name + "." + field.Name + ": " + field.FieldType.Name,
                            iconPath    = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/field.png"
                        };
                        data.Add(onedata);
                    }
                }
            }
            return(data);
        }
示例#2
0
 private void GetDataFromQuickerVars(IList <ICompletionData> data)
 {
     foreach (var item in quickerVarInfo.OfType <JObject>())
     {
         if (item != null)
         {
             var varName      = item["Key"].ToString();
             var DefaultValue = item["DefaultValue"].ToString();
             var Desc         = item["Desc"].ToString();
             var temp         = new CustomCompletionData()
             {
                 name        = varName,
                 actualText  = varName + "}",
                 description = "介绍:" + Desc +
                               (DefaultValue.Length < 10000 ? "\r\n" + "默认值:" + DefaultValue : ""),
                 iconPath = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/" + quickerVarMetaData[item["Type"].ToString()]["name"].ToString().ToLower() + ".png",
             };
             data.Add(temp);
         }
     }
     //data.Add(new CustomCompletionData()
     //{
     //    name = "quicker_in_param",
     //    actualText = "quicker_in_param}",
     //    replaceOffset = 0,
     //    description = "介绍:保存有传入动作的参数",
     //    iconPath = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/text.png",
     //});
 }
示例#3
0
 private void GetDataFromPredefindTypes(string token, IList <ICompletionData> data)
 {
     foreach (var item in PredefindTypes.Where(x => x.Name.StartsWith(token, StringComparison.OrdinalIgnoreCase)))
     {
         var name = ValueTypeHandle(item.Name);
         var temp = new CustomCompletionData()
         {
             name        = name,
             actualText  = item.IsGenericType ? Regex.Replace(name, @"`\d+$", "<$1>") : name,
             priority    = 10,
             description = name,
             iconPath    = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/class.png"
         };
         if (item != null)
         {
             temp.replaceOffset = token.Length;
             data.Add(temp);
         }
     }
 }
示例#4
0
        private List <CustomCompletionData> GetMethods(
            List <Type> types,
            BindingFlags flag = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static,
            bool isInstance   = true)
        {
            var data = new List <CustomCompletionData>();

            for (int i = 0; i < types.Count; i++)
            {
                Type   type       = types[i];
                Type[] interfaces = type.GetInterfaces();
                var    methods    = type.GetMethods(flag);
                //var extensionMethod = type.GetMethods(BindingFlags.Public | BindingFlags.Static).Where(t => t.IsDefined(typeof(ExtensionAttribute), false));
                foreach (var group in methods.Where(x => !x.Name.Contains("_")).GroupBy(x => x.Name))
                {
                    var    method      = group.First(x => true);
                    string description = String.Join("\r\n", group.Select(m =>
                    {
                        IEnumerable <ParameterInfo> paramss = null;
                        bool isExtension = m.IsDefined(typeof(ExtensionAttribute), false);
                        if (isExtension && isInstance)
                        {
                            paramss = m.GetParameters().Skip(1);
                        }
                        else
                        {
                            paramss = m.GetParameters();
                        }
                        return(((!isInstance) ? "static: " : "") + GetGenericTypeName(type)
                               + "."
                               + m.Name
                               + "("
                               + String.Join(", ", paramss.Select(y => GetGenericTypeName(y.ParameterType) + " " + y.Name))
                               + "): "
                               + m.ReturnType.Name);
                    }));
                    string genericPart = (method.IsGenericMethod ? "<>" : "");
                    var    onedata     = new CustomCompletionData()
                    {
                        name       = method.Name + genericPart,
                        actualText = method.Name +
                                     ((method.IsGenericMethod && !method.ContainsGenericParameters) ? "<$1>" : "") +
                                     (method.GetParameters().Count() > 0 ? "($1" : "(") + ")",
                        priority    = types.Count() - i,
                        description = description,
                        iconPath    = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/method.png"
                    };
                    data.Add(onedata);
                }
                if (interfaces.Any(x => x.Name.StartsWith("IEnumerable")))
                {
                    foreach (var group in typeof(Enumerable).GetMethods().Where(x => !x.Name.Contains("_")).GroupBy(x => x.Name))
                    {
                        var    method      = group.First(x => true);
                        var    ts          = GetIEnumerableTs(type).First(x => true);
                        var    TSourse     = ts.GetGenericArguments()[0].Name;
                        string description = String.Join("\r\n", group.Select(m =>
                        {
                            var paramss = m.GetParameters().Skip(1);
                            return(GetGenericTypeName(ts)
                                   + "."
                                   + m.Name
                                   + "("
                                   + string.Join(", ", paramss.Select(x => GetGenericTypeName(x.ParameterType).Replace("TSource", TSourse) + " " + x.Name))
                                   + "): "
                                   + GetGenericTypeName(m.ReturnType));
                        }));
                        string genericPart = ((method.IsGenericMethod && !method.ContainsGenericParameters) ? "<>" : "");
                        var    onedata     = new CustomCompletionData()
                        {
                            name       = method.Name + genericPart,
                            actualText = method.Name +
                                         ((method.IsGenericMethod && !method.ContainsGenericParameters) ? "<$1>" : "") +
                                         (method.GetParameters().Count() > 0 ? "($1" : "(") + ")",
                            priority    = types.Count() - i,
                            description = description,
                            iconPath    = $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Icon/method.png"
                        };
                        data.Add(onedata);
                    }
                }
            }
            return(data);
        }