From 1012755da5f48b0155a29dc936597653e133c0ea Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 27 Dec 2008 21:38:15 +0000 Subject: [PATCH] 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 --- ...ProjectResourcesMemberCodeDomSerializer.cs | 3 +- .../NRefactoryASTGenerator/Attributes.cs | 2 +- .../NRefactory/NRefactoryASTGenerator/Main.cs | 38 ++-- .../NRefactoryASTGenerator.csproj | 8 +- .../ICSharpCode.Core.WinForms.csproj | 1 + .../Util/NativeMethods.cs | 19 ++ .../WinFormsResourceService.cs | 24 ++- .../Project/Src/EasyCodeDom.cs | 202 ++++++------------ 8 files changed, 141 insertions(+), 156 deletions(-) create mode 100644 src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs index 7beb6884c5..24d35023a3 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesMemberCodeDomSerializer.cs @@ -142,8 +142,7 @@ namespace ICSharpCode.FormsDesigner.Services } statements.Add( - new EasyExpression(extProvider) - .InvokeMethod( + extProvider.InvokeMethod( "Set" + propDesc.Name, targetObjectExpr, propRefSource diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs index b0c9631c7a..4c47086ab4 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs @@ -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); diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs b/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs index 6d32bb4462..bb309b359d 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs @@ -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 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 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 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 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 } //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 static CodeTypeDeclaration CreateAstVisitorInterface(List 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 static CodeTypeDeclaration CreateAstVisitorClass(List 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 "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 List assertions = new List(); 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 return td; } - static void AddFieldVisitCode(EasyMethod m, Type type, EasyExpression var, List assertions, bool transformer) + static void AddFieldVisitCode(EasyMethod m, Type type, CodeExpression var, List assertions, bool transformer) { if (type != null) { if (type.BaseType != typeof(StatementWithEmbeddedStatement)) { @@ -309,10 +309,10 @@ namespace NRefactoryASTGenerator "\t\t\t}"; } - static bool AddVisitCode(EasyMethod m, FieldInfo field, EasyExpression var, List assertions, bool transformer) + static bool AddVisitCode(EasyMethod m, FieldInfo field, CodeExpression var, List 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 // 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 static CodeTypeDeclaration CreateNodeTrackingAstVisitorClass(List 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 static CodeTypeDeclaration CreateNotImplementedAstVisitorClass(List nodeTypes) { - EasyTypeDeclaration td = new EasyTypeDeclaration("NotImplementedAstVisitor"); + CodeTypeDeclaration td = new CodeTypeDeclaration("NotImplementedAstVisitor"); td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class; td.BaseTypes.Add(new CodeTypeReference("IAstVisitor")); diff --git a/src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj b/src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj index 0522d181bc..d95bf39e97 100644 --- a/src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj +++ b/src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj @@ -1,4 +1,4 @@ - + Exe NRefactoryASTGenerator @@ -16,6 +16,7 @@ 4 0169 false + v3.5 bin\Debug\ @@ -35,6 +36,9 @@ + + 3.5 + @@ -55,4 +59,4 @@ - \ No newline at end of file + diff --git a/src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj b/src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj index 4f73e0dec3..efab108000 100644 --- a/src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj +++ b/src/Main/ICSharpCode.Core.WinForms/ICSharpCode.Core.WinForms.csproj @@ -73,6 +73,7 @@ + diff --git a/src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs b/src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs new file mode 100644 index 0000000000..5b73498802 --- /dev/null +++ b/src/Main/ICSharpCode.Core.WinForms/Util/NativeMethods.cs @@ -0,0 +1,19 @@ +// +// +// +// +// $Revision$ +// + +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); + } +} diff --git a/src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs b/src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs index 0fe88843d6..8e6d42412f 100644 --- a/src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs +++ b/src/Main/ICSharpCode.Core.WinForms/WinFormsResourceService.cs @@ -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; } } + /// + /// Converts a bitmap into an icon. + /// + 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); + } + } + /// /// Returns a bitmap from the resource database, it handles localization /// transparent for the user. diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs index 317285a7dd..ad19025d55 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/EasyCodeDom.cs @@ -30,82 +30,82 @@ namespace ICSharpCode.EasyCodeDom } /// - /// 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. /// - 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 } } - 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 /// /// Adds a method with return type void and attributes=Public|Final to this type. /// - 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); } /// /// Adds a method with return type and attributes=Public|Final to this type. /// - 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); } /// /// Adds a method with return type and attributes=Public|Final to this type. /// - 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 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 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);