想法
第一步 实现对命名空间的智能提示
输入: using Sy
System.Diagnostics.Tools.dll
System.IO.FileSystem.DriveInfo.dll
System.Buffers.dll
System.Data.DataSetExtensions.dll
System.Diagnostics.StackTrace.dll
System.Net.Http.dll
System.Security.Cryptography.Csp.dll
System.Net.HttpListener.dll
System.Runtime.Handles.dll
libSystem.Security.Cryptography.Native.OpenSsl.so
System.Security.Cryptography.Encoding.dll
输入: using System.Di
System.Diagnostics.Tools.dll
System.Diagnostics.StackTrace.dll
System.Diagnostics.DiagnosticSource.dll
System.Diagnostics.Contracts.dll
System.Diagnostics.Process.dll
System.Diagnostics.Tracing.dll
System.Diagnostics.TextWriterTraceListener.dll
System.Diagnostics.TraceSource.dll
System.Diagnostics.Debug.dll
System.Diagnostics.FileVersionInfo.dll
实现
using System.IO;
using System.Collections.Generic;
using System.Reflection;
using System;
namespace c_数据结构
{
class Program
{
static void Main(string[] args)
{
Edit editobj=new Edit();
while (true){
string str=Console.ReadLine();
if(str=="break")break;
foreach(var item in editobj.SetCodeType(str)){
System.Console.WriteLine(item);
}
}
}
}
class Edit{
private List<string> namespaceList=new List<string>();//保存所有命名空间
public int codeType=0;
public List<string> GetNamepace(string code){
List<string> NamesList=new List<string>();
string Namespce="/home/yh/dotnetshred/shared/Microsoft.NETCore.App/5.0.7/"; //填写你自己的sdk路径
if(Directory.Exists(Namespce))
{
string[] nameFile=Directory.GetFiles(Namespce);
int count=0;
foreach(string name in nameFile){
if(name.Contains(code)){
NamesList.Add(name.Replace(Namespce,""));
count++;
}
if(count>10){
break;
}
}
}
else{
System.Console.WriteLine("路径错误");
}
return NamesList;
}
public List<string> SetCodeType(string code){
if(code.Contains("using")){
code=code.Replace("using ","");
return GetNamepace(code);
}
else
{
return GetClassName(code);
}
}
private List<string> GetClassName(string code){
foreach (string namesp in namespaceList){
}
return new List<string>();
}
}
}