本文整理汇总了C#中System.Reflection.Emit.ConstructorBuilder.DefineParameter方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorBuilder.DefineParameter方法的具体用法?C# ConstructorBuilder.DefineParameter怎么用?C# ConstructorBuilder.DefineParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ConstructorBuilder
的用法示例。
在下文中一共展示了ConstructorBuilder.DefineParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineParams
public static void DefineParams(ConstructorBuilder constructorBuilder, IEnumerable<RppParameterInfo> constructorParams)
{
int index = 1;
foreach (var param in constructorParams)
{
constructorBuilder.DefineParameter(index++, ParameterAttributes.None, RppClass.StringConstructorArgName(param.Name));
}
}
示例2: Compile
internal void Compile(ConstructorBuilder c)
{
if (Builder == null)
{
int ofs = (c.IsStatic ? 0 : 1);
Builder = c.DefineParameter(this.Index + ofs, this.Attributes, this.Name);
}
}
示例3: DefineParameterNames
private static void DefineParameterNames(
ConstructorBuilder constructor,
ConstructorMetadata constructorMetadata)
{
for (var i = 0; i < constructorMetadata.Parameters.Length; i++)
{
var parameter = constructorMetadata.Parameters[i];
constructor.DefineParameter(parameter.Sequence, ParameterAttributes.None, parameter.Name);
}
}
示例4: Execute
public void Execute()
{
constructorBuilder = builder().TypeBuilder.DefineConstructor(
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.RTSpecialName,
CallingConventions.Standard,
this.types().ToArray());
int counter = 1;
foreach(Type type in this.types())
{
constructorBuilder.DefineParameter(counter, ParameterAttributes.None, type.Name + "_" + counter);
counter++;
}
}
示例5: ConstructorEmitter
internal ConstructorEmitter(AbstractTypeEmitter maintype, params ArgumentReference[] arguments)
{
this.maintype = maintype;
var args = ArgumentsUtil.InitializeAndConvert(arguments);
builder = maintype.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args);
// if we don't copy the parameter attributes, the default binder will fail
// when trying to resolve constructors from the passed argument values.
for (int i = 0; i < args.Length; ++i)
{
var arg = arguments[i];
var paramBuilder = builder.DefineParameter(i + 1, arg.ParameterAttributes, "");
if (arg.DefaultValue != DBNull.Value)
paramBuilder.SetConstant(arg.DefaultValue);
}
}
示例6: NegTestCaseVerificationHelper
private void NegTestCaseVerificationHelper(
ConstructorBuilder constructor,
int sequence,
ParameterAttributes attribute,
string paramName,
Type desiredException)
{
Assert.Throws(desiredException, () => { constructor.DefineParameter(sequence, attribute, paramName); });
}
示例7: DefineParameterCopy
// TODO: use in Python's OverrideConstructor:
public static ParameterBuilder DefineParameterCopy(ConstructorBuilder builder, int paramIndex, ParameterInfo info) {
var result = builder.DefineParameter(1 + paramIndex, info.Attributes, info.Name);
CopyParameterAttributes(info, result);
return result;
}
示例8: ApplyAttributes
public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
{
if (builder != null)
throw new InternalErrorException ("builder already exists");
if (mb == null)
builder = cb.DefineParameter (index, Attributes, Name);
else
builder = mb.DefineParameter (index, Attributes, Name);
if (OptAttributes != null)
OptAttributes.Emit ();
if (HasDefaultValue) {
//
// Emit constant values for true constants only, the other
// constant-like expressions will rely on default value expression
//
Constant c = default_expr as Constant;
if (c != null) {
if (default_expr.Type == TypeManager.decimal_type) {
builder.SetCustomAttribute (Const.CreateDecimalConstantAttribute (c, pa));
} else {
builder.SetConstant (c.GetTypedValue ());
}
}
}
if (parameter_type != null) {
if (parameter_type == InternalType.Dynamic) {
pa.Dynamic.EmitAttribute (builder);
} else if (parameter_type.HasDynamicElement) {
pa.Dynamic.EmitAttribute (builder, parameter_type);
}
}
}
示例9: RegisterBuilders
public static void RegisterBuilders(this IReadOnlyList<ParameterStructure> prm, ConstructorBuilder builder, bool isInstance)
{
for (var i = 0; i < prm.Count; ++i)
{
var p = prm[i];
var pb = builder.DefineParameter(i + 1, p.Attributes, p.Name);
p.RegisterBuilder(pb, isInstance);
}
}
示例10: ApplyAttributes
public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
{
if (mb == null)
builder = cb.DefineParameter (index, Attributes, Name);
else
builder = mb.DefineParameter (index, Attributes, Name);
if (OptAttributes != null)
OptAttributes.Emit ();
if (HasDefaultValue) {
//
// Emit constant values for true constants only, the other
// constant-like expressions will rely on default value expression
//
Constant c = default_expr as Constant;
if (c != null) {
if (default_expr.Type == TypeManager.decimal_type) {
builder.SetCustomAttribute (Const.CreateDecimalConstantAttribute (c));
} else {
builder.SetConstant (c.GetTypedValue ());
}
}
}
if (parameter_type == InternalType.Dynamic) {
PredefinedAttributes.Get.Dynamic.EmitAttribute (builder);
} else {
var trans_flags = TypeManager.HasDynamicTypeUsed (parameter_type);
if (trans_flags != null) {
var pa = PredefinedAttributes.Get.DynamicTransform;
if (pa.Constructor != null || pa.ResolveConstructor (Location, ArrayContainer.MakeType (TypeManager.bool_type))) {
builder.SetCustomAttribute (
new CustomAttributeBuilder (pa.Constructor, new object [] { trans_flags }));
}
}
}
}
示例11: DefineParameter
private void DefineParameter(MethodBuilder methodBuilder, ConstructorBuilder constructorBuilder, Cci.IParameterDefinition paramDef)
{
// No explicit param row is needed if param has no flags (other than optionally IN),
// no name and no references to the param row, such as CustomAttribute, Constant, or FieldMarshall
var attributes = paramDef.GetAttributes(_context);
var defaultValue = paramDef.GetDefaultValue(_context);
if (defaultValue != null ||
paramDef.IsOptional ||
paramDef.IsOut ||
paramDef.IsMarshalledExplicitly ||
attributes.Any() ||
paramDef.Name.Length > 0)
{
int index = paramDef is Cci.ReturnValueParameter ? 0 : paramDef.Index + 1;
ParameterAttributes attrs = (ParameterAttributes)Cci.MetadataWriter.GetParameterFlags(paramDef);
ParameterBuilder paramBuilder = (methodBuilder != null) ?
methodBuilder.DefineParameter(index, attrs, paramDef.Name) :
constructorBuilder.DefineParameter(index, attrs, paramDef.Name);
if (defaultValue != null)
{
object rawValue = defaultValue.Value;
if (rawValue == null)
{
var paramTypeRef = paramDef.GetType(_context);
if (paramTypeRef.IsValueType)
{
SetParameterDefaultStructValue(paramBuilder);
}
else
{
paramBuilder.SetConstant(null);
}
}
else
{
// TODO (tomat): Ref.Emit has too strict checks on the constant type. While it is ok to emit value,
// e.g. of type Int16 for parameter of type Int32 to metadata, Ref.Emit checks if these types are Type.IsAssignableFrom.
// To make this work we need to convert.
//
// We also need to support Nullable<T>.
if (rawValue.GetType().IsPrimitive)
{
// parameter type has already been resolved once when defining the method, so just retrive it:
Type paramType = ResolveType(paramDef.GetType(_context));
if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
paramType = paramType.GetGenericArguments()[0];
}
if (paramType.IsEnum)
{
// If emitting the enum, it isn't "created" as this stage so Enum.GetUnderlyingType() will throw
// Otherwise, if the enum is already defined, we should use Enum.GetUnderlyingType() to get the correct type
paramType = paramType is TypeBuilder ? paramType.UnderlyingSystemType : Enum.GetUnderlyingType(paramType);
}
rawValue = Convert.ChangeType(rawValue, paramType, System.Globalization.CultureInfo.InvariantCulture);
}
paramBuilder.SetConstant(rawValue);
}
}
if (paramDef.IsMarshalledExplicitly)
{
// FieldMarshal
var marshallingInformation = paramDef.MarshallingInformation;
if (marshallingInformation != null)
{
paramBuilder.SetCustomAttribute(GetMarshalAsAttribute(marshallingInformation));
}
else
{
Debug.Assert(!paramDef.MarshallingDescriptor.IsDefaultOrEmpty);
// TODO:
throw new NotImplementedException();
}
}
EmitCustomAttributes(paramBuilder, attributes);
}
}
示例12: DefineStubParameters
/// <summary>
/// Sets attributes of generated override/implement/export stub parameters.
/// </summary>
/// <param name="stub">The stub constructor builder.
/// </param>
/// <param name="formalParams">Formal parameters of the implementing PHP method.</param>
/// <param name="templateParams">Parameters of the overload being overriden/implemented/exported.</param>
public static void DefineStubParameters(ConstructorBuilder/*!*/ stub,
PHP.Core.AST.FormalParam[] formalParams, ParameterInfo[]/*!*/ templateParams)
{
for (int i = 0; i < templateParams.Length; i++)
{
string name;
// take the overriding parameter name if available
if (formalParams != null && i < formalParams.Length) name = formalParams[i].Name.ToString();
else name = templateParams[i].Name;
stub.DefineParameter(i + 1, templateParams[i].Attributes, name);
}
}
示例13: ApplyAttributes
public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
{
if (mb == null)
builder = cb.DefineParameter (index, Attributes, Name);
else
builder = mb.DefineParameter (index, Attributes, Name);
if (OptAttributes != null)
OptAttributes.Emit ();
}
示例14: ConvertConstructorParameters
private void ConvertConstructorParameters(ICommonMethodNode value, ConstructorBuilder methb)
{
ParameterBuilder pb = null;
IParameterNode[] parameters = value.parameters;
for (int i = 0; i < parameters.Length; i++)
{
object default_value = null;
if (parameters[i].default_value != null)
default_value = helper.GetConstantForExpression(parameters[i].default_value);
ParameterAttributes pa = ParameterAttributes.None;
if (parameters[i].parameter_type == parameter_type.var)
pa = ParameterAttributes.Retval;
if (default_value != null)
pa |= ParameterAttributes.Optional;
pb = methb.DefineParameter(i + 1, pa, parameters[i].name);
if (default_value != null)
pb.SetConstant(default_value);
helper.AddParameter(parameters[i], pb);
if (parameters[i].is_params)
pb.SetCustomAttribute(TypeFactory.ParamArrayAttributeConstructor, new byte[] { 0x1, 0x0, 0x0, 0x0 });
}
}
示例15: Define
public override bool Define ()
{
if (IsGeneric) {
foreach (TypeParameter type_param in TypeParameters) {
if (!type_param.Resolve (this))
return false;
}
foreach (TypeParameter type_param in TypeParameters) {
if (!type_param.DefineType (this))
return false;
}
}
member_cache = new MemberCache (TypeManager.multicast_delegate_type, this);
// FIXME: POSSIBLY make this static, as it is always constant
//
Type [] const_arg_types = new Type [2];
const_arg_types [0] = TypeManager.object_type;
const_arg_types [1] = TypeManager.intptr_type;
const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
MethodAttributes.HideBySig | MethodAttributes.Public;
ConstructorBuilder = TypeBuilder.DefineConstructor (ctor_mattr,
CallingConventions.Standard,
const_arg_types);
ConstructorBuilder.DefineParameter (1, ParameterAttributes.None, "object");
ConstructorBuilder.DefineParameter (2, ParameterAttributes.None, "method");
//
// HACK because System.Reflection.Emit is lame
//
IParameterData [] fixed_pars = new IParameterData [] {
new ParameterData ("object", Parameter.Modifier.NONE),
new ParameterData ("method", Parameter.Modifier.NONE)
};
AParametersCollection const_parameters = new ParametersImported (
fixed_pars,
new Type[] { TypeManager.object_type, TypeManager.intptr_type });
TypeManager.RegisterMethod (ConstructorBuilder, const_parameters);
member_cache.AddMember (ConstructorBuilder, this);
ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
//
// Here the various methods like Invoke, BeginInvoke etc are defined
//
// First, call the `out of band' special method for
// defining recursively any types we need:
if (!Parameters.Resolve (this))
return false;
//
// Invoke method
//
// Check accessibility
foreach (Type partype in Parameters.Types){
if (!IsAccessibleAs (partype)) {
Report.SymbolRelatedToPreviousError (partype);
Report.Error (59, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
TypeManager.CSharpName (partype),
GetSignatureForError ());
return false;
}
}
ReturnType = ReturnType.ResolveAsTypeTerminal (this, false);
if (ReturnType == null)
return false;
ret_type = ReturnType.Type;
if (!IsAccessibleAs (ret_type)) {
Report.SymbolRelatedToPreviousError (ret_type);
Report.Error (58, Location,
"Inconsistent accessibility: return type `" +
TypeManager.CSharpName (ret_type) + "' is less " +
"accessible than delegate `" + GetSignatureForError () + "'");
return false;
}
CheckProtectedModifier ();
if (RootContext.StdLib && TypeManager.IsSpecialType (ret_type)) {
Method.Error1599 (Location, ret_type, Report);
return false;
}
TypeManager.CheckTypeVariance (ret_type, Variance.Covariant, this);
//
// We don't have to check any others because they are all
// guaranteed to be accessible - they are standard types.
//.........这里部分代码省略.........