Field.cs :  » Aspect-Oriented-Frameworks » Runtime-Assembly-Instrumentation-Library » rail » Reflect » 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 » Aspect Oriented Frameworks » Runtime Assembly Instrumentation Library 
Runtime Assembly Instrumentation Library » rail » Reflect » Field.cs
/*
  The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
  you may not use this file except in compliance with the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  Software distributed under the License is distributed on an "AS IS" basis, 
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language 
  governing rights and limitations under the License. 

  The Original Code is RAIL(Runtime Assembly Instrumentation Library) Alpha Version.
  The Initial Developer of the Original Code is University of Coimbra,
  Computer Science Department, Dependable Systems Group. Copyright (C) University of Coimbra. 
  All Rights Reserved.  
*/
using System;
using System.Reflection;
using Rail.Transformation;

namespace Rail.Reflect{
  /// <summary>
  /// 
  /// TODO: A nice way to initialize the field and change its value.
  /// Possible kind of values:
  ///   - not initialized
  ///   - null
  ///   - constant
  ///   - expression
  ///   - method call (probably only static methods)
  ///   - new object/array
  /// </summary>
  public abstract class RField : RMember 
  {
    #region fields
    /// <summary>
    /// 
    /// </summary>
    protected FieldAttributes attributes;
    /// <summary>
    /// 
    /// </summary>
    protected RType fieldType;
    /// <summary>
    /// 
    /// </summary>
    protected Object fieldValue;
    /// <summary>
    /// 
    /// </summary>
    protected MarshalSpec marshalSpec;

    #endregion
    
    /// <summary>
    /// Verify if the field has marshal information
    /// </summary>
    public bool HasMarshal
    {
      get
      {
        return this.marshalSpec!=null;
      }
    }
    
    /// <summary>
    /// Get the field marshaling information
    /// </summary>
    public virtual MarshalSpec MarshalSpec
    {
      get
      {
        return this.marshalSpec;
      }
      set
      {
        throw new NotSupportedException();
      }
    }
    /// <summary>
    /// Gets the attributes for this field
    /// </summary>
    public virtual FieldAttributes Attributes 
    {
      get 
      {
        return this.attributes;
      }
      set 
      {
        throw new NotSupportedException();
      }
    }

    /// <summary>
    /// Gets or sets the type of this field
    /// </summary>
    public virtual RType FieldType 
    {
      get 
      {
        return this.fieldType;
      }
      set 
      {
        throw new NotSupportedException();
      }
    }

    /// <summary>
    /// 
    /// </summary>
    public virtual Object Value
    {
      set
      {
        throw new NotSupportedException();
      }
      get
      {
        return this.fieldValue;
      }
    }
  }

  /// <summary>
  /// 
  /// </summary>
  public class RFieldRef : RField 
  {
    #region fields
    /// <summary>
    /// 
    /// </summary>
    private RAssemblyDef rad;
    #endregion
    /// <summary>
    /// 
    /// </summary>
    /// <param name="fi"></param>
    /// <param name="rad"></param>
    internal RFieldRef(FieldInfo fi,RAssemblyDef rad) 
    {      
      this.rad = rad;
      this.attributes = fi.Attributes;
      this.declaringType = rad.GetRTypeRef(fi.DeclaringType);
      this.fieldType = rad.GetRTypeRef(fi.FieldType);
      this.memberType = fi.MemberType;
      this.name = fi.Name;
      //TODO: Set the field value
      //this.fieldValue = fi.FieldType.
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="declaringType"></param>
    /// <param name="fieldType"></param>
    /// <param name="rad"></param>
    internal RFieldRef(string name,RTypeRef declaringType,RType fieldType,RAssemblyDef rad)
    {
      this.rad = rad;
      this.attributes = (FieldAttributes)0;
      this.declaringType = declaringType;
      this.fieldType = fieldType;
      this.memberType = MemberTypes.Field;
      this.name = name;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="declaringMethod"></param>
    /// <param name="fieldType"></param>
    /// <param name="rad"></param>
    internal RFieldRef(string name,RMethodBase declaringMethod,RType fieldType,RAssemblyDef rad)
    {
      this.rad = rad;
      this.attributes = (FieldAttributes)0;
      this.declaringType = declaringMethod.DeclaringType;
      this.fieldType = fieldType;
      this.memberType = MemberTypes.Field;
      this.name = name;
    }
   
    #region Custom Attributes

    /// <summary>
    /// 
    /// </summary>
    /// <param name="inherit"></param>
    /// <returns></returns>
    public override RCustomAttrib[] GetCustomAttributes(bool inherit) {
          throw new NotImplementedException();
        }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="attributeType"></param>
    /// <param name="inherit"></param>
    /// <returns></returns>
        public override RCustomAttrib[] GetCustomAttributes(RType attributeType, bool inherit){
          throw new NotImplementedException();
        }
        
        public override bool IsDefined(RType attributeType,bool inherit){
          throw new NotImplementedException();
        }
    #endregion
  }

  /// <summary>
  /// 
  /// </summary>
  public sealed class RFieldDef : RField, IVisitable, ICustomAttributeOwnerDef 
  {
    private int offset = -1;

    /// <summary>
    /// 
    /// </summary>
    public int Offset
    {
      get
      {
        return this.offset;
      }
      set
      {
        if (value<=0)
          this.offset = -1;
        else this.offset = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    internal RFieldDef() 
    {
    }

    /// <summary>
    /// Gets or sets the name of this member.
    /// </summary>
    public override String Name 
    {
      set 
      {
        this.name = value;
      }
    }


    /// <summary>
    /// Get or set the field marshaling information
    /// </summary>
    public override MarshalSpec MarshalSpec
    {
      set
      {
        this.marshalSpec = value;
      }
    }

    /// <summary>
    /// Define the MarshalSpec
    /// </summary>
    /// <param name="typ"></param>
    /// <returns></returns>
    public MarshalSpec DefineMarshalSpec(System.Runtime.InteropServices.UnmanagedType typ)
    {
      this.marshalSpec = new MarshalSpec(typ);
      return this.marshalSpec;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="arrayType"></param>
    /// <param name="ParamNum"></param>
    /// <param name="ElemMult"></param>
    /// <param name="NumElem"></param>
    /// <returns></returns>
    public MarshalSpec DefineMarshalSpecAsArray(System.Runtime.InteropServices.UnmanagedType arrayType,
      int ParamNum, int ElemMult, int NumElem)
    {
      this.marshalSpec = new MarshalSpec(System.Runtime.InteropServices.UnmanagedType.ByValArray);
      this.marshalSpec.ElemMult = ElemMult;
      this.marshalSpec.NumElem = NumElem;
      this.marshalSpec.ParamNum = ParamNum;
      return this.marshalSpec;
    }

    /// <summary>
    /// Remove the marshal information
    /// </summary>
    public void RemoveMarshal()
    {
      this.marshalSpec = null;
    }
    /// <summary>
    /// Gets or sets the attributes for this field
    /// </summary>
    public override FieldAttributes Attributes 
    {
      set 
      {
        this.attributes = value;
      }
    }

    /// <summary>
    /// Gets or sets the type of this field
    /// </summary>
    public override RType FieldType 
    {
      set 
      {
        this.fieldType = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    public override Object Value
    {
      set
      {
        this.fieldValue = value;
      }
      get
      {
        return this.fieldValue;
      }
    }
    
    #region Custom Attributes

//    /// <summary>
//    /// 
//    /// </summary>
//    /// <param name="inherit"></param>
//    /// <returns></returns>
//        public override RCustomAttrib[] GetCustomAttributes(bool inherit) {
//          throw new NotImplementedException();
//        }
//    /// <summary>
//    /// 
//    /// </summary>
//    /// <param name="attributeType"></param>
//    /// <param name="inherit"></param>
//    /// <returns></returns>
//        public override RCustomAttrib[] GetCustomAttributes(RType attributeType, bool inherit){
//          throw new NotImplementedException();
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="attributeType"></param>
//        /// <param name="inherit"></param>
//        /// <returns></returns>
//        public override bool IsDefined(RType attributeType,bool inherit){
//          throw new NotImplementedException();
//        }    
//     

    /// <summary>
    /// 
    /// </summary>
    /// <param name="attribute"></param>
    public void AddCustomAttributtes(RCustomAttrib attribute) 
    {
      InternalAddCustomAttributtes(attribute);
    }

    /// <summary>
    /// TODO: How should the attribute be specified?
    /// </summary>
    /// <param name="attribute"></param>
    public void RemoveCustomAttribute(RCustomAttrib attribute) 
    {
      InternalRemoveCustomAttribute(attribute);
    }

    #endregion

    /// <summary>
    /// Visits this field.
    /// </summary>
    /// <remarks>
    /// A field has no subelements.
    /// </remarks>
    /// <param name="v">The visitor to be used.</param>
    public void Accept(Visitor v) 
    {
      // We could call directly v.VisitField(this), but this way is more flexible
      // In the future, the Walker classes may be used for more than just choosing
      // the traversal order.
      v.GetWalker().WalkField(this);
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.