Browse Source

add back SettingsEditor addin

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
41beb10d7c
  1. 13
      SharpDevelop.sln
  2. 5
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsCodeGeneratorTool.cs
  3. 7
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsDisplayBinding.cs
  4. 8
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj
  5. 9
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs
  6. 10
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx
  7. 5
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs
  8. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  9. 382
      src/Main/Base/Project/Util/EasyCodeDom.cs

13
SharpDevelop.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.3 # SharpDevelop 5.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection
@ -117,6 +117,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IconEditor", "src\AddIns\Di
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyAddIn", "src\AddIns\DisplayBindings\ILSpyAddIn\ILSpyAddIn.csproj", "{8AA421C8-D7AF-4957-9F43-5135328ACB24}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyAddIn", "src\AddIns\DisplayBindings\ILSpyAddIn\ILSpyAddIn.csproj", "{8AA421C8-D7AF-4957-9F43-5135328ACB24}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SettingsEditor", "src\AddIns\DisplayBindings\SettingsEditor\Project\SettingsEditor.csproj", "{85226AFB-CE71-4851-9A75-7EEC663A8E8A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{7019F43E-DFD7-4D1C-8C96-E75D55646DE7}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{7019F43E-DFD7-4D1C-8C96-E75D55646DE7}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection
@ -477,6 +479,14 @@ Global
{E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|x86.Build.0 = Release|Any CPU {E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|x86.Build.0 = Release|Any CPU
{E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|x86.ActiveCfg = Release|Any CPU {E2FD63DA-8478-4066-934C-DA82A852C83A}.Release|x86.ActiveCfg = Release|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Debug|x86.Build.0 = Debug|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Debug|x86.ActiveCfg = Debug|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Release|Any CPU.Build.0 = Release|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Release|x86.Build.0 = Release|Any CPU
{85226AFB-CE71-4851-9A75-7EEC663A8E8A}.Release|x86.ActiveCfg = Release|Any CPU
{B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|Any CPU.Build.0 = Debug|x86 {B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|Any CPU.Build.0 = Debug|x86
{B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|Any CPU.ActiveCfg = Debug|x86 {B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|Any CPU.ActiveCfg = Debug|x86
{B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|x86.Build.0 = Debug|x86 {B5D8C3E6-42EC-4D4B-AD05-3644B32563EF}.Debug|x86.Build.0 = Debug|x86
@ -537,6 +547,7 @@ Global
{DCA2703D-250A-463E-A68A-07ED105AE6BD} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {DCA2703D-250A-463E-A68A-07ED105AE6BD} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {DFB936AD-90EE-4B4F-941E-4F4A636F0D92} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{8AA421C8-D7AF-4957-9F43-5135328ACB24} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {8AA421C8-D7AF-4957-9F43-5135328ACB24} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{85226AFB-CE71-4851-9A75-7EEC663A8E8A} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{1F261725-6318-4434-A1B1-6C70CE4CD324} = {7019F43E-DFD7-4D1C-8C96-E75D55646DE7} {1F261725-6318-4434-A1B1-6C70CE4CD324} = {7019F43E-DFD7-4D1C-8C96-E75D55646DE7}
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E} {1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E}
{EC06F96A-AEEC-49D6-B03D-AB87C6EB674C} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E} {EC06F96A-AEEC-49D6-B03D-AB87C6EB674C} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E}

5
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsCodeGeneratorTool.cs

@ -10,6 +10,7 @@ using System.Reflection;
using System.Xml; using System.Xml;
using ICSharpCode.EasyCodeDom; using ICSharpCode.EasyCodeDom;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
@ -128,7 +129,7 @@ namespace ICSharpCode.SettingsEditor
End If End If
End Sub End Sub
#End If #End If
#End Region".Replace("\t", EditorControlService.GlobalOptions.IndentationString) #End Region".Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString)
)); ));
defaultProperty.GetStatements.Insert(0, new CodeSnippetStatement( defaultProperty.GetStatements.Insert(0, new CodeSnippetStatement(
@ -141,7 +142,7 @@ namespace ICSharpCode.SettingsEditor
End If End If
End SyncLock End SyncLock
End If End If
#End If".Replace("\t", EditorControlService.GlobalOptions.IndentationString) #End If".Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString)
)); ));
} }

7
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsDisplayBinding.cs

@ -5,12 +5,13 @@ using System;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Workbench;
namespace ICSharpCode.SettingsEditor namespace ICSharpCode.SettingsEditor
{ {
public sealed class SettingsDisplayBinding : IDisplayBinding public sealed class SettingsDisplayBinding : IDisplayBinding
{ {
public bool CanCreateContentForFile(string fileName) public bool CanCreateContentForFile(FileName fileName)
{ {
return true; return true;
} }
@ -20,12 +21,12 @@ namespace ICSharpCode.SettingsEditor
return new SettingsViewContent(file); return new SettingsViewContent(file);
} }
public bool IsPreferredBindingForFile(string fileName) public bool IsPreferredBindingForFile(FileName fileName)
{ {
return true; return true;
} }
public double AutoDetectFileContent(string fileName, System.IO.Stream fileContent, string detectedMimeType) public double AutoDetectFileContent(FileName fileName, System.IO.Stream fileContent, string detectedMimeType)
{ {
return 1; return 1;
} }

8
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj

@ -13,7 +13,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SourceAnalysisOverrideSettingsFile>C:\Users\Daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile> <SourceAnalysisOverrideSettingsFile>C:\Users\Daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>False</Optimize> <Optimize>False</Optimize>
@ -79,6 +80,11 @@
<Compile Include="SettingsCodeGeneratorTool.cs" /> <Compile Include="SettingsCodeGeneratorTool.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>

9
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs

@ -6,6 +6,8 @@ using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
@ -46,15 +48,18 @@ namespace ICSharpCode.SettingsEditor
List<string> typeNames = new List<string>(); List<string> typeNames = new List<string>();
List<Type> types = new List<Type>(); List<Type> types = new List<Type>();
IAmbience ambience; IAmbience ambience;
ICompilation compilation;
public SettingsView() public SettingsView()
{ {
InitializeComponent(); InitializeComponent();
ambience = AmbienceService.GetCurrentAmbience(); ambience = AmbienceService.GetCurrentAmbience();
compilation = MinimalCorlib.Instance.CreateCompilation();
foreach (Type type in defaultAvailableTypes) { foreach (Type type in defaultAvailableTypes) {
types.Add(type); types.Add(type);
typeNames.Add(ambience.GetIntrinsicTypeName(type.FullName)); typeNames.Add(ambience.ConvertType(type.ToTypeReference().Resolve(compilation)));
} }
foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) {
types.Add(d.type); types.Add(d.type);
@ -147,7 +152,7 @@ namespace ICSharpCode.SettingsEditor
if (type == d.type) if (type == d.type)
return d.name; return d.name;
} }
return ambience.GetIntrinsicTypeName(type.FullName); return ambience.ConvertType(type.ToTypeReference().Resolve(compilation));
} }
Type ISettingsEntryHost.GetTypeByDisplayName(string displayName) Type ISettingsEntryHost.GetTypeByDisplayName(string displayName)

10
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx

@ -117,10 +117,12 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="TypeColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TypeColumn.UserAddedColumn" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
</metadata> </data>
<metadata name="bindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="bindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing">
<value>28, 18</value> <value>28, 18</value>
</metadata> </data>
</root> </root>

5
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs

@ -13,6 +13,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Workbench;
namespace ICSharpCode.SettingsEditor namespace ICSharpCode.SettingsEditor
{ {
@ -50,7 +51,7 @@ namespace ICSharpCode.SettingsEditor
return; return;
FileName appConfigFileName = CompilableProject.GetAppConfigFile(p, createIfNotExists); FileName appConfigFileName = CompilableProject.GetAppConfigFile(p, createIfNotExists);
if (appConfigFileName != null) { if (appConfigFileName != null) {
appConfigFile = FileService.GetOrCreateOpenedFile(appConfigFileName); appConfigFile = SD.FileService.GetOrCreateOpenedFile(appConfigFileName);
this.Files.Add(appConfigFile); this.Files.Add(appConfigFile);
if (createIfNotExists) if (createIfNotExists)
appConfigFile.MakeDirty(); appConfigFile.MakeDirty();
@ -72,7 +73,7 @@ namespace ICSharpCode.SettingsEditor
} }
} else if (file == appConfigFile) { } else if (file == appConfigFile) {
appConfigStream = new MemoryStream(); appConfigStream = new MemoryStream();
stream.WriteTo(appConfigStream); stream.CopyTo(appConfigStream);
} }
} }

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -234,6 +234,7 @@
<Compile Include="Util\CustomThreadPoolTaskScheduler.cs" /> <Compile Include="Util\CustomThreadPoolTaskScheduler.cs" />
<Compile Include="Util\DebugTimer.cs" /> <Compile Include="Util\DebugTimer.cs" />
<Compile Include="Util\DotnetDetection.cs" /> <Compile Include="Util\DotnetDetection.cs" />
<Compile Include="Util\EasyCodeDom.cs" />
<Compile Include="Util\EnumBinding.cs" /> <Compile Include="Util\EnumBinding.cs" />
<Compile Include="Util\SharpDevelopExtensions.cs" /> <Compile Include="Util\SharpDevelopExtensions.cs" />
<Compile Include="Util\GenericConverter.cs" /> <Compile Include="Util\GenericConverter.cs" />

382
src/Main/Base/Project/Util/EasyCodeDom.cs

@ -0,0 +1,382 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.CodeDom;
namespace ICSharpCode.EasyCodeDom
{
public static class Easy
{
public static CodeTypeReference TypeRef(Type type)
{
return new CodeTypeReference(type, CodeTypeReferenceOptions.GlobalReference);
}
public static CodeTypeReference TypeRef(CodeTypeDeclaration type)
{
return new CodeTypeReference(type.Name);
}
public static CodeTypeReference TypeRef(string typeName, params string[] typeArguments)
{
CodeTypeReference tr = new CodeTypeReference(typeName);
foreach (string ta in typeArguments) {
tr.TypeArguments.Add(ta);
}
return tr;
}
/// <summary>
/// Gets the CodeExpression for any primitive value that can be expressed as literal.
/// Also works for enumeration values.
/// </summary>
public static CodeExpression Prim(object literalValue)
{
if (literalValue is Enum) {
return Type(literalValue.GetType()).Field(literalValue.ToString());
} else {
return new CodePrimitiveExpression(literalValue);
}
}
public static CodeTypeReferenceExpression Type(Type type)
{
return Type(TypeRef(type));
}
public static CodeTypeReferenceExpression Type(CodeTypeReference type)
{
return new CodeTypeReferenceExpression(type);
}
public static CodeTypeReferenceExpression Type(string type)
{
return Type(new CodeTypeReference(type));
}
public static CodeTypeOfExpression TypeOf(Type type)
{
return TypeOf(TypeRef(type));
}
public static CodeTypeOfExpression TypeOf(CodeTypeReference type)
{
return new CodeTypeOfExpression(type);
}
public static CodeObjectCreateExpression New(Type type, params CodeExpression[] arguments)
{
return New(TypeRef(type), arguments);
}
public static CodeObjectCreateExpression New(CodeTypeReference type, params CodeExpression[] arguments)
{
return new CodeObjectCreateExpression(type, arguments);
}
public static CodeVariableReferenceExpression Var(string name)
{
return new CodeVariableReferenceExpression(name);
}
public static CodeBinaryOperatorExpression Binary(CodeExpression left,
CodeBinaryOperatorType op,
CodeExpression right)
{
return new CodeBinaryOperatorExpression(left, op, right);
}
public static CodeThisReferenceExpression This {
get {
return new CodeThisReferenceExpression();
}
}
public static CodeBaseReferenceExpression Base {
get {
return new CodeBaseReferenceExpression();
}
}
public static CodePropertySetValueReferenceExpression Value {
get {
return new CodePropertySetValueReferenceExpression();
}
}
public static CodePrimitiveExpression Null {
get {
return new CodePrimitiveExpression(null);
}
}
public static void AddSummary(CodeTypeMember member, string summary)
{
member.Comments.Add(new CodeCommentStatement("<summary>", true));
member.Comments.Add(new CodeCommentStatement(summary, true));
member.Comments.Add(new CodeCommentStatement("</summary>", true));
}
internal static CodeAttributeDeclaration AddAttribute(CodeAttributeDeclarationCollection col,
CodeTypeReference type,
CodeExpression[] arguments)
{
CodeAttributeArgument[] attributeArguments = new CodeAttributeArgument[arguments.Length];
for (int i = 0; i < arguments.Length; i++) {
attributeArguments[i] = new CodeAttributeArgument(arguments[i]);
}
CodeAttributeDeclaration cad = new CodeAttributeDeclaration(type, attributeArguments);
col.Add(cad);
return cad;
}
}
public static class ExtensionMethods
{
public static CodeMethodInvokeExpression InvokeMethod(this CodeExpression expr, string name, params CodeExpression[] arguments)
{
return new CodeMethodInvokeExpression(expr, name, arguments);
}
public static CodeCastExpression CastTo(this CodeExpression expr, Type type)
{
return expr.CastTo(Easy.TypeRef(type));
}
public static CodeCastExpression CastTo(this CodeExpression expr, CodeTypeReference type)
{
return new CodeCastExpression(type, expr);
}
public static CodeIndexerExpression Index(this CodeExpression expr, params CodeExpression[] indices)
{
return new CodeIndexerExpression(expr, indices);
}
public static CodeFieldReferenceExpression Field(this CodeExpression expr, string name)
{
return new CodeFieldReferenceExpression(expr, name);
}
public static CodePropertyReferenceExpression Property(this CodeExpression expr, string name)
{
return new CodePropertyReferenceExpression(expr, name);
}
public static CodeNamespace AddNamespace(this CodeCompileUnit ccu, string name)
{
CodeNamespace n = new CodeNamespace(name);
ccu.Namespaces.Add(n);
return n;
}
public static CodeTypeDeclaration AddType(this CodeNamespace ns, string name)
{
CodeTypeDeclaration n = new CodeTypeDeclaration(name);
ns.Types.Add(n);
return n;
}
public static CodeNamespaceImport AddImport(this CodeNamespace ns, string nameSpace)
{
CodeNamespaceImport cni = new CodeNamespaceImport(nameSpace);
ns.Imports.Add(cni);
return cni;
}
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return typeDecl.AddField(Easy.TypeRef(type), name);
}
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
CodeMemberField f = new CodeMemberField(type, name);
typeDecl.Members.Add(f);
return f;
}
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return AddProperty(typeDecl, Easy.TypeRef(type), name);
}
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
EasyProperty p = new EasyProperty(type, name);
typeDecl.Members.Add(p);
if (typeDecl.IsInterface == false) {
p.Attributes = MemberAttributes.Public | MemberAttributes.Final;
}
return p;
}
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeMemberField field, string name)
{
EasyProperty p = AddProperty(typeDecl, field.Type, name);
p.Getter.Return(new CodeVariableReferenceExpression(field.Name));
p.Attributes |= field.Attributes & MemberAttributes.Static; // copy static flag
return p;
}
/// <summary>
/// Adds a method with return type <c>void</c> and attributes=Public|Final to this type.
/// </summary>
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, string name)
{
return AddMethod(typeDecl, Easy.TypeRef(typeof(void)), name);
}
/// <summary>
/// Adds a method with return type <paramref name="type"/> and attributes=Public|Final to this type.
/// </summary>
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return AddMethod(typeDecl, Easy.TypeRef(type), name);
}
/// <summary>
/// Adds a method with return type <paramref name="type"/> and attributes=Public|Final to this type.
/// </summary>
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
EasyMethod p = new EasyMethod(type, name);
typeDecl.Members.Add(p);
if (typeDecl.IsInterface == false) {
p.Attributes = MemberAttributes.Public | MemberAttributes.Final;
}
return p;
}
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, Type type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(typeMember.CustomAttributes, Easy.TypeRef(type), arguments);
}
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, CodeTypeReference type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(typeMember.CustomAttributes, type, arguments);
}
}
public class EasyProperty : CodeMemberProperty
{
EasyBlock getter, setter;
public EasyProperty()
{
getter = new EasyBlock(this.GetStatements);
setter = new EasyBlock(this.SetStatements);
}
public EasyProperty(CodeTypeReference type, string name) : this()
{
this.Type = type;
this.Name = name;
}
public EasyBlock Getter {
get { return getter; }
}
public EasyBlock Setter {
get { return setter; }
}
}
public class EasyMethod : CodeMemberMethod
{
EasyBlock body;
public EasyMethod()
{
body = new EasyBlock(this.Statements);
}
public EasyMethod(CodeTypeReference type, string name) : this()
{
this.ReturnType = type;
this.Name = name;
}
public CodeParameterDeclarationExpression AddParameter(Type type, string name)
{
return AddParameter(Easy.TypeRef(type), name);
}
public CodeParameterDeclarationExpression AddParameter(CodeTypeReference type, string name)
{
CodeParameterDeclarationExpression cpde;
cpde = new CodeParameterDeclarationExpression(type, name);
this.Parameters.Add(cpde);
return cpde;
}
public EasyBlock Body {
get { return body; }
}
}
public sealed class EasyBlock
{
readonly CodeStatementCollection csc;
public EasyBlock(CodeStatementCollection csc)
{
this.csc = csc;
}
public CodeMethodReturnStatement Return(CodeExpression expr)
{
CodeMethodReturnStatement st = new CodeMethodReturnStatement(expr);
csc.Add(st);
return st;
}
public CodeThrowExceptionStatement Throw(CodeExpression expr)
{
CodeThrowExceptionStatement st = new CodeThrowExceptionStatement(expr);
csc.Add(st);
return st;
}
public CodeAssignStatement Assign(CodeExpression lhs, CodeExpression rhs)
{
CodeAssignStatement st = new CodeAssignStatement(lhs, rhs);
csc.Add(st);
return st;
}
/// <summary>
/// Execute one expression as statement.
/// </summary>
public CodeExpressionStatement Add(CodeExpression expr)
{
CodeExpressionStatement st = new CodeExpressionStatement(expr);
csc.Add(st);
return st;
}
/// <summary>
/// Adds the statement.
/// </summary>
public CodeStatement Add(CodeStatement st)
{
csc.Add(st);
return st;
}
/// <summary>
/// Invoke a method on target as statement.
/// </summary>
public CodeExpressionStatement InvokeMethod(CodeExpression target, string name, params CodeExpression[] arguments)
{
return Add(new CodeMethodInvokeExpression(target, name, arguments));
}
/// <summary>
/// Declares a local variable.
/// </summary>
public CodeVariableDeclarationStatement DeclareVariable(Type type, string name)
{
return DeclareVariable(Easy.TypeRef(type), name);
}
/// <summary>
/// Declares a local variable.
/// </summary>
public CodeVariableDeclarationStatement DeclareVariable(CodeTypeReference type, string name)
{
CodeVariableDeclarationStatement st = new CodeVariableDeclarationStatement(type, name);
csc.Add(st);
return st;
}
}
}
Loading…
Cancel
Save