Posted 16 years ago by Luciano Furlan
Version: 4.0.0275
Avatar
Is there an example of how to use SyntaxEditor with partial classes written in C#?

Comments (14)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, I believe the .NET Reflection quick start shows that.


Actipro Software Support

Posted 16 years ago by Miha Markic - Righthand
Avatar
Looks like fragment editing doesn't work with partial classes, i.e.:
Header:
partial class Tubo
{
  public void One() {}
}
Body:
partial class Tubo
{
  public void Two() 
  {
    this.One(); // intellisense doesn't see method One
  }
}

Miha Markic Righthand .net consulting and software development

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Miha,

That is correct, right now partial class IntelliPrompt only works when they are in separate source files. So you could add the fragments you had in the header into a separate Document and keep that alive while editing the one in your SyntaxEditor. Some of the other QuickStarts show how to do parsing without SyntaxEditors attached.

We do have an item on the TODO list to try and improve multiple partial classes to work in the same file, which would resolve this issue.


Actipro Software Support

Posted 16 years ago by Miha Markic - Righthand
Avatar
I took a look and I see how I can create SemanticParserServiceRequest and get the result. Now, the question is how to make syntaxeditor's intelliprompt to use this result?

Thanks,

Miha Markic Righthand .net consulting and software development

Posted 16 years ago by Trevor McAlister
Avatar
Hi

I am having the same problem.
I have just tried putting the my two partial classes in separate SyntaxEditors with separate documents associated with them but the classes still can't see each other.
The only thing I have got shared between the two is the same DotNetProjectResolver

Am I still missing something, or is using partial classes generally untested.

Assuming a fix is going to be in the next release what date is it scheduled for, so I can make a decision of doing a work around or not.

Trevor
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Miha,

Actually it's simpler than that. This code shows you what you do:
dotNetProjectResolver.SourceProjectContent.LoadForCode(cSharpLanguage, "unique key for snippet here", code);

First parameter is the .NET language, second is a key that identifies the snippet (so you can remove it later too), and the third is the text of the code snippet.
Trevor,

The problem could be that your partial classes aren't getting placed in the SourceProjectContent, so what I mentioned above for Miha would probably apply to you to. Partial classes should work fine as long as they are registered in different source keys (which are normally documents).


Actipro Software Support

Posted 16 years ago by Miha Markic - Righthand
Avatar
Hi support,

Yep, that really sounds easy. However it still doesn't work for me as expected. Take this example:
partial class Tubo
{
    public void Meho(){
        Tubo t;
        t.One();   // t sees One() but not Meho()
        this.One();// this doesn't see One() but sees Meho()
    }
}
here is the snippet:
const string text = @"partial class Tubo { public void One(){}}";
string s = resolver.SourceProjectContent.LoadForCode(language, "xxx", text);

Miha Markic Righthand .net consulting and software development

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I did a test and it worked fine. I went into the .NET Language Reflection QuickStart's DotNetReflectionForm.cs code and added your two lines:
const string text = @"partial class Tubo { public void One(){}}";
string s = dotNetProjectResolver.SourceProjectContent.LoadForCode(cSharpLanguage, "xxx", text);
Then I ran the QuickStart and pasted the other snippet right under the using's. When I go into a method and declare a Tubo, I see all defined methods.


Actipro Software Support

Posted 16 years ago by Miha Markic - Righthand
Avatar
Hi supporter,

Great, thanks, I did compare the two samples:
I think I've found the reason why it didn't work for me. I didn't set Document.FileName.
Is this by design? I wouldn't guess that not setting a filename would have this effect.

Miha Markic Righthand .net consulting and software development

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, that is indicated in the key steps for getting started documentation for the add-on. The Filename must be set so that it knows how to identify that code in the SourceProjectContent and add/remove it when it is changed.


Actipro Software Support

Posted 16 years ago by Trevor McAlister
Avatar
Hi

I must confess I hadn’t read that page of the document.
But I have set different file names on my two code documents, and even put things in the described order. But the two partial classes still can’t see each other.

Trevor
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It's hard to say without debugging it. If you can't figure it out, perhaps make a simple sample that shows the problem and we can take a look.


Actipro Software Support

Posted 15 years ago by BorodaAlex
Avatar
I followed the hints of this thread and that helped me with partial classes, but I have one common problem regarding correct displaying list of methods in IntelliPrompt popup.

In one of my partial classes I use code with Pre Processor Directive (#if #endif etc) like this:

partial class Tubo
{
  #if Net11
  public void One() 
  {
     return;    
  }
  #else
  public void OneEx() 
  {
     return;    
  }
  #endif
}

But both methods One() and OneEx() are displayed in IntelliPrompt
of a partial class:

partial class Tubo
{
    public void Meho(){
        Tubo t;
        t.One();   // IntelliPrompt contains two methods - One() and OneEx().
    }
}
It sounds like editor ignores any PreProcessor Directives during building list of items to be shown.

Is there any way to display a corresponding method in IntelliPrompt that matches PreProcessor Directives?

Thanks in advance.

[Modified at 05/22/2009 10:00 AM]

[Modified at 05/22/2009 10:01 AM]
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Correct, at this time pre-processor instructions are ignored by the semantic parser so it will show both methods. This is something we have on our TODO list to eventually look into.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.