/*
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;
namespace Rail.Reflect{
/// <summary>
///
/// </summary>
public class RParameter : CustomAttributeOwner, ICustomAttributeOwnerDef
{
#region fields
/// <summary>
///
/// </summary>
private ParameterAttributes attributes;
/// <summary>
///
/// </summary>
private String name;
/// <summary>
///
/// </summary>
private RType parameterType;
/// <summary>
///
/// </summary>
private int sequence;
/// <summary>
///
/// </summary>
private RAssemblyDef rad;
/// <summary>
///
/// </summary>
private 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 MarshalSpec MarshalSpec
{
get
{
return this.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>
///
/// </summary>
public int Sequence
{
get
{
return this.sequence;
}
set
{
this.sequence = value;
}
}
/// <summary>
///
/// </summary>
public ParameterAttributes Attributes
{
get
{
return this.attributes;
}
set
{
this.attributes = value;
}
}
/// <summary>
///
/// </summary>
public String Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
/// <summary>
///
/// </summary>
public RType ParameterType
{
get
{
return this.parameterType;
}
set
{
this.parameterType = value;
}
}
/// <summary>
/// Creates a new RParamenter
/// </summary>
/// <param name="sequence">The position</param>
/// <param name="attributes">The ParamAttributes</param>
/// <param name="name">The name of the Parameter</param>
/// <param name="type">The Rtype of the parameter</param>
public RParameter(int sequence, int attributes, string name, RType type)
{
this.sequence = sequence;
this.attributes = (ParameterAttributes)attributes;
this.name = name;
this.parameterType = type;
}
/// <summary>
///
/// </summary>
/// <param name="sequence"></param>
/// <param name="type"></param>
public RParameter(int sequence, RType type)
{
this.sequence = sequence;
this.parameterType = type;
}
/// <summary>
///
/// </summary>
/// <param name="param"></param>
/// <param name="rad"></param>
/// <param name="me"></param>
public RParameter(ParameterInfo param,RAssemblyDef rad, MethodAttributes me)
{
if ((me & MethodAttributes.Static) != 0)
this.sequence = param.Position;
else
this.sequence = param.Position + 1;
this.rad = rad;
this.attributes = (ParameterAttributes)param.Attributes;
this.name = param.Name;
this.parameterType = rad.GetRTypeRef(param.ParameterType);
}
/// <summary>
///
/// </summary>
/// <param name="param"></param>
/// <param name="rad"></param>
public RParameter(ParameterInfo param,RAssemblyDef rad)
{
this.sequence = param.Position + 1;
this.rad = rad;
this.attributes = (ParameterAttributes)param.Attributes;
this.name = param.Name;
this.parameterType = rad.GetRTypeRef(param.ParameterType);
}
#region Custom Attributes
/// <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
}
}
|