SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

December 2007 - Posts

  • Porting an AddIn from SharpDevelop 2.2 to 3.0

    There have been some fairly large code changes on moving from SharpDevelop 2.2 to 3.0 and addins written for 2.2 are unlikely to work without some modification. We will look at the changes in the core parts of SharpDevelop and then look at one way to do the porting.

    Not all the differences are covered in the next section just those types and methods that are likely to have been used by an addin.

    ICSharpCode.Core

    TypeDescription
    ICSharpCode.Core.AddInReference
    bool RequirePreload New property that specifies that when a type from an addin is created any addins that are needed by this addin will be preloaded if this flag is set to true. This corresponds to the new requirePreload attribute in an .addin file.

    <Dependency addin="ICSharpCode.XmlEditor" requirePreload="true"/>

    ICSharpCode.Core.AddInTreeNode.TopologicalSortType is no longer public.
    ICSharpCode.Core.FileUtility
    bool IsValidPath(string path)New method that determines whether a full or relative path is valid. This replaces the IsValidFileName method.
    bool IsValidFileName(string fileName)Renamed to IsValidPath.
    static string NormalizePath(string fileName)New method that gets the normalized version of the filename. Slashes are replaced with backslashes, backreferences "." and ".." are 'evaluated'.
    ICSharpCode.Core.Properties
    void ReadProperties(XmlReader reader, string endElement)Method is no longer public but internal.

    NRefactory

    TypeDescription
    ICSharpCode.NRefactory.Ast.ArrayInitializerExpressionReplaced by the CollectionInitializerExpression type.
    ICSharpCode.NRefactory.Ast.BlockStatement
    BlockStatement NullThe Null property now returns a BlockStatement instead of a NullStatement type.
    ICSharpCode.NRefactory.Ast.FieldReferenceExpressionReplaced by the MemberReferenceExpression type.
    ICSharpCode.NRefactory.Ast.MemberReferenceExpressionReplaces the FieldReferenceExpression type.
    ICSharpCode.NRefactory.Ast.InvocationExpression
    List<TypeReference> TypeArgumentsThis property has been removed.
    ICSharpCode.NRefactory.Ast.NullArrayInitializerExpressionThis type has been removed.
    ICSharpCode.NRefactory.Ast.NullBlockStatementNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullConstructorInitializerNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullEventAddRegionNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullEventRaiseStatementNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullEventRemoveStatementNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullExpressionNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullPropertyGetRegionNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullPropertySetRegionNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.Ast.NullStatementNo longer a public type instead it is now internal.
    ICSharpCode.NRefactory.IAstVisitorVarious new methods on this interface to support new types.
    object VisitArrayInitializerExpression(...)Method removed along with the ArrayInitializerExpression type. Replaced by the VisitCollectionInitializerExpression method.
    object VisitFieldReferenceExpression(...)Method removed along with the ArrayInitializerExpression type. Replaced by the VisitMemberReferenceExpression method.
    ICSharpCode.NRefactory.Visitors.NodeTrackingAstVisitorAll TrackedVisit methods have been renamed and now include the name of the type being tracked (e.g. TrackedVisitAddHandlerStatement).

    ICSharpCode.SharpDevelop.Dom

    TypeDescription
    ICSharpCode.SharpDevelop.Dom.AbstractAmbience
    bool IncludeBodiesReplaced by the new IncludeBody property.
    bool IncludeBodyReplaces the IncludeBodies property.
    bool IncludeHTMLMarkupReplaced by the new IncludeHtmlMarkup property.
    bool IncludeHtmlMarkupReplaces the old IncludeHTMLMarkup property.
    bool UseFullyQualifiedMemberNamesReplaced by the new UseFullyQualifiedMemberTypeNames property.
    bool UseFullyQualifiedMemberTypeNamesReplaces the old UseFullyQualifiedMemberNames property.
    String Convert(ModifierEnum)Method removed.
    ICSharpCode.SharpDevelop.Dom.AbstractReturnType
    int TypeArgumentCountReplaces the old TypeParameterCount property.
    int TypeParameterCountReplaced by the new TypeArgumentCount property.
    ICSharpCode.SharpDevelop.Dom.AttributeArgumentType has been removed.
    ICSharpCode.SharpDevelop.Dom.ClassFinderThe constructors now take a ParseInformation type instead of a filename.
    ICSharpCode.SharpDevelop.Dom.ConversionFlags
    IncludeBodiesReplaced by IncludeBody.
    IncludeBodyReplaces IncludeBodies.
    IncludeHTMLMarkupReplaced by IncludeHtmlMarkup.
    IncludeHtmlMarkupReplaces IncludeHTMLMarkup.
    QualifiedNamesOnlyForReturnTypesEnum value removed.
    UseFullyQualifiedNamesReplaced by two new enums UseFullyQualifiedMemberNames and UseFullyQualifedTypeNames.
    UseFullyQualifiedMemberNamesReplaces the UseFullyQualifiedNames enum value.
    UseFullyQualifiedTypeNamesReplaces the UseFullyQualifiedNames enum value.
    ICSharpCode.SharpDevelop.Dom.CSharpExpressionFinder
    int LastExpressionStartPositionProperty has been removed.
    string FindExpressionInternal(string inText, int offset)Method has been removed.
    ctor(string fileName)Constructor now takes a ParseInformation type instead of the filename.
    ICSharpCode.SharpDevelop.Dom.CtrlSpaceResolveHelper
    ResolveResult GetResultFromDeclarationLine(IClass callingClass, IMethodOrProperty callingMember, int caretLine, int caretColumn, string expression)Obsolete method removed. Should use the GetResultFromDeclarationLine method that takes an ExpressionResult instead of a string.
    ICSharpCode.SharpDevelop.Dom.DefaultAttribute
    int CompareTo(IAttribute attribute)Method removed.
    string NameProperty has been removed. The attribute name can now be obtained from the Name property of the AttributeReturnType.
    ICSharpCode.SharpDevelop.Dom.DefaultCompilationUnit
    List<IClass> GetOuterClasses(int caretLine, int caretColumn)Method removed.
    ICSharpCode.SharpDevelop.DomRegion
    int CompareTo(DomRegion region)Method removed and replaced by the Equals method.
    ctor(Location start, Location end)Replaced by the static FromLocation method.
    ICSharpCode.SharpDevelop.ExpressionContext
    bool IsAttributeContextProperty has been removed. Instead compare the ExpressionContext against the ExpressionContext.Attribute.
    ExpressionContext GetAttribute(IProjectContent projectContent)Method removed. To indicate that an expression is an attribute use the ExpressionContext.Attribute type.
    ExpressionContext TypeDerivingFrom(IClass baseClass, bool isObjectCreation)Method now requires an IReturnType instead of an IClass type.
    ICSharpCode.SharpDevelop.ExpressionResult
    ctor(string expression, ExpressionContext context, object tag)Replaced by the new constructor that also takes a DomRegion.
    ctor(string expression, object tag)Replaced by the new constructor that also takes a DomRegion and ExpressionContext.
    ICSharpCode.SharpDevelop.GacAssemblyNameType removed. Code should use the DomAssemblyName instead.
    ICSharpCode.SharpDevelop.GacInterop
    GacAssemblyName FindBestMatchingAssemblyName(GacAssemblyName name)Method now uses DomAssemblyName types.
    GacAssemblyName FindBestMatchingAssemblyName(string name)Method now returns a DomAssemblyName type.
    ICSharpCode.SharpDevelop.GacInterop.AssemblyListEntryType has been removed. Code should now use a DomAssemblyName type.
    ICSharpCode.SharpDevelop.Dom.IAmbience
    String Convert(ModifierEnum)Method removed.
    ICSharpCode.SharpDevelop.Dom.IAttribute
    string NameProperty has been removed. The attribute name can now be obtained from the Name property of the AttributeReturnType.
    ICSharpCode.SharpDevelop.Dom.ICompilationUnit
    List<IClass> GetOuterClasses(int caretLine, int caretColumn) Method removed. Code should now use the IClass's DeclaringType property. For example:
        IClass type = callingClass.DeclaringType; 
    while (type != null) {
    ...
    type = type.DeclaringType;
    }
    ICSharpCode.SharpDevelop.Dom.IProjectContent
    IClass GetClass(string typeName)Method removed. Code should now use GetClass(string typeName, int typeParameterCount) and pass 0 for the typeParameterCount.
    ICSharpCode.SharpDevelop.Dom.IResolver
    ArrayList CtrlSpace(int caretLine, int caretColumn, string fileName, string fileContent, ExpressionContext context)Method changed to use a ParseInformation type instead of a filename.
    ResolveResult Resolve(ExpressionResult expressionResult, int line, int col, string fileName, string fileContent)Method changed to take a ParseInformation type instead of a filename and the line and column parameters have been removed.
    ICSharpCode.SharpDevelop.Dom.IReturnType
    int TypeArgumentCountReplaces the old TypeParameterCount property.
    int TypeParameterCountReplaced by the new TypeArgumentCount property.
    ICSharpCode.SharpDevelop.Dom.MemberLookupHelper
    IMethod FindOverload(IList<IMethod> methods, IReturnType[] typeParameters, IReturnType[] arguments)Method now has an extra out parameter called resultIsAcceptable. This parameter is true if the resulting method is an acceptable match, false if the resulting method is just a guess and will lead to a compile error.
    ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
    bool Initialize(string fileName, int line, int column)Method now takes a ParseInformation type instead of a filename.
    IClass SearchClass(string name)Method now takes an extra Location parameter which is used to search for a class at a particular location in the file. Code that does not need to specify a location should use Location.Empty.
    IReturnType DynamicLookup(string identifier)Method now takes an extra Location parameter. Use Location.Empty if no location can be specified.
    IReturnType SearchMember(IReturnType type, string memberName)Method removed. Instead of using this method call GetMember and then use the IMember's ReturnType.
    IReturnType SearchType(string name)Method now takes an extra Location parameter. Use Location.Empty if no location can be specified.
    ResolveResult Resolve(ExpressionResult expressionResult, int line, int column, string fileName, string fileContent)Method now takes a ParseInformation type instead of the filename. The line and column parameters are no longer required.
    ArrayList CtrlSpace(int caretLine, int caretColumn, string fileName, string fileContent, ExpressionContext context)Method changed to use a ParseInformation type instead of a filename.
    ICSharpCode.SharpDevelop.Dom.ProjectContentRegistry
    IProjectContent GetExistingProjectContent(AssemblyName assembly)Obsolete method has been removed. Use the overloaded method that takes a DomAssemblyName type instead.
    IProjectContent GetExistingProjectContent(string itemInclude, string itemFileName)Method removed. Use the overloaded method that takes a single string parameter.
    ICSharpCode.SharpDevelop.Dom.ReflectionProjectContent
    AssemblyName[] ReferencedAssembliesProperty removed and replaced by the ReferencedAssemblyNames property which returns a list of DomAssemblyNames.
    IList<DomAssemblyName> ReferencedAssemblyNamesReplaces the old ReferencedAssemblies property.

    ICSharpCode.SharpDevelop.Widgets

    TypeDescription
    ICSharpCode.SharpDevelop.Widgets.SideBar.SideTab
    bool IsClipboardRingProperty removed.

    ICSharpCode.SharpDevelop

    TypeDescription
    ICSharpCode.SharpDevelop.ClassBrowserIconService
    int CombineIndexField removed and replaced with SolutionIndex.
    ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.CtrlSpaceCompletionDataProvider
    bool ForceNewExpressionProperty removed.
    ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties
    bool CreateBackupCopyProperty removed.
    bool UseAntiAliasedFontProperty removed.
    ICSharpCode.SharpDevelop.FileService
    IWorkbenchWindow GetOpenFile(string fileName)Method now returns an IViewContent type.
    IWorkbenchWindow NewFile(string defaultName, string language, string content)Method now returns an IViewContent type and the language parameter has been removed.
    IWorkbenchWindow OpenFile(string fileName)Method now returns an IViewContent type.
    ICSharpCode.SharpDevelop.Gui.AbstractBaseViewContentClass has been removed.
    ICSharpCode.SharpDevelop.Gui.AbstractSecondaryViewContent
    void NotifyAfterSave(bool successful)Method removed.
    void NotifyBeforeSave()Method removed.
    void NotifyFileNameChanged()Method removed. Code should either use the TitleNameChanged event or the FileNameChanged event on the PrimaryFile.
    ICSharpCode.SharpDevelop.Gui.AbstractViewContent
    event DirtyChangedEvent renamed to IsDirtyChanged.
    string FileNameProperty renamed to PrimaryFileName.
    bool IsUntitledProperty removed. The property has been moved to the OpenedFile type which can be accessed via the view content's PrimaryFile property.
    void Load(string fileName)Method replaced by the Load method that takes an OpenedFile and a Stream.
    void Load(OpenedFile file, Stream stream)New method that is used to open a file in a view. The OpenedFile type contains information about the file, whilst the stream is the actual file data.
    event SavedEvent removed.
    event SavingEvent removed.
    string UntitledNameProperty removed. The untitled name is now stored as the filename.
    ICSharpCode.SharpDevelop.Gui.DefaultWorkbenchClass is now private and no longer publicly accessible.
    ICSharpCode.SharpDevelop.Gui.DriveObjectClass is now private and no longer publicly accessible.
    ICSharpCode.SharpDevelop.Gui.ExtTreeView
    void ApplyViewStateString(string state, TreeView tree)Method moved to the TreeViewHelper class.
    string GetViewStateString(TreeView tree)Method moved to the TreeViewHelper class.
    ICSharpCode.SharpDevelop.Gui.FileListClass is now private and no longer publicly accessible.
    ICSharpCode.SharpDevelop.Gui.IBaseViewContent Interface has been removed. Most of the interface has been moved to the IViewContent interface apart from the following methods which no longer exist.
    void Deselected()
    void Deselecting()
    void Selected()
    void SwitchedTo()
    ICSharpCode.SharpDevelop.Gui.ICanBeDirty
    event DirtyChangedEvent renamed to IsDirtyChanged.
    bool IsDirtyProperty setter is no longer defined in the interface. Only the getter is defined.
    ICSharpCode.SharpDevelop.Gui.IParseableContentInterface removed.
    ICSharpCode.SharpDevelop.Gui.ISecondaryViewContentInterface removed. All secondary view contents now implement the IViewContent interface.
    ICSharpCode.SharpDevelop.Gui.IViewContent
    bool IsDisposedNew property that indicates whether the view has been disposed.
    bool IsUntitledProperty removed. Code should check the PrimaryFile's Untitled property instead.
    event SavedEvent removed.
    bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)New method. Determines whether switching without a Save/Load is supported when switching from this view to another view.
    bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)New method. Determines whether switching without a Save/Load is supported when switching to this view from another view.
    IWorkbenchWindow WorkbenchWindowProperty moved from the now obsolete IBaseViewContent interface. Gives access to the workbench window associated with this view.
    List<ISecondaryViewContent> SecondaryViewContentsProperty now returns an ICollection instead of a list.
    event FileNameChangedEvent moved to the OpenedFile class which is accessible via the PrimaryFile property.
    event SavingEvent removed.
    OpenedFile PrimaryFileNew property that gives access to information about the primary file associated with this view.
    IList<OpenedFile> FilesNew property that returns a list of files that are associated with this view.
    event DisposedNew event raised when the view is disposed.
    event TabPageTextChangedNew event raised when the tab page text at the bottom of the window is changed.
    string FileNameThe filename associated with a view is now accessible from the PrimaryFileName property.
    string TabPageTextGets or sets the tab page text at the bottom of the window. This property was originally on the now obsolete IBaseViewContent interface.
    string UntitledNameProperty removed. The UntitledName is now the same as the PrimaryFileName.
    Control ControlGets or sets the control associated with this view. Originally part of the IBaseViewContent interface.
    void Load(string fileName)Replaced by the Load method that takes an OpenedFile and a Stream.
    void Load(OpenedFile file, Stream stream)New method that is used to open a file in a view. The OpenedFile type contains information about the file, whilst the stream is the actual file data..
    void Save()Replaced by the Save method that takes an OpenedFile and a Stream.
    void Save(string fileName)Replaced by the Save method that takes an OpenedFile and a Stream.
    void Save(OpenedFile file, Stream stream)New method that is used to save a file in a view.
    ICSharpCode.SharpDevelop.Gui.IViewContentMementoClass removed.
    ICSharpCode.SharpDevelop.Gui.IViewContentMementoCreatorClass removed.
    ICSharpCode.SharpDevelop.Gui.IWorkbenchWindow
    IBaseViewContent ActiveViewContentThe ActiveViewContent property is now an IViewContent.
    IViewContent ViewContentProperty removed. Use the ActiveViewContent property instead.
    ICSharpCode.SharpDevelop.IDisplayBinding
    bool CanCreateContentForFile(string fileName)Method now takes an OpenedFile type instead of a string.
    bool CanCreateContentForLanguage(string language)Method removed.
    ICSharpCode.SharpDevelop.ISecondaryDisplayBinding
    ISecondaryViewContent[] CreateSecondaryViewContent(IViewContent view)Method now returns an IViewContent array since the ISecondaryViewContent interface is obsolete.

    ICSharpCode.TextEditor

    TypeDescription
    ICSharpCode.TextEditor.Caret
    Point PositionThe Position property now uses the ICSharpCode.TextEditor.TextLocation type instead of the System.Drawing.Point type.
    Point ValidatePosition(Position pos)The method now returns and uses the ICSharpCode.TextEditor.TextLocation type instead of the System.Drawing.Point type.
    ICSharpCode.TextEditor.Document.Bookmark
    event LineNumberChangedEvent removed.
    ICSharpCode.TextEditor.Document.BookmarkManager
    event ChangedEvent removed.
    ICSharpCode.TextEditor.Document.DefaultFormattingStrategy
    int FormatLine(TextArea textArea, int line, int caretOffset, char charTyped)Method now no longer returns anything.
    ICSharpCode.TextEditor.Document.DefaultTextEditorProperties
    bool UseAntiAliasedFontProperty removed.
    ICSharpCode.TextEditor.Document.IDocument
    LineSegment GetLineSegment(int line)The default implementation in the DefaultLineSegment class no longer allows the line number to be equal to the number of items in the IDocument's LineSegment collection.
    Point OffsetToPosition(int offset)Method now returns a TextLocation type.
    int PositionToOffset(Point point)Method now takes a TextLocation type.
    ICSharpCode.TextEditor.Document.IFormattingStrategy
    int FormatLine(TextArea textArea, int line, int caretOffset, char charTyped)Method now no longer returns anything.
    ICSharpCode.TextEditor.Document.ILineManagerInterface has been removed.
    ICSharpCode.TextEditor.Document.ISelection
    bool ContainsPosition(Point point)Method now uses a TextLocation type.
    Point EndPositionProperty now uses a TextLocation type.
    Point StartPositionProperty now uses a TextLocation type.
    ICSharpCode.TextEditor.Document.ITextEditorProperties
    bool CreateBackupCopyProperty removed.
    bool UseAntiAliasedFontProperty removed.
    ICSharpCode.TextEditor.Document.LineLengthEventArgsReplaced by the LineLengthChangedEventArgs type.
    ICSharpCode.TextEditor.Gui.InsightWindow.IInsightDataProvider
    char CharTypedProperty removed.
    ICSharpCode.TextEditor.TextEditorControlBase
    event ChangedEvent renamed to TextChanged.
    bool CreateBackupCopyProperty removed.
    bool IsUpdatingProperty removed.
    bool UseAntiAliasedFontProperty removed.
    ICSharpCode.TextEditor.ToolTipRequestEventArgs
    Point LogicalPositionProperty now uses a TextLocation type.
    ICSharpCode.TextEditor.Undo.UndoStack
    void CombineLast(int actionCount)Method removed. Similar functionality can be obtained by using the StartUndoGroup and EndUndoGroup method.
    void UndoLast(int actionCount)Method removed. Similar functionality can be obtained by using the StartUndoGroup and EndUndoGroup method.

    How to Port

    This section looks at one way to port an addin. This is the way that the IronPython addin was ported from SharpDevelop 2.2 to SharpDevelop 3.

    Download the source code for SharpDevelop 3.0 and 2.2.

    Copy the source code of your addin to a folder inside SharpDevelop 3.0.

    Run three copies of SharpDevelop, one to view SharpDevelop 2.2's source, one to view SharpDevelop 3.0's source, one with your addin. In the other copies of SharpDevelop you should open SharpDevelop.sln for 2.2 and 3.0. This will allow you to quickly search for SharpDevelop classes when you find your addin code will not compile.

    Compile your code and fix the code or comment it out as you try to work out what is wrong.

    You do not have to convert the project to use .NET 3.5. SharpDevelop itself uses it, but some of the addins do not. With the IronPython addin I needed to change it to use .NET 3.5 since there were some assembly conflicts between what SharpDevelop was using and what the addin was using. Obviously changing to use .NET 3.5 will allow you to use any new features of this framework.

    .NET Framework Differences

    One change in .NET 3.5 caused me a few problems when porting the IronPython addin. This was a change in MSBuild.

    After finally getting the IronPython addin to compile with the modified SharpDevelop 3 assemblies there was an assembly conflict for MSBuild. The ICSharpCode.SharpDevelop assembly now uses MSBuild 3.5 assemblies whilst the IronPython build task project and test project were using MSBuild 2.0. This was fixed by converting these two projects so they use the .NET Framework 3.5. This can be done by opening the project's properties, selecting the Compiling tab, then clicking the Convert Project to C# 3.0 button. In the dialog that opens we select the "Change target framework to .NET 3.5" and click the OK button. After making this change the addin compiled and worked however all the unit tests for the IronPython build tasks were failing with the error:

    System.ArrayTypeMismatchException : Attempted to access an element as a type incompatible with the array.

    The test code that was failing:

    PythonCompilerTask compiler = new PythonCompilerTask(); 
    TaskItem sourceTaskItem = new TaskItem("test.py");
    compiler.Sources = new ITaskItem[] {sourceTaskItem};

    The last line was failing when the unit test was run. The TaskItem type implements the ITaskItem interface so the code should have worked. The reason for this error is that both the build task and build task tests project were referencing the MSBuild libraries just using the reference name.

        <Reference Include="Microsoft.Build.Framework" /> 
    <Reference Include="Microsoft.Build.Tasks" />
    <Reference Include="Microsoft.Build.Utilities" />

    Running MSBuild from the command line the actual assemblies being used were a mix of 3.5 and 2.0 versions.

    "Python.Build.Tasks.csproj": 
    /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\Microsoft.Build.Framework.dll"
    /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Build.Tasks.dll
    /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Build.Utilities.dll

    Printing out the code base of the TaskItem and ITaskItem types whilst running the unit tests showed that the TaskItem was being taken from Microsoft.Build.Utilities assembly version 2.0 and the ITaskItem was being taken the Microsoft.Build.Framework 3.5 assembly. The TaskItem we actually needed was in the new Microsoft.Build.Utilities assembly version 3.5. Changing the project references so they used this new 3.5 assembly fixed the problem.

    Posted Dec 09 2007, 05:28 PM by MattWard with no comments
    Filed under:
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.