Setting SyntaxLanguageTypeName within the code

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by John Youren
Version: 4.0.0243
Avatar
Hi,

I want to use the outlining features of Syntax Editor, so I have written the C# class to handle this. However, I can't use an XML file for two reasons:

1). The component is set up programmatically, without an XML file
2). An XML file wouldn't work because I use an obfuscator, and so everything ends up as ?'s

Therefore, is there away of connecting my dynamically created language to my outlining class programmatically?

Thanks,
John

Comments (8)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Can you load your XML file (without a SyntaxLanguageTypeName set) in the assembly as an embedded resource? If so, there is a protected constructor on DynamicSyntaxLanguage that is defined like this:
protected DynamicSyntaxLanguage(Assembly assembly, string manifestResourceName, int encryptionKey)
So in your DynamicSyntaxLanguage class implementation you would call that constructor with the manifest resource name in the specified assembly of the XML file and it will load it. That way everything is merged and to create your language you just create an instance of your concrete language class.


Actipro Software Support

Posted 17 years ago by John Youren
Avatar
Thanks, I'll see if that works.

Would it be possible to add a method in the next release of SyntaxEditor that will let me do it programmicaly?
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Actually there also is a "hidden" property on DynamicSyntaxLanguage named DefinitionXml that is for use by the designer to set the XML data. It generally isn't intended for use by developers but it would probably work for you too. In that case, create an instance of your special DynamicSyntaxLanguage class then immediately set the DefinitionXml property to the string that is the XML definition.


Actipro Software Support

Posted 17 years ago by John Youren
Avatar
Thanks,

This is my code

Type t = typeof(BasicOutlining);
                    string xml = t.Namespace + "." + t.Name + "," + t.Assembly.FullName.Substring(0, t.Assembly.FullName.IndexOf(','));
                    syn.Properties.Add(new SyntaxLanguageProperty("DefinitionXml", xml));
Doesn't work though :( Can you see anything wrong?
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Oh sorry, looks like you misunderstood me. More like this:
// Load complete contents of like ActiproSoftware.CSharp.xml or something similar here
string xml = GetXmlDefinition();

// Create language
YourDynamicSyntaxLanguage language = new YourDynamicSyntaxLanguage();
language.DefinitionXml = xml;


Actipro Software Support

Posted 17 years ago by John Youren
Avatar
That method didn't work for me, so I came up with this round-about-way of doing it

string xml;
using (StreamReader sr = new StreamReader(FileUtilities.GetAppPath() + "Syntax\\" + Variables.GetSelectedCompilerChoice() + ".xml"))
{
    xml = sr.ReadToEnd();
}
DynamicSyntaxLanguage syn;
Type t = typeof(BasicOutlining);
xml = xml.Replace("$Data$", t.Namespace + "." + t.Name + "," + t.Assembly.FullName.Substring(0, t.Assembly.FullName.IndexOf(',')));
using (MemoryStream ms = new MemoryStream(xml.Length))
{
    using (StreamWriter sw = new StreamWriter(ms))
    {
        sw.Write(xml);
        sw.Flush();
        ms.Position = 0;
        using (StreamReader sr = new StreamReader(ms))
        {
            syn = DynamicSyntaxLanguage.LoadFromXml(sr.BaseStream, 0);
        }
    }
}
[Modified at 02/21/2007 08:21 AM]
Posted 17 years ago by John Youren
Avatar
The reflection code has problems with my obfuscator (Xenocode), I have to do a lot of tweaking to get that working.

What do you think of my suggestion to allow the outlining class to be set pragmatically in future versions?

e.g.

DynamicSyntaxLanguage syn = new DynamicSyntaxLanguage(...);
..
syn.outliner = new OutliningClass();
..
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Actually you can do that right now. Just take your language class that inherits DynamicSyntaxLanguage and override the PerformAutomaticOutlining method. Then make a property on your language that is a class with your outlining code and call a method on it from PerformAutomaticOutlining.


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.