CodeReferenceExpression.cs :  » Development » devAdvantage » AnticipatingMinds » Genesis » CodeDOM » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » devAdvantage 
devAdvantage » AnticipatingMinds » Genesis » CodeDOM » CodeReferenceExpression.cs
using System;

namespace AnticipatingMinds.Genesis.CodeDOM{

  /// <summary>
  /// Represents a reference expression.
  /// </summary>
  [Serializable]
  public abstract class CodeReferenceExpression : CodeExpression
  {
  }

  /// <summary>
  /// Represents a reference to a method parameter.
  /// </summary>
  [Serializable]
  public class CodeMethodParameterReferenceExpression : CodeReferenceExpression
  {
    /// <summary>
    /// Method parameter declaration.
    /// </summary>
    public CodeMethodParameter  MethodParameter
    {
      get
      {
        return methodParameter;
      }
      set
      {
        methodParameter = value;
      }
    }

    /// <summary>
    /// Gets parameter name.
    /// </summary>
    public string ParameterName
    {
      get
      {
        return methodParameter.Name;
      }
      set
      {
        methodParameter.Name = value;
      }
    }

    private CodeMethodParameter  methodParameter;
  }

  /// <summary>
  /// Represents reference to the base class.
  /// </summary>
  [Serializable]
  public class CodeBaseReferenceExpression : CodeReferenceExpression
  {
  }
  
  /// <summary>
  /// Represents reference to the current class.
  /// </summary>
  [Serializable]
  public class CodeThisReferenceExpression : CodeReferenceExpression
  {
  }

  /// <summary>
  /// Represents reference to the null (Nothing) constant.
  /// </summary>
  [Serializable]
  public class CodeNullReferenceExpression : CodeReferenceExpression
  {
  }

  /// <summary>
  /// Represents reference to a type.
  /// </summary>
  [Serializable]
  public class CodeTypeReferenceExpression : CodeReferenceExpression
  {
    /// <summary>
    /// Initialize new instance of <see cref="CodeTypeReferenceExpression"/> class.
    /// </summary>
    public CodeTypeReferenceExpression():this((CodeTypeReference) null){}
    /// <summary>
    /// Initialize new instance of <see cref="CodeTypeReferenceExpression"/> class.
    /// </summary>
    /// <param name="typeName">Name of the type being referenced in expression.</param>
    public CodeTypeReferenceExpression(string typeName):this(new CodeTypeReference(typeName)){}
    /// <summary>
    /// Initialize new instance of <see cref="CodeTypeReferenceExpression"/> class.
    /// </summary>
    /// <param name="referencedType">Reference to the type being referenced in expression.</param>
    public CodeTypeReferenceExpression(CodeTypeReference referencedType):base()
    {
      this.referencedType = referencedType;
    }
    /// <summary>
    /// Gets or sets type being referenced in expression.
    /// </summary>
    public CodeTypeReference ReferencedType
    {
      get
      {
        return referencedType;
      }
      set
      {
        referencedType = value;
      }

    }

    private CodeTypeReference referencedType;
  }
  
  /// <summary>
  /// Represents reference to a variable.
  /// </summary>
  [Serializable]
  public class CodeVariableReferenceExpression : CodeReferenceExpression
  {
    /// <summary>
    /// Initialize new instance of <see cref="CodeVariableReferenceExpression"/> class.
    /// </summary>
    public CodeVariableReferenceExpression():this(string.Empty,null)
    {
    }
    /// <summary>
    /// Initialize new instance of <see cref="CodeVariableReferenceExpression"/> class.
    /// </summary>
    /// <param name="variableName"></param>
    /// <param name="variableDeclaration"></param>
    public CodeVariableReferenceExpression(string variableName,CodeVariableDeclarationStatement variableDeclaration)
    {
      name = variableName;
      referencedVariable = variableDeclaration;
    }

    /// <summary>
    /// Gets or sets declaration of the referenced variable.
    /// </summary>
    public CodeVariableDeclarationStatement VariableDeclaration
    {
      get
      {
        return referencedVariable;
      }
      set
      {
        referencedVariable = value;
      }
    }
    /// <summary>
    /// Gets or sets name of the referenced variable.
    /// </summary>
    public string VariableName
    {
      get
      {
        return name;
      }
      set
      {
        name = value;
      }
    }


    private CodeVariableDeclarationStatement  referencedVariable;
    private string name;
  }

  /// <summary>
  /// Represents base class for any named reference.
  /// </summary>
  [Serializable]
  public abstract class CodeNamedReferenceExpression : CodeReferenceExpression
  {

    /// <summary>
    /// Initialize new instance of <see cref="CodeNamedReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetExpression">Expression that leads (targets) current reference.</param>
    /// <param name="name">Name of the reference. For example property name.</param>
    protected CodeNamedReferenceExpression(CodeExpression targetExpression,string name)
    {
      this.target = targetExpression;
      this.name = name;
    }
    /// <summary>
    /// Initialize new instance of <see cref="CodeNamedReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetExpression">Expression that leads (targets) current reference.</param>
    protected CodeNamedReferenceExpression(CodeExpression targetExpression):this(targetExpression,string.Empty)
    {
    }
    /// <summary>
    /// Initialize new instance of <see cref="CodeNamedReferenceExpression"/> class.
    /// </summary>
    /// <param name="name">Name of the reference. For example property name.</param>
    protected CodeNamedReferenceExpression(string name):this(null,name)
    {
    }
    /// <summary>
    /// Initialize new instance of <see cref="CodeNamedReferenceExpression"/> class.
    /// </summary>
    protected CodeNamedReferenceExpression():this(null,string.Empty)
    {
    }
    /// <summary>
    /// Gets or sets the the expression that leads (targets) current reference.
    /// </summary>
    /// <remarks>
    /// For example call tho the function this.foo() will be represented as 
    /// named reference to the method foo where target object will be <see cref="CodeThisReferenceExpression"/>.
    /// </remarks>
    public CodeExpression TargetObject
    {
      get
      {
        return target;
      }
      set
      {
        target = value;
      }
    }

    /// <summary>
    /// Referenced name.
    /// </summary>
    public string Name
    {
      get
      {
        return name;
      }
      set
      {
        name = value == null ? string.Empty : value;
      }
    }

    public override object Clone()
    {
      //In the case of reference expression clone all the target expressions as well - 
      //hence preserving the chain on new instances.
      CodeNamedReferenceExpression namedReferenceExpressionClone =  base.Clone() as CodeNamedReferenceExpression;
      if(namedReferenceExpressionClone.TargetObject != null)
        namedReferenceExpressionClone.TargetObject = namedReferenceExpressionClone.TargetObject.Clone() as CodeExpression;
      return namedReferenceExpressionClone;
    }


    private string name;
    private CodeExpression target;
  }

  
  /// <summary>
  /// Represents a reference to a event.
  /// </summary>
  /// <remarks>This class represents a reference to an event member of the same or different class.</remarks>
  [Serializable]
  public class CodeEventReferenceExpression : CodeNamedReferenceExpression
  {
    /// <summary>
    /// Initializes new instance of the <see cref="CodeEventReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member referenced event is.</param>
    /// <param name="eventName">Name of the referenced event.</param>
    public CodeEventReferenceExpression(CodeExpression targetObject,string eventName):base(targetObject,eventName)
    {
    }

    /// <summary>
    /// Gets or sets a code metadata information about referenced Event.
    /// </summary>
    /// <value>The value can be null if code metadata information is not available.</value>
    public CodeEventInfo EventInfo
    {
      get
      {
        return eventInfo;
      }
      set
      {
        eventInfo = value;
      }
    }

    private CodeEventInfo eventInfo;
  }
  
  /// <summary>
  /// Represents a reference to a field.
  /// </summary>
  /// <remarks>This class represents a reference to a field member of the same or different class.</remarks>
  [Serializable]
  public class CodeFieldReferenceExpression : CodeNamedReferenceExpression
  {

    /// <summary>
    /// Initializes new instance of the <see cref="CodeFieldReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member referenced field is.</param>
    /// <param name="fieldName">Name of the referenced field.</param>
    public CodeFieldReferenceExpression(CodeExpression targetObject,string fieldName):base(targetObject,fieldName)
    {
    }

    /// <summary>
    /// Gets or sets a code metadata information about referenced field.
    /// </summary>
    /// <value>The value can be null if code metadata information is not available.</value>
    public CodeFieldInfo FieldInfo
    {
      get
      {
        return fieldInfo;
      }
      set
      {
        fieldInfo = value;
      }
    }

    private CodeFieldInfo fieldInfo;
  }

  /// <summary>
  /// Represents a reference to a method.
  /// </summary>
  [Serializable]
  public class CodeMethodReferenceExpression : CodeNamedReferenceExpression
  {
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    public CodeMethodReferenceExpression():this(null,string.Empty)
    {
    }
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member referenced method is.</param>
    /// <param name="methodName">Name of the referenced method.</param>
    public CodeMethodReferenceExpression(CodeExpression targetObject,string methodName):base(targetObject,methodName)
    {
    }

    /// <summary>
    /// Gets or sets a code metadata information about referenced method.
    /// </summary>
    /// <value>The value can be null if code metadata information is not available.</value>
    public CodeMethodInfo MethodInfo
    {
      get
      {
        return methodInfo;
      }
      set
      {
        methodInfo = value;
      }
    }
    
    private CodeMethodInfo methodInfo;
  }
  
  /// <summary>
  /// Represents a reference to a property.
  /// </summary>
  [Serializable]
  public class CodePropertyReferenceExpression : CodeNamedReferenceExpression
  {
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member referenced method is.</param>
    /// <param name="propertyName">Name of the referenced property.</param>
    public CodePropertyReferenceExpression(CodeExpression targetObject,string propertyName):base(targetObject,propertyName)
    {
    }

    /// <summary>
    /// Gets or sets a code metadata information about referenced property.
    /// </summary>
    /// <value>The value can be null if code metadata information is not available.</value>
    public CodePropertyInfo PropertyInfo
    {
      get
      {
        return propertyInfo;
      }
      set
      {
        propertyInfo = value;
      }
    }

    private CodePropertyInfo propertyInfo;
  }


  /// <summary>
  /// Represents uresolved named reference.
  /// </summary>
  /// <remarks>
  /// <para>
  ///    During the first pass parsr cannot distingush between properties and fields.
  /// </para>
  /// <para>
  /// For example expression foo.A can be a reference to a property or a field named 'A'.
  /// This is why A is represented as <see cref="CodeUnresolvedReferenceExpression"/>. Later
  /// When parser builds code metadata information and resolves types of target objects
  /// parser will replace this expression with correct <see cref="CodePropertyReferenceExpression"/> or 
  /// <see cref="CodeFieldReferenceExpression"/> object.
  /// </para>
  /// </remarks>
  [Serializable]
  public class CodeUnresolvedReferenceExpression : CodeNamedReferenceExpression
  {
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member is referenced.</param>
    /// <param name="name">Name of the referenced member.</param>
    public CodeUnresolvedReferenceExpression(CodeExpression targetObject,string name):base(targetObject,name){}
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    /// <param name="targetObject">An expression that resolves to a type or an instance of a type whose member is referenced.</param>
    public CodeUnresolvedReferenceExpression(CodeExpression targetObject):this(targetObject,string.Empty){}
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    /// <param name="name">Name of the referenced member.</param>
    public CodeUnresolvedReferenceExpression(string name):this(null,name){}
    /// <summary>
    /// Initializes new instance of the <see cref="CodeMethodReferenceExpression"/> class.
    /// </summary>
    public CodeUnresolvedReferenceExpression():this(null,string.Empty){}
  }

}  

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.