Browse Source

Create CSharp.COM.Component.xft

Template to allow creation of Windows COM Components that can be used through Interop from other applications.
pull/488/head
William MacDonald 11 years ago
parent
commit
9d76f7c68e
  1. 206
      data/templates/file/CSharp/CSharp.COM.Component.xft

206
data/templates/file/CSharp/CSharp.COM.Component.xft

@ -0,0 +1,206 @@ @@ -0,0 +1,206 @@
<?xml version="1.0"?>
<Template author="William MacDonald" version="1.0">
<Config
name = "COM Component"
icon = "C#.File.Form"
category = "C#"
subcategory = "${res:Templates.File.Categories.WindowsApplications}"
defaultname = "COMComponent${Number}.cs"
language = "C#"/>
<Description>A COM Component for use by other applications.</Description>
<References>
<Reference include="System" />
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!--
Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension
${FullName} -> Full generated path name
${FileName} -> File name with extension
${FileNameWithoutExtension} -> File name without extension
${Extension} -> Extension in the component ".cs"
${Path} -> Full path of the file
${ClassName} -> Class name (generally FileNameWithoutExtension w/o 'bad' characters)
-->
<Files>
<!-- Designer file must come first, so the design tab is shown correctly -->
<File name="${Path}/${FileNameWithoutExtension}.Designer.cs" DependentUpon="${FileName}" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
partial class ${ClassName}
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the Component.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Component designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
}
}
]]></File>
<File name="${FullName}" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
/// <summary>
/// Description of ${ClassName}.
/// </summary>
[Guid(${ClassName}.guid${ClassName}),
ProgId("${StandardNamespace}.${ClassName}"),
ClassInterface(ClassInterfaceType.AutoDispatch),
ComSourceInterfaces(typeof(I${ClassName}Events)),
ComVisible(true)]
public partial class ${ClassName} : Component, I${ClassName}Wrapper
{
public const string guid${ClassName} = "${GUID}";
public const string guidI${ClassName}Wrapper = "${GUID}";
public const string guidI${ClassName}Events = "${GUID}";
private string name;
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
public ${ClassName}()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public ${ClassName}(IContainer container)
{
container.Add(this);
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public void Open(string info)
{
System.Console.Out.WriteLine("Open");
}
public void Close()
{
if (this.Closing != null)
{
this.Closing("Done");
}
System.Console.Out.WriteLine("Close");
if (this.Closed != null)
{
this.Closed();
}
}
public event ${ClassName}EventHandler Closing;
public event ${ClassName}EventHandler2 Closed;
}
}
]]></File>
<File name="${Path}/I${FileNameWithoutExtension}.cs" DependentUpon="${FileName}" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
using System;
using System.Runtime.InteropServices;
public delegate void ${ClassName}EventHandler(string status);
public delegate void ${ClassName}EventHandler2();
/// <summary>
/// Description of I${ClassName}Wrapper.
/// </summary>
[Guid(${ClassName}.guidI${ClassName}Wrapper),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
ComVisible(true)]
public interface I${ClassName}Wrapper
{
[DispId(10)]
string Name
{
get;
set;
}
[DispId(30)]
void Open(string info);
[DispId(31)]
void Close();
}
/// <summary>
/// Description of I${ClassName}Events.
/// </summary>
[Guid(${ClassName}.guidI${ClassName}Events),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
ComVisible(true)]
public interface I${ClassName}Events
{
[DispId(20)]
void Closing(string status);
[DispId(21)]
void Closed();
}
}
]]></File>
</Files>
<AdditionalOptions/>
</Template>
Loading…
Cancel
Save