|
|
|
@ -20,6 +20,7 @@ using System;
@@ -20,6 +20,7 @@ using System;
|
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
using ICSharpCode.NRefactory.TypeSystem; |
|
|
|
|
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
|
|
|
|
using ICSharpCode.SharpDevelop.Dom; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.PackageManagement.EnvDTE |
|
|
|
@ -37,9 +38,39 @@ namespace ICSharpCode.PackageManagement.EnvDTE
@@ -37,9 +38,39 @@ namespace ICSharpCode.PackageManagement.EnvDTE
|
|
|
|
|
|
|
|
|
|
public global::EnvDTE.CodeFunction AddFunction(string name, global::EnvDTE.vsCMFunction kind, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic) |
|
|
|
|
{ |
|
|
|
|
// var codeGenerator = new ClassCodeGenerator(Class);
|
|
|
|
|
// return codeGenerator.AddPublicMethod(name, (string)type);
|
|
|
|
|
IType returnType = GetMethodReturnType((string)type); |
|
|
|
|
|
|
|
|
|
context.CodeGenerator.AddMethodAtStart(typeDefinition, Access.ToAccessibility(), returnType, name); |
|
|
|
|
|
|
|
|
|
ReloadTypeDefinition(); |
|
|
|
|
|
|
|
|
|
IMethod method = typeDefinition.Methods.FirstOrDefault(f => f.Name == name); |
|
|
|
|
if (method != null) { |
|
|
|
|
return new CodeFunction(context, method); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IType GetMethodReturnType(string typeName) |
|
|
|
|
{ |
|
|
|
|
var fullTypeName = new FullTypeName(typeName); |
|
|
|
|
|
|
|
|
|
IType type = typeDefinition.Compilation.FindType(fullTypeName); |
|
|
|
|
if (type != null) { |
|
|
|
|
return type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new UnknownType(fullTypeName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ReloadTypeDefinition() |
|
|
|
|
{ |
|
|
|
|
ICompilation compilation = context.DteProject.GetCompilationUnit(typeDefinition.BodyRegion.FileName); |
|
|
|
|
|
|
|
|
|
ITypeDefinition matchedTypeDefinition = compilation.MainAssembly.GetTypeDefinition(typeDefinition.FullTypeName); |
|
|
|
|
if (matchedTypeDefinition != null) { |
|
|
|
|
typeDefinition = matchedTypeDefinition; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|