Creating an ICSharpFile from text

Hello.

I was wondering if it's possible at all to create the ICSharpFile representation from a text string? I'd like to use this in a unit test.

Thanks,
Igal.

7 comments

Use CSharpElementFactory.CreateFile method

--
Eugene Pasynkov
ReSharper Technical Lead
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


"Igal Tabachnik" <no_reply@jetbrains.com> wrote in message
news:18057083.201233740951684.JavaMail.clearspace@app4.labs.intellij.net...

Hello.

>

I was wondering if it's possible at all to create the ICSharpFile
representation from a text string? I'd like to use this in a unit test.

>

Thanks,
Igal.

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5231341#5231341



0

And what about IProject? It seems that CSharpElementFactory has a GetInstance method that takes an IProject. Can I create that too? Basically, I would like to create a ICSharpFile to use as a a test object...

0

You can pass "null" there

--
Eugene Pasynkov
ReSharper Technical Lead
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


"Igal Tabachnik" <no_reply@jetbrains.com> wrote in message
news:8854187.17201233877062086.JavaMail.clearspace@app4.labs.intellij.net...

And what about IProject? It seems that CSharpElementFactory has a
GetInstance method that takes an IProject. Can I create that too?
Basically, I would like to create a ICSharpFile to use as a a test
object...

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5231553#5231553



0

Hi Eugene,

Here's how I'm interpreting what you are saying:

CSharpElementFactory.GetInstance(null).CreateFile(@"
    enum MyEnum { First, Second }
");


But I get a null ref exception inside GetInstance().  From what I can tell with Reflector it seems to be due to the project.GetSolution() call in the CSharpElementFactoryImpl .ctor.

0

No, you can't pass 'null' here.
You should get valid IPsiModule for any project in your solution

--
Eugene Pasynkov
ReSharper Technical Lead
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


"jbuedel" <no_reply@jetbrains.com> wrote in message
news:20832618.11101234650333180.JavaMail.clearspace@app4.labs.intellij.net...

Hi Eugene,

>

Here's how I'm interpreting what you are saying:

 enum MyEnum { First, Second }
> ");]]>

>

But I get a null ref exception inside GetInstance(). From what I can tell
with Reflector it seems to be due to the project.GetSolution() call in the
CSharpElementFactoryImpl .ctor.

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5232141#5232141



0

I'm sorry, but your answer contradicts your previous one. Perhaps there's a misunderstanding.
I'll rephrase my question: given a string:

string classText =
@"using System;


public class MyClass
{
  public int Number = 5;
}
";


How can I turn this text to an instance of an IFile, without (known) ISolution/IProject. Furthermore, this should happen during an external unit test, not while the plugin is runnig.

Thanks,
Igal.

0

I was wrong saying it is safe to pass 'null' :( All ReSharper utility
methods require valid solution/projects to be opened.
If you would like to access ReSharepr services in your tests, then you need
to open some empty solution in the memory, for example:

var solution = SolutionManager.Instance.CreateSolution(...)
vap project = solution.CreateProject(...)

--
Eugene Pasynkov
ReSharper Technical Lead
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


"Igal Tabachnik" <no_reply@jetbrains.com> wrote in message
news:13663024.8101234911432599.JavaMail.clearspace@app4.labs.intellij.net...

I'm sorry, but your answer contradicts your previous one. Perhaps there's
a misunderstanding.
I'll rephrase my question: given a string:

>

string classText =
> @"using System;
>
>
> public class MyClass
> {
> public int Number = 5;
> }
> ";

>

How can I turn this text to an instance of an IFile, without (known)
ISolution/IProject. Furthermore, this should happen during an external
unit test, not while the plugin is runnig.

>

Thanks,
Igal.

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5232358#5232358



0

Please sign in to leave a comment.