Browse Source

Fixed SD2-783: GDI Handle leak

EasyCodeDom: use extension methods.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3722 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
1012755da5
  1. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs
  2. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs
  3. 38
      src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs
  4. 8
      src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj
  5. 1
      src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj
  6. 19
      src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs
  7. 24
      src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs
  8. 202
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs

3
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs

@ -142,8 +142,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -142,8 +142,7 @@ namespace ICSharpCode.FormsDesigner.Services
}
statements.Add(
new EasyExpression(extProvider)
.InvokeMethod(
extProvider.InvokeMethod(
"Set" + propDesc.Name,
targetObjectExpr,
propRefSource

2
src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs

@ -120,7 +120,7 @@ namespace NRefactoryASTGenerator @@ -120,7 +120,7 @@ namespace NRefactoryASTGenerator
ctd.Members.Add(prop);
}
if (implementation != NullableImplementation.Abstract) {
EasyTypeDeclaration newType = new EasyTypeDeclaration("Null" + ctd.Name);
CodeTypeDeclaration newType = new CodeTypeDeclaration("Null" + ctd.Name);
newType.TypeAttributes = TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Sealed;
newType.BaseTypes.Add(new CodeTypeReference(ctd.Name));
cns.Types.Add(newType);

38
src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs

@ -42,13 +42,13 @@ namespace NRefactoryASTGenerator @@ -42,13 +42,13 @@ namespace NRefactoryASTGenerator
}
nodeTypes.Sort(delegate(Type a, Type b) { return a.Name.CompareTo(b.Name); });
EasyCompileUnit ccu = new EasyCompileUnit();
EasyNamespace cns = ccu.AddNamespace("ICSharpCode.NRefactory.Ast");
CodeCompileUnit ccu = new CodeCompileUnit();
CodeNamespace cns = ccu.AddNamespace("ICSharpCode.NRefactory.Ast");
cns.AddImport("System");
cns.AddImport("System.Collections.Generic");
foreach (Type type in nodeTypes) {
if (type.GetCustomAttributes(typeof(CustomImplementationAttribute), false).Length == 0) {
EasyTypeDeclaration ctd = cns.AddType(type.Name);
CodeTypeDeclaration ctd = cns.AddType(type.Name);
if (type.IsAbstract) {
ctd.TypeAttributes |= TypeAttributes.Abstract;
}
@ -95,7 +95,7 @@ namespace NRefactoryASTGenerator @@ -95,7 +95,7 @@ namespace NRefactoryASTGenerator
File.WriteAllText(directory + "Generated.cs", writer.ToString());
}
ccu = new EasyCompileUnit();
ccu = new CodeCompileUnit();
cns = ccu.AddNamespace("ICSharpCode.NRefactory");
cns.AddImport("System");
cns.AddImport("ICSharpCode.NRefactory.Ast");
@ -106,7 +106,7 @@ namespace NRefactoryASTGenerator @@ -106,7 +106,7 @@ namespace NRefactoryASTGenerator
File.WriteAllText(visitorsDir + "../IAstVisitor.cs", writer.ToString());
}
ccu = new EasyCompileUnit();
ccu = new CodeCompileUnit();
cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors");
cns.AddImport("System");
cns.AddImport("System.Collections.Generic");
@ -119,7 +119,7 @@ namespace NRefactoryASTGenerator @@ -119,7 +119,7 @@ namespace NRefactoryASTGenerator
File.WriteAllText(visitorsDir + "AbstractAstVisitor.cs", writer.ToString());
}
ccu = new EasyCompileUnit();
ccu = new CodeCompileUnit();
cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors");
cns.AddImport("System");
cns.AddImport("System.Collections.Generic");
@ -132,7 +132,7 @@ namespace NRefactoryASTGenerator @@ -132,7 +132,7 @@ namespace NRefactoryASTGenerator
File.WriteAllText(visitorsDir + "AbstractAstTransformer.cs", writer.ToString());
}
ccu = new EasyCompileUnit();
ccu = new CodeCompileUnit();
cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors");
cns.AddImport("System");
cns.AddImport("ICSharpCode.NRefactory.Ast");
@ -146,7 +146,7 @@ namespace NRefactoryASTGenerator @@ -146,7 +146,7 @@ namespace NRefactoryASTGenerator
}
//NotImplementedAstVisitor
ccu = new EasyCompileUnit();
ccu = new CodeCompileUnit();
cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors");
cns.AddImport("System");
cns.AddImport("ICSharpCode.NRefactory.Ast");
@ -161,7 +161,7 @@ namespace NRefactoryASTGenerator @@ -161,7 +161,7 @@ namespace NRefactoryASTGenerator
static CodeTypeDeclaration CreateAstVisitorInterface(List<Type> nodeTypes)
{
EasyTypeDeclaration td = new EasyTypeDeclaration("IAstVisitor");
CodeTypeDeclaration td = new CodeTypeDeclaration("IAstVisitor");
td.IsInterface = true;
foreach (Type t in nodeTypes) {
@ -176,7 +176,7 @@ namespace NRefactoryASTGenerator @@ -176,7 +176,7 @@ namespace NRefactoryASTGenerator
static CodeTypeDeclaration CreateAstVisitorClass(List<Type> nodeTypes, bool transformer)
{
EasyTypeDeclaration td = new EasyTypeDeclaration(transformer ? "AbstractAstTransformer" : "AbstractAstVisitor");
CodeTypeDeclaration td = new CodeTypeDeclaration(transformer ? "AbstractAstTransformer" : "AbstractAstVisitor");
td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Abstract;
td.BaseTypes.Add(new CodeTypeReference("IAstVisitor"));
@ -191,7 +191,7 @@ namespace NRefactoryASTGenerator @@ -191,7 +191,7 @@ namespace NRefactoryASTGenerator
"or remove the current node, totally independent from the type of the parent node.";
Easy.AddSummary(td, comment);
EasyField field = td.AddField(Easy.TypeRef("Stack", "INode"), "nodeStack");
CodeMemberField field = td.AddField(Easy.TypeRef("Stack", "INode"), "nodeStack");
field.InitExpression = Easy.New(field.Type);
/*
@ -225,7 +225,7 @@ namespace NRefactoryASTGenerator @@ -225,7 +225,7 @@ namespace NRefactoryASTGenerator
List<CodeStatement> assertions = new List<CodeStatement>();
string varVariableName = GetFieldName(type.Name);
EasyExpression var = Easy.Var(varVariableName);
CodeExpression var = Easy.Var(varVariableName);
assertions.Add(AssertIsNotNull(var));
AddFieldVisitCode(m, type, var, assertions, transformer);
@ -258,7 +258,7 @@ namespace NRefactoryASTGenerator @@ -258,7 +258,7 @@ namespace NRefactoryASTGenerator
return td;
}
static void AddFieldVisitCode(EasyMethod m, Type type, EasyExpression var, List<CodeStatement> assertions, bool transformer)
static void AddFieldVisitCode(EasyMethod m, Type type, CodeExpression var, List<CodeStatement> assertions, bool transformer)
{
if (type != null) {
if (type.BaseType != typeof(StatementWithEmbeddedStatement)) {
@ -309,10 +309,10 @@ namespace NRefactoryASTGenerator @@ -309,10 +309,10 @@ namespace NRefactoryASTGenerator
"\t\t\t}";
}
static bool AddVisitCode(EasyMethod m, FieldInfo field, EasyExpression var, List<CodeStatement> assertions, bool transformer)
static bool AddVisitCode(EasyMethod m, FieldInfo field, CodeExpression var, List<CodeStatement> assertions, bool transformer)
{
EasyExpression prop = var.Property(GetPropertyName(field.Name));
EasyExpression nodeStack = Easy.Var("nodeStack");
CodeExpression prop = var.Property(GetPropertyName(field.Name));
CodeExpression nodeStack = Easy.Var("nodeStack");
if (field.FieldType.FullName.StartsWith("System.Collections.Generic.List")) {
Type elType = field.FieldType.GetGenericArguments()[0];
if (!typeof(INode).IsAssignableFrom(elType))
@ -376,7 +376,7 @@ namespace NRefactoryASTGenerator @@ -376,7 +376,7 @@ namespace NRefactoryASTGenerator
// Body);
}
static void ProcessType(Type type, EasyTypeDeclaration ctd)
static void ProcessType(Type type, CodeTypeDeclaration ctd)
{
foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)) {
ctd.AddField(ConvertType(field.FieldType), field.Name).Attributes = 0;
@ -494,7 +494,7 @@ namespace NRefactoryASTGenerator @@ -494,7 +494,7 @@ namespace NRefactoryASTGenerator
static CodeTypeDeclaration CreateNodeTrackingAstVisitorClass(List<Type> nodeTypes)
{
EasyTypeDeclaration td = new EasyTypeDeclaration("NodeTrackingAstVisitor");
CodeTypeDeclaration td = new CodeTypeDeclaration("NodeTrackingAstVisitor");
td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Abstract;
td.BaseTypes.Add(new CodeTypeReference("AbstractAstVisitor"));
@ -554,7 +554,7 @@ namespace NRefactoryASTGenerator @@ -554,7 +554,7 @@ namespace NRefactoryASTGenerator
static CodeTypeDeclaration CreateNotImplementedAstVisitorClass(List<Type> nodeTypes)
{
EasyTypeDeclaration td = new EasyTypeDeclaration("NotImplementedAstVisitor");
CodeTypeDeclaration td = new CodeTypeDeclaration("NotImplementedAstVisitor");
td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class;
td.BaseTypes.Add(new CodeTypeReference("IAstVisitor"));

8
src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>NRefactoryASTGenerator</RootNamespace>
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
@ -35,6 +36,9 @@ @@ -35,6 +36,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
@ -55,4 +59,4 @@ @@ -55,4 +59,4 @@
<Folder Include="AST" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
</Project>

1
src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj

@ -73,6 +73,7 @@ @@ -73,6 +73,7 @@
<Compile Include="ToolBar\ToolBarSplitButton.cs" />
<Compile Include="ToolBar\ToolBarTextBox.cs" />
<Compile Include="Util\ClipboardWrapper.cs" />
<Compile Include="Util\NativeMethods.cs" />
<Compile Include="Util\RightToLeftConverter.cs" />
<Compile Include="WinFormsResourceService.cs" />
</ItemGroup>

19
src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Runtime.InteropServices;
namespace ICSharpCode.Core.WinForms
{
static class NativeMethods
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyIcon(IntPtr handle);
}
}

24
src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs

@ -173,13 +173,35 @@ namespace ICSharpCode.Core.WinForms @@ -173,13 +173,35 @@ namespace ICSharpCode.Core.WinForms
if (iconobj is Icon) {
ico = (Icon)iconobj;
} else {
ico = Icon.FromHandle(((Bitmap)iconobj).GetHicon());
ico = BitmapToIcon((Bitmap)iconobj);
}
iconCache[name] = ico;
return ico;
}
}
/// <summary>
/// Converts a bitmap into an icon.
/// </summary>
public static Icon BitmapToIcon(Bitmap bmp)
{
IntPtr hIcon = bmp.GetHicon();
try {
using (Icon tempIco = Icon.FromHandle(hIcon)) {
// Icon.FromHandle creates a Icon object that uses the HIcon but does
// not own it. We could leak HIcons on language changes.
// We have no idea when we may dispose the icons after a language change
// (they could still be used), so we'll have to create an owned icon.
// Unfortunately, there's no Icon.FromHandle(IntPtr,bool takeOwnership) method.
// We could use reflection to set the ownHandle field; or we create a copy of the icon
// and immediately destroy the original
return new Icon(tempIco, tempIco.Width, tempIco.Height);
} // dispose tempico, doesn't do much because the icon isn't owned
} finally {
NativeMethods.DestroyIcon(hIcon);
}
}
/// <summary>
/// Returns a bitmap from the resource database, it handles localization
/// transparent for the user.

202
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs

@ -30,82 +30,82 @@ namespace ICSharpCode.EasyCodeDom @@ -30,82 +30,82 @@ namespace ICSharpCode.EasyCodeDom
}
/// <summary>
/// Gets the EasyExpression for any primitive value that can be expressed as literal.
/// Gets the CodeExpression for any primitive value that can be expressed as literal.
/// Also works for enumeration values.
/// </summary>
public static EasyExpression Prim(object literalValue)
public static CodeExpression Prim(object literalValue)
{
if (literalValue is Enum) {
return Type(literalValue.GetType()).Field(literalValue.ToString());
} else {
return new EasyExpression(new CodePrimitiveExpression(literalValue));
return new CodePrimitiveExpression(literalValue);
}
}
public static EasyExpression Type(Type type)
public static CodeTypeReferenceExpression Type(Type type)
{
return Type(TypeRef(type));
}
public static EasyExpression Type(CodeTypeReference type)
public static CodeTypeReferenceExpression Type(CodeTypeReference type)
{
return new EasyExpression(new CodeTypeReferenceExpression(type));
return new CodeTypeReferenceExpression(type);
}
public static EasyExpression Type(string type)
public static CodeTypeReferenceExpression Type(string type)
{
return Type(new CodeTypeReference(type));
}
public static EasyExpression TypeOf(Type type)
public static CodeTypeOfExpression TypeOf(Type type)
{
return TypeOf(TypeRef(type));
}
public static EasyExpression TypeOf(CodeTypeReference type)
public static CodeTypeOfExpression TypeOf(CodeTypeReference type)
{
return new EasyExpression(new CodeTypeOfExpression(type));
return new CodeTypeOfExpression(type);
}
public static EasyExpression New(Type type, params CodeExpression[] arguments)
public static CodeObjectCreateExpression New(Type type, params CodeExpression[] arguments)
{
return New(TypeRef(type), arguments);
}
public static EasyExpression New(CodeTypeReference type, params CodeExpression[] arguments)
public static CodeObjectCreateExpression New(CodeTypeReference type, params CodeExpression[] arguments)
{
return new EasyExpression(new CodeObjectCreateExpression(type, arguments));
return new CodeObjectCreateExpression(type, arguments);
}
public static EasyExpression Var(string name)
public static CodeVariableReferenceExpression Var(string name)
{
return new EasyExpression(new CodeVariableReferenceExpression(name));
return new CodeVariableReferenceExpression(name);
}
public static EasyExpression Binary(CodeExpression left,
CodeBinaryOperatorType op,
CodeExpression right)
public static CodeBinaryOperatorExpression Binary(CodeExpression left,
CodeBinaryOperatorType op,
CodeExpression right)
{
return new EasyExpression(new CodeBinaryOperatorExpression(left, op, right));
return new CodeBinaryOperatorExpression(left, op, right);
}
public static EasyExpression This {
public static CodeThisReferenceExpression This {
get {
return new EasyExpression(new CodeThisReferenceExpression());
return new CodeThisReferenceExpression();
}
}
public static EasyExpression Base {
public static CodeBaseReferenceExpression Base {
get {
return new EasyExpression(new CodeBaseReferenceExpression());
return new CodeBaseReferenceExpression();
}
}
public static EasyExpression Value {
public static CodePropertySetValueReferenceExpression Value {
get {
return new EasyExpression(new CodePropertySetValueReferenceExpression());
return new CodePropertySetValueReferenceExpression();
}
}
public static EasyExpression Null {
public static CodePrimitiveExpression Null {
get {
return new EasyExpression(new CodePrimitiveExpression(null));
return new CodePrimitiveExpression(null);
}
}
@ -130,122 +130,86 @@ namespace ICSharpCode.EasyCodeDom @@ -130,122 +130,86 @@ namespace ICSharpCode.EasyCodeDom
}
}
public sealed class EasyExpression
public static class ExtensionMethods
{
readonly CodeExpression expr;
public EasyExpression(CodeExpression expr)
public static CodeMethodInvokeExpression InvokeMethod(this CodeExpression expr, string name, params CodeExpression[] arguments)
{
this.expr = expr;
return new CodeMethodInvokeExpression(expr, name, arguments);
}
public static implicit operator CodeExpression(EasyExpression expr)
public static CodeCastExpression CastTo(this CodeExpression expr, Type type)
{
return expr.expr;
return expr.CastTo(Easy.TypeRef(type));
}
public EasyExpression InvokeMethod(string name, params CodeExpression[] arguments)
public static CodeCastExpression CastTo(this CodeExpression expr, CodeTypeReference type)
{
return new EasyExpression(new CodeMethodInvokeExpression(expr, name, arguments));
return new CodeCastExpression(type, expr);
}
public EasyExpression CastTo(Type type)
public static CodeIndexerExpression Index(this CodeExpression expr, params CodeExpression[] indices)
{
return CastTo(Easy.TypeRef(type));
}
public EasyExpression CastTo(CodeTypeReference type)
{
return new EasyExpression(new CodeCastExpression(type, expr));
return new CodeIndexerExpression(expr, indices);
}
public EasyExpression Index(params CodeExpression[] indices)
public static CodeFieldReferenceExpression Field(this CodeExpression expr, string name)
{
return new EasyExpression(new CodeIndexerExpression(expr, indices));
return new CodeFieldReferenceExpression(expr, name);
}
public EasyExpression Field(string name)
public static CodePropertyReferenceExpression Property(this CodeExpression expr, string name)
{
return new EasyExpression(new CodeFieldReferenceExpression(expr, name));
return new CodePropertyReferenceExpression(expr, name);
}
public EasyExpression Property(string name)
{
return new EasyExpression(new CodePropertyReferenceExpression(expr, name));
}
}
public class EasyCompileUnit : CodeCompileUnit
{
public EasyNamespace AddNamespace(string name)
public static CodeNamespace AddNamespace(this CodeCompileUnit ccu, string name)
{
EasyNamespace n = new EasyNamespace(name);
this.Namespaces.Add(n);
CodeNamespace n = new CodeNamespace(name);
ccu.Namespaces.Add(n);
return n;
}
}
public class EasyNamespace : CodeNamespace
{
public EasyNamespace() : base() {}
public EasyNamespace(string name) : base(name) {}
public EasyTypeDeclaration AddType(string name)
public static CodeTypeDeclaration AddType(this CodeNamespace ns, string name)
{
EasyTypeDeclaration n = new EasyTypeDeclaration(name);
this.Types.Add(n);
CodeTypeDeclaration n = new CodeTypeDeclaration(name);
ns.Types.Add(n);
return n;
}
public CodeNamespaceImport AddImport(string nameSpace)
public static CodeNamespaceImport AddImport(this CodeNamespace ns, string nameSpace)
{
CodeNamespaceImport cni = new CodeNamespaceImport(nameSpace);
this.Imports.Add(cni);
ns.Imports.Add(cni);
return cni;
}
}
public class EasyTypeDeclaration : CodeTypeDeclaration
{
public EasyTypeDeclaration() : base() {}
public EasyTypeDeclaration(string name) : base(name) {}
public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments)
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments);
return typeDecl.AddField(Easy.TypeRef(type), name);
}
public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments)
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
return Easy.AddAttribute(this.CustomAttributes, type, arguments);
}
public EasyField AddField(Type type, string name)
{
return AddField(Easy.TypeRef(type), name);
}
public EasyField AddField(CodeTypeReference type, string name)
{
EasyField f = new EasyField(type, name);
this.Members.Add(f);
CodeMemberField f = new CodeMemberField(type, name);
typeDecl.Members.Add(f);
return f;
}
public EasyProperty AddProperty(Type type, string name)
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return AddProperty(Easy.TypeRef(type), name);
return AddProperty(typeDecl, Easy.TypeRef(type), name);
}
public EasyProperty AddProperty(CodeTypeReference type, string name)
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
EasyProperty p = new EasyProperty(type, name);
this.Members.Add(p);
if (this.IsInterface == false) {
typeDecl.Members.Add(p);
if (typeDecl.IsInterface == false) {
p.Attributes = MemberAttributes.Public | MemberAttributes.Final;
}
return p;
}
public EasyProperty AddProperty(CodeMemberField field, string name)
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeMemberField field, string name)
{
EasyProperty p = AddProperty(field.Type, 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;
@ -254,43 +218,37 @@ namespace ICSharpCode.EasyCodeDom @@ -254,43 +218,37 @@ namespace ICSharpCode.EasyCodeDom
/// <summary>
/// Adds a method with return type <c>void</c> and attributes=Public|Final to this type.
/// </summary>
public EasyMethod AddMethod(string name)
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, string name)
{
return AddMethod(Easy.TypeRef(typeof(void)), 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 EasyMethod AddMethod(Type type, string name)
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, Type type, string name)
{
return AddMethod(Easy.TypeRef(type), 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 EasyMethod AddMethod(CodeTypeReference type, string name)
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name)
{
EasyMethod p = new EasyMethod(type, name);
this.Members.Add(p);
if (this.IsInterface == false) {
typeDecl.Members.Add(p);
if (typeDecl.IsInterface == false) {
p.Attributes = MemberAttributes.Public | MemberAttributes.Final;
}
return p;
}
}
public class EasyField : CodeMemberField
{
public EasyField() : base() {}
public EasyField(CodeTypeReference type, string name) : base(type, name) {}
public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments)
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, Type type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments);
return Easy.AddAttribute(typeMember.CustomAttributes, Easy.TypeRef(type), arguments);
}
public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments)
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, CodeTypeReference type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, type, arguments);
return Easy.AddAttribute(typeMember.CustomAttributes, type, arguments);
}
}
@ -310,15 +268,6 @@ namespace ICSharpCode.EasyCodeDom @@ -310,15 +268,6 @@ namespace ICSharpCode.EasyCodeDom
this.Name = name;
}
public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments);
}
public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, type, arguments);
}
public EasyBlock Getter {
get { return getter; }
}
@ -343,15 +292,6 @@ namespace ICSharpCode.EasyCodeDom @@ -343,15 +292,6 @@ namespace ICSharpCode.EasyCodeDom
this.Name = name;
}
public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments);
}
public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments)
{
return Easy.AddAttribute(this.CustomAttributes, type, arguments);
}
public CodeParameterDeclarationExpression AddParameter(Type type, string name)
{
return AddParameter(Easy.TypeRef(type), name);

Loading…
Cancel
Save