1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 namespace System.CodeDom 6 { 7 [Serializable] 8 public class CodeMemberMethod : CodeTypeMember 9 { 10 private readonly CodeParameterDeclarationExpressionCollection _parameters = new CodeParameterDeclarationExpressionCollection(); 11 private readonly CodeStatementCollection _statements = new CodeStatementCollection(); 12 private CodeTypeReference _returnType; 13 private CodeTypeReferenceCollection _implementationTypes = null; 14 private CodeAttributeDeclarationCollection _returnAttributes = null; 15 private CodeTypeParameterCollection _typeParameters; 16 17 private int _populated = 0x0; 18 private const int ParametersCollection = 0x1; 19 private const int StatementsCollection = 0x2; 20 private const int ImplTypesCollection = 0x4; 21 22 public event EventHandler PopulateParameters; 23 public event EventHandler PopulateStatements; 24 public event EventHandler PopulateImplementationTypes; 25 26 public CodeTypeReference ReturnType 27 { 28 get { return _returnType ?? (_returnType = new CodeTypeReference(typeof(void).FullName)); } 29 set { _returnType = value; } 30 } 31 32 public CodeStatementCollection Statements 33 { 34 get 35 { 36 if (0 == (_populated & StatementsCollection)) 37 { 38 _populated |= StatementsCollection; 39 PopulateStatements?.Invoke(this, EventArgs.Empty); 40 } 41 return _statements; 42 } 43 } 44 45 public CodeParameterDeclarationExpressionCollection Parameters 46 { 47 get 48 { 49 if (0 == (_populated & ParametersCollection)) 50 { 51 _populated |= ParametersCollection; 52 PopulateParameters?.Invoke(this, EventArgs.Empty); 53 } 54 return _parameters; 55 } 56 } 57 58 public CodeTypeReference PrivateImplementationType { get; set; } 59 60 public CodeTypeReferenceCollection ImplementationTypes 61 { 62 get 63 { 64 if (_implementationTypes == null) 65 { 66 _implementationTypes = new CodeTypeReferenceCollection(); 67 } 68 69 if (0 == (_populated & ImplTypesCollection)) 70 { 71 _populated |= ImplTypesCollection; 72 PopulateImplementationTypes?.Invoke(this, EventArgs.Empty); 73 } 74 75 return _implementationTypes; 76 } 77 } 78 79 public CodeAttributeDeclarationCollection ReturnTypeCustomAttributes => _returnAttributes ?? (_returnAttributes = new CodeAttributeDeclarationCollection()); 80 81 public CodeTypeParameterCollection TypeParameters => _typeParameters ?? (_typeParameters = new CodeTypeParameterCollection()); 82 } 83 } 84