本文整理汇总了C#中MethodBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder类的具体用法?C# MethodBuilder怎么用?C# MethodBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodBuilder类属于命名空间,在下文中一共展示了MethodBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ReturnParameter
// TODO: merge method and mb
public ReturnParameter (MemberCore method, MethodBuilder mb, Location location)
{
this.method = method;
try {
builder = mb.DefineParameter (0, ParameterAttributes.None, "");
}
catch (ArgumentOutOfRangeException) {
method.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type");
}
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:11,代码来源:parameter.cs
示例2: VerifyMethodInfo
private void VerifyMethodInfo(MethodInfo methodInfo, MethodBuilder builder, Type returnType)
{
if (methodInfo == null)
{
Assert.Null(builder);
}
else
{
Assert.Equal(methodInfo.Name, builder.Name);
Assert.Equal(methodInfo.ReturnType, returnType);
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:12,代码来源:MethodBuilderMakeGenericMethod.cs
示例3: EmitTestEvents
static void EmitTestEvents (TypeBuilder genericFoo) {
MethodBuilder mb = genericFoo.DefineMethod ("TestEvents", MethodAttributes.Public, typeof (void), null);
ILGenerator il = mb.GetILGenerator ();
for (int i = 0; i < 20; ++i)
il.Emit (OpCodes.Nop);
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Callvirt, targetMethod);
il.Emit (OpCodes.Ret);
testEvents = mb;
}
开发者ID:Zman0169,项目名称:mono,代码行数:14,代码来源:bug-389886-2.cs
示例4: EmitTargetMethod
static void EmitTargetMethod (TypeBuilder genericFoo) {
MethodBuilder mb = genericFoo.DefineMethod ("TargetMethod", MethodAttributes.Public, typeof (void), new Type[] {typeof (object) });
ILGenerator il = mb.GetILGenerator ();
for (int i = 0; i < 20; ++i)
il.Emit (OpCodes.Nop);
il.Emit (OpCodes.Ldtoken, genericArgs [0]);
il.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle"));
il.Emit (OpCodes.Call, typeof (Console).GetMethod ("WriteLine", new Type[] { typeof (object) }));
il.Emit (OpCodes.Ret);
targetMethod = mb;
}
开发者ID:Zman0169,项目名称:mono,代码行数:14,代码来源:bug-389886-2.cs
示例5: DefaultPropertyBuilder
/// <summary>
/// Constructor
/// </summary>
/// <param name="typeBuilder">Type builder</param>
/// <param name="name">Name of the property</param>
/// <param name="attributes">Attributes for the property (public, private, etc.)</param>
/// <param name="getMethodAttributes">Get method attributes</param>
/// <param name="setMethodAttributes">Set method attributes</param>
/// <param name="propertyType">Property type for the property</param>
/// <param name="parameters">Parameter types for the property</param>
public DefaultPropertyBuilder(TypeBuilder typeBuilder, string name,
PropertyAttributes attributes, MethodAttributes getMethodAttributes,
MethodAttributes setMethodAttributes,
Type propertyType, IEnumerable<Type> parameters)
{
if (typeBuilder == null)
throw new ArgumentNullException("typeBuilder");
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
Name = name;
Type = typeBuilder;
Attributes = attributes;
GetMethodAttributes = getMethodAttributes;
SetMethodAttributes = setMethodAttributes;
DataType = propertyType;
Parameters = new List<ParameterBuilder>();
if (parameters != null)
{
int x = 1;
foreach (var parameter in parameters)
{
Parameters.Add(new ParameterBuilder(parameter, x));
++x;
}
}
Field = new FieldBuilder(Type, "_" + name + "field", propertyType, FieldAttributes.Private);
Builder = Type.Builder.DefineProperty(name, attributes, propertyType,
(parameters != null && parameters.Count() > 0)
? parameters.ToArray()
: System.Type.EmptyTypes);
GetMethod = new MethodBuilder(Type, "get_" + name, getMethodAttributes, parameters, propertyType);
GetMethod.Generator.Emit(OpCodes.Ldarg_0);
GetMethod.Generator.Emit(OpCodes.Ldfld, Field.Builder);
GetMethod.Generator.Emit(OpCodes.Ret);
var setParameters = new List<Type>();
if (parameters != null)
{
setParameters.AddRange(parameters);
}
setParameters.Add(propertyType);
SetMethod = new MethodBuilder(Type, "set_" + name, setMethodAttributes, setParameters, typeof (void));
SetMethod.Generator.Emit(OpCodes.Ldarg_0);
SetMethod.Generator.Emit(OpCodes.Ldarg_1);
SetMethod.Generator.Emit(OpCodes.Stfld, Field.Builder);
SetMethod.Generator.Emit(OpCodes.Ret);
Builder.SetGetMethod(GetMethod.Builder);
Builder.SetSetMethod(SetMethod.Builder);
}
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:58,代码来源:DefaultPropertyBuilder.cs
示例6: VerifyGenericArguments
private static void VerifyGenericArguments(MethodBuilder method, GenericTypeParameterBuilder[] expected)
{
Type[] genericArguments = method.GetGenericArguments();
if (expected == null)
{
Assert.Null(genericArguments);
}
else
{
Assert.Equal(expected.Length, genericArguments.Length);
for (int i = 0; i < genericArguments.Length; ++i)
{
Assert.True(expected[i].Equals(genericArguments[i]));
}
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:16,代码来源:MethodBuilderGetGenericArguments.cs
示例7: DefaultPropertyBuilder
/// <summary>
/// Constructor
/// </summary>
/// <param name="TypeBuilder">Type builder</param>
/// <param name="Name">Name of the property</param>
/// <param name="Attributes">Attributes for the property (public, private, etc.)</param>
/// <param name="GetMethodAttributes">Get method attributes</param>
/// <param name="SetMethodAttributes">Set method attributes</param>
/// <param name="PropertyType">Property type for the property</param>
/// <param name="Parameters">Parameter types for the property</param>
public DefaultPropertyBuilder(TypeBuilder TypeBuilder, string Name,
PropertyAttributes Attributes, MethodAttributes GetMethodAttributes,
MethodAttributes SetMethodAttributes,
Type PropertyType, List<Type> Parameters)
: base()
{
if (TypeBuilder == null)
throw new ArgumentNullException("TypeBuilder");
if (string.IsNullOrEmpty(Name))
throw new ArgumentNullException("Name");
this.Name = Name;
this.Type = TypeBuilder;
this.Attributes = Attributes;
this.GetMethodAttributes = GetMethodAttributes;
this.SetMethodAttributes = SetMethodAttributes;
this.DataType = PropertyType;
this.Parameters = new List<ParameterBuilder>();
if (Parameters != null)
{
int x = 1;
foreach (Type Parameter in Parameters)
{
this.Parameters.Add(new ParameterBuilder(Parameter, x));
++x;
}
}
Field = new FieldBuilder(Type, "_" + Name + "field", PropertyType, FieldAttributes.Private);
Builder = Type.Builder.DefineProperty(Name, Attributes, PropertyType,
(Parameters != null && Parameters.Count > 0) ? Parameters.ToArray() : System.Type.EmptyTypes);
GetMethod = new MethodBuilder(Type, "get_" + Name, GetMethodAttributes, Parameters, PropertyType);
GetMethod.Generator.Emit(OpCodes.Ldarg_0);
GetMethod.Generator.Emit(OpCodes.Ldfld, Field.Builder);
GetMethod.Generator.Emit(OpCodes.Ret);
List<Type> SetParameters = new List<System.Type>();
if (Parameters != null)
{
SetParameters.AddRange(Parameters);
}
SetParameters.Add(PropertyType);
SetMethod = new MethodBuilder(Type, "set_" + Name, SetMethodAttributes, SetParameters, typeof(void));
SetMethod.Generator.Emit(OpCodes.Ldarg_0);
SetMethod.Generator.Emit(OpCodes.Ldarg_1);
SetMethod.Generator.Emit(OpCodes.Stfld, Field.Builder);
SetMethod.Generator.Emit(OpCodes.Ret);
Builder.SetGetMethod(GetMethod.Builder);
Builder.SetSetMethod(SetMethod.Builder);
}
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:57,代码来源:DefaultPropertyBuilder.cs
示例8: PropertyBuilder
/// <summary>
/// Constructor
/// </summary>
/// <param name="TypeBuilder">Type builder</param>
/// <param name="Name">Name of the property</param>
/// <param name="Attributes">Attributes for the property (public, private, etc.)</param>
/// <param name="GetMethodAttributes">Get method attributes</param>
/// <param name="SetMethodAttributes">Set method attributes</param>
/// <param name="PropertyType">Property type for the property</param>
/// <param name="Parameters">Parameter types for the property</param>
public PropertyBuilder(TypeBuilder TypeBuilder,
string Name,
PropertyAttributes Attributes,
MethodAttributes GetMethodAttributes,
MethodAttributes SetMethodAttributes,
Type PropertyType,
IEnumerable<Type> Parameters)
: base()
{
Contract.Requires<ArgumentNullException>(TypeBuilder!=null,"TypeBuilder");
Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Name),"Name");
this.Name = Name;
this.Type = TypeBuilder;
this.Attributes = Attributes;
this.GetMethodAttributes = GetMethodAttributes;
this.SetMethodAttributes = SetMethodAttributes;
this.DataType = PropertyType;
this.Parameters = new List<ParameterBuilder>();
if (Parameters != null)
{
int x = 1;
foreach (Type Parameter in Parameters)
{
this.Parameters.Add(new ParameterBuilder(Parameter, x));
++x;
}
}
Builder = Type.Builder.DefineProperty(Name, Attributes, PropertyType,
(Parameters != null && Parameters.Count() > 0) ? Parameters.ToArray() : System.Type.EmptyTypes);
GetMethod = new MethodBuilder(Type, "get_" + Name, GetMethodAttributes, Parameters, PropertyType);
List<Type> SetParameters = new List<System.Type>();
if (Parameters != null)
SetParameters.AddRange(Parameters);
SetParameters.Add(PropertyType);
SetMethod = new MethodBuilder(Type, "set_" + Name, SetMethodAttributes, SetParameters, typeof(void));
Builder.SetGetMethod(GetMethod.Builder);
Builder.SetSetMethod(SetMethod.Builder);
}
开发者ID:kaytie,项目名称:Craig-s-Utility-Library,代码行数:48,代码来源:PropertyBuilder.cs
示例9: initialize
void initialize(MethodBuilder methodBuilder, TypeBuilder lambdaScope) {
this.methods.clear();
this.ParametersUsedInLambdas.clear();
this.ParametersUsedInLambda.clear();
this.CatchVariables.clear();
this.TreeLocals.clear();
this.TreeLabels.clear();
this.LocalFields.clear();
this.Labels.clear();
this.methods.add(methodBuilder);
this.LambdaScope = lambdaScope;
this.Generator = methodBuilder.CodeGenerator;
this.destructor = methodBuilder.Name.equals("finalize") && !methodBuilder.Parameters.any();
this.IsLambdaScopeUsed = false;
this.IsLambdaScopeInitialized = false;
this.IsLambdaScopeThisInitialized = false;
this.IsBuildingString = false;
this.foreachStatement = 0;
this.YieldCount = 0;
this.stringSwitch = 0;
this.PreviousLineNumber = 0;
this.generatedLocal = 0;
}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:24,代码来源:CompilerContext.stab.cs
示例10: enterLambdaMethod
void enterLambdaMethod(MethodBuilder methodBuilder) {
context.MemberResolver.enterMethod(methodBuilder, true);
methods.add(methodBuilder);
returnTypes.add(new ArrayList<TypeInfo>());
}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:5,代码来源:CompilerContext.stab.cs
示例11: enterMethod
void enterMethod(MethodBuilder methodBuilder) {
context.MemberResolver.enterMethod(methodBuilder);
this.IsStatic = methodBuilder.IsStatic;
methods.add(methodBuilder);
this.YieldCount = 0;
}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:6,代码来源:CompilerContext.stab.cs
示例12: Define
public override bool Define ()
{
if (!base.Define ())
return false;
if (!CheckBase ())
return false;
MemberKind kind;
if (this is Operator)
kind = MemberKind.Operator;
else if (this is Destructor)
kind = MemberKind.Destructor;
else
kind = MemberKind.Method;
if (IsPartialDefinition) {
caching_flags &= ~Flags.Excluded_Undetected;
caching_flags |= Flags.Excluded;
// Add to member cache only when a partial method implementation has not been found yet
if ((caching_flags & Flags.PartialDefinitionExists) == 0) {
// MethodBase mb = new PartialMethodDefinitionInfo (this);
spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, null, parameters, ModFlags);
if (MemberName.Arity > 0) {
spec.IsGeneric = true;
// TODO: Have to move DefineMethod after Define (ideally to Emit)
throw new NotImplementedException ("Generic partial methods");
}
Parent.MemberCache.AddMember (spec);
}
return true;
}
MethodData = new MethodData (
this, ModFlags, flags, this, MethodBuilder, base_method);
if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
return false;
MethodBuilder = MethodData.MethodBuilder;
spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, MethodBuilder, parameters, ModFlags);
if (MemberName.Arity > 0)
spec.IsGeneric = true;
Parent.MemberCache.AddMember (this, MethodBuilder.Name, spec);
return true;
}
开发者ID:Viewserve,项目名称:mono,代码行数:54,代码来源:method.cs
示例13: Apply
internal override void Apply(ClassLoaderWrapper loader, MethodBuilder mb, object annotation)
{
Annotation annot = type.Annotation;
foreach (object ann in UnwrapArray(annotation))
{
annot.Apply(loader, mb, ann);
}
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:8,代码来源:DotNetTypeWrapper.cs
示例14: ApplyAttributes
public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
{
if (builder != null)
throw new InternalErrorException ("builder already exists");
var pattrs = ParametersCompiled.GetParameterAttribute (modFlags);
if (HasOptionalExpression)
pattrs |= ParameterAttributes.Optional;
if (mb == null)
builder = cb.DefineParameter (index, pattrs, Name);
else
builder = mb.DefineParameter (index, pattrs, 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
//
var def_value = DefaultValue;
Constant c = def_value != null ? def_value.Child as Constant : default_expr as Constant;
if (c != null) {
if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
pa.DecimalConstant.EmitAttribute (builder, (decimal) c.GetValue (), c.Location);
} else {
builder.SetConstant (c.GetValue ());
}
} else if (default_expr.Type.IsStruct) {
//
// Handles special case where default expression is used with value-type
//
// void Foo (S s = default (S)) {}
//
builder.SetConstant (null);
}
}
if (parameter_type != null) {
if (parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
pa.Dynamic.EmitAttribute (builder);
} else if (parameter_type.HasDynamicElement) {
pa.Dynamic.EmitAttribute (builder, parameter_type, Location);
}
}
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:48,代码来源:parameter.cs
示例15: ApplyReturnValue
internal override void ApplyReturnValue(ClassLoaderWrapper loader, MethodBuilder mb, ref ParameterBuilder pb, object annotation)
{
// TODO make sure the descriptor is correct
Annotation ann = type.Annotation;
object[] arr = (object[])annotation;
for (int i = 2; i < arr.Length; i += 2)
{
if ("value".Equals(arr[i]))
{
if (pb == null)
{
pb = mb.DefineParameter(0, ParameterAttributes.None, null);
}
object[] value = (object[])arr[i + 1];
if (value[0].Equals(AnnotationDefaultAttribute.TAG_ANNOTATION))
{
ann.Apply(loader, pb, value);
}
else
{
for (int j = 1; j < value.Length; j++)
{
ann.Apply(loader, pb, value[j]);
}
}
break;
}
}
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:29,代码来源:DotNetTypeWrapper.cs
示例16: EmitLineNumberTable
internal void EmitLineNumberTable(MethodBuilder mb)
{
if(linenums != null)
{
AttributeHelper.SetLineNumberTable(mb, linenums);
}
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:7,代码来源:CodeEmitter.cs
示例17: Create
internal static CodeEmitter Create(MethodBuilder mb)
{
return new CodeEmitter(mb.GetILGenerator(), mb.DeclaringType);
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:4,代码来源:CodeEmitter.cs
示例18: Call
/// <summary>
/// Calls a method on this variable
/// </summary>
/// <param name="Method">Method</param>
/// <param name="Parameters">Parameters sent in</param>
/// <returns>Variable returned by the function (if one exists, null otherwise)</returns>
public virtual VariableBase Call(MethodBuilder Method, object[] Parameters = null)
{
if (Method == null)
throw new ArgumentNullException("Method");
return Call(Method.Builder, Parameters);
}
开发者ID:summer-breeze,项目名称:ChengGouHui,代码行数:12,代码来源:VariableBase.cs
示例19: Create
internal static CodeEmitter Create(MethodBuilder mb)
{
return new CodeEmitter(mb.GetILGenerator());
}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:4,代码来源:CodeEmitter.cs
示例20: enterLambda
void enterLambda(MethodBuilder method) {
this.PreviousLineNumber = 0;
this.methods.add(method);
this.Generator = method.CodeGenerator;
}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:5,代码来源:CompilerContext.stab.cs
注:本文中的MethodBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论