本文整理汇总了C#中Mono.Cecil.ParameterDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ParameterDefinition类的具体用法?C# ParameterDefinition怎么用?C# ParameterDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterDefinition类属于Mono.Cecil命名空间,在下文中一共展示了ParameterDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddConstructor
public void AddConstructor(TypeDefinition adapterType,
FieldReference targetField)
{
var adapterCtor = adapterType.AddDefaultConstructor();
var adapterParameter = new ParameterDefinition(_targetDependency);
adapterCtor.Parameters.Add(adapterParameter);
// HACK: Remove the ret instruction from the default constructor and replace it with
// the field setter
var adapterBody = adapterCtor.Body;
var adapterInstructions = adapterBody.Instructions.Cast<Instruction>().Where(i => i.OpCode != OpCodes.Ret).ToArray();
adapterBody.Instructions.Clear();
// Copy the old instructions
var IL = adapterBody.CilWorker;
foreach (var instruction in adapterInstructions)
{
IL.Append(instruction);
}
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Ldarg, adapterParameter);
IL.Emit(OpCodes.Stfld, targetField);
IL.Emit(OpCodes.Ret);
}
开发者ID:philiplaureano,项目名称:Taiji,代码行数:25,代码来源:AddAdapterConstructor.cs
示例2: MakeHostInstanceGeneric
internal static MethodReference MakeHostInstanceGeneric(this MethodReference self,
params TypeReference[] arguments)
{
var genericInstanceType = self.DeclaringType.MakeGenericInstanceType(arguments);
var reference = new MethodReference(self.Name, self.ReturnType, genericInstanceType)
{
HasThis = self.HasThis,
ExplicitThis = self.ExplicitThis,
CallingConvention = self.CallingConvention
};
foreach (var parameter in self.Parameters)
{
// TODO: This won't work with methods that has generic arguments, since the ParameterType needs to be replaced. @asbjornu
var parameterDefinition = new ParameterDefinition(parameter.Name,
parameter.Attributes,
parameter.ParameterType);
reference.Parameters.Add(parameterDefinition);
}
foreach (var genericParameter in self.GenericParameters)
reference.GenericParameters.Add(new GenericParameter(genericParameter.Name, reference));
return reference;
}
开发者ID:Pomona,项目名称:Pomona,代码行数:25,代码来源:CecilExtensions.cs
示例3: ArgumentReferenceEmitter
internal ArgumentReferenceEmitter(IdentifierExpression identifierExpression, ParameterDefinition parameterDefinition, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
: base(ilGenerator, instructionsIndexer) {
_parameterDefinition = parameterDefinition;
_identifierExpression = identifierExpression;
Type = parameterDefinition.ParameterType.GetActualType();
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:ArgumentReferenceEmitter.cs
示例4: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly(OpCode opCode, bool invert)
{
var name = new AssemblyNameDefinition("TestConditionalsBoundaryTurtle", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestConditionalsBoundaryTurtle", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var boolType = assembly.MainModule.Import(typeof(bool));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var param = new ParameterDefinition("input", ParameterAttributes.In, intType);
method.Parameters.Add(param);
var resultVariable = new VariableDefinition(boolType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, param));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(opCode));
if (invert)
{
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
}
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(loadReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
开发者ID:dbremner,项目名称:ninjaturtles,代码行数:32,代码来源:ConditionalBoundaryTurtleTests.cs
示例5: InjectInterceptedMethod
MethodDefinition InjectInterceptedMethod(TypeDefinition targetType, MethodDefinition innerOnPropertyChanging)
{
var delegateHolderInjector = new DelegateHolderInjector
{
TargetTypeDefinition=targetType,
OnPropertyChangingMethodReference = innerOnPropertyChanging,
ModuleWeaver = this
};
delegateHolderInjector.InjectDelegateHolder();
var method = new MethodDefinition(EventInvokerNames.First(), GetMethodAttributes(targetType), ModuleDefinition.TypeSystem.Void);
var propertyName = new ParameterDefinition("propertyName", ParameterAttributes.None, ModuleDefinition.TypeSystem.String);
method.Parameters.Add(propertyName);
if (InterceptorType == InvokerTypes.Before)
{
var before = new ParameterDefinition("before", ParameterAttributes.None, ModuleDefinition.TypeSystem.Object);
method.Parameters.Add(before);
}
var action = new VariableDefinition("firePropertyChanging", ActionTypeReference);
method.Body.Variables.Add(action);
var variableDefinition = new VariableDefinition("delegateHolder", delegateHolderInjector.TypeDefinition);
method.Body.Variables.Add(variableDefinition);
var instructions = method.Body.Instructions;
var last = Instruction.Create(OpCodes.Ret);
instructions.Add(Instruction.Create(OpCodes.Newobj, delegateHolderInjector.ConstructorDefinition));
instructions.Add(Instruction.Create(OpCodes.Stloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.PropertyName));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.Target));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldftn, delegateHolderInjector.MethodDefinition));
instructions.Add(Instruction.Create(OpCodes.Newobj, ActionConstructorReference));
instructions.Add(Instruction.Create(OpCodes.Stloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Ldloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldfld, delegateHolderInjector.PropertyName));
if (InterceptorType == InvokerTypes.Before)
{
instructions.Add(Instruction.Create(OpCodes.Ldarg_2));
instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
}
else
{
instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
}
instructions.Add(last);
method.Body.InitLocals = true;
targetType.Methods.Add(method);
return method;
}
开发者ID:Fody,项目名称:PropertyChanging,代码行数:60,代码来源:MethodInjector.cs
示例6: UseParameter
private bool UseParameter (MethodDefinition method, ParameterDefinition parameter)
{
foreach (Instruction instruction in method.Body.Instructions) {
switch (instruction.OpCode.Code) {
case Code.Ldarg_0:
if (method.Parameters.IndexOf (parameter) == 0)
return true;
break;
case Code.Ldarg_1:
if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 1 : 0))
return true;
break;
case Code.Ldarg_2:
if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 2 : 1))
return true;
break;
case Code.Ldarg_3:
if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 3 : 2))
return true;
break;
case Code.Ldarg_S:
if (instruction.Operand.Equals (parameter))
return true;
break;
default:
break;
}
}
return false;
}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:30,代码来源:AvoidUnusedParametersRule.cs
示例7: InjectAsStreamReader
void InjectAsStreamReader(TypeDefinition targetType, FieldDefinition fieldDefinition)
{
AsStreamReaderMethod = new MethodDefinition("AsStreamReader", staticMethodAttributes, StreamReaderTypeReference);
var streamVariable = new VariableDefinition(StreamTypeReference);
AsStreamReaderMethod.Body.Variables.Add(streamVariable);
var pathParam = new ParameterDefinition(ModuleDefinition.TypeSystem.String);
AsStreamReaderMethod.Parameters.Add(pathParam);
AsStreamReaderMethod.Body.InitLocals = true;
var inst = AsStreamReaderMethod.Body.Instructions;
var skipReturn = Instruction.Create(OpCodes.Nop);
inst.Add(Instruction.Create(OpCodes.Ldsfld, fieldDefinition));
inst.Add(Instruction.Create(OpCodes.Ldarg, pathParam));
inst.Add(Instruction.Create(OpCodes.Callvirt, GetManifestResourceStreamMethod));
inst.Add(Instruction.Create(OpCodes.Stloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Brtrue_S, skipReturn));
inst.Add(Instruction.Create(OpCodes.Ldnull));
inst.Add(Instruction.Create(OpCodes.Ret));
inst.Add(skipReturn);
inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Newobj, StreamReaderConstructorReference));
inst.Add(Instruction.Create(OpCodes.Ret));
targetType.Methods.Add(AsStreamReaderMethod);
}
开发者ID:huoxudong125,项目名称:Resourcer,代码行数:29,代码来源:HelperClassInjector.cs
示例8: DomCecilParameter
public DomCecilParameter (ParameterDefinition parameterDefinition)
{
this.parameterDefinition = parameterDefinition;
base.Name = parameterDefinition.Name;
// base.modifiers = DomCecilType.GetModifiers (parameterDefinition..Attributes);
base.ReturnType = DomCecilMethod.GetReturnType (parameterDefinition.ParameterType);
if (parameterDefinition.ParameterType is Mono.Cecil.ReferenceType) {
this.ParameterModifiers = (parameterDefinition.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out ? ParameterModifiers.Out : ParameterModifiers.Ref;
} else {
this.ParameterModifiers = ParameterModifiers.In;
}
if ((parameterDefinition.Attributes & ParameterAttributes.Optional) == ParameterAttributes.Optional)
this.ParameterModifiers |= ParameterModifiers.Optional;
if ((parameterDefinition.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault) {
this.DefaultValue = new System.CodeDom.CodePrimitiveExpression (parameterDefinition.Constant);
}
if (ReturnType.ArrayDimensions > 0) {
foreach (CustomAttribute customAttribute in parameterDefinition.CustomAttributes) {
if (customAttribute.Constructor.DeclaringType.FullName == "System.ParamArrayAttribute")
this.ParameterModifiers |= ParameterModifiers.Params;
}
}
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:26,代码来源:DomCecilParameter.cs
示例9: Parameter
public Parameter(ParameterDefinition parameterDefinition, ComponentCache componentCache) : base(parameterDefinition.ParameterType, componentCache)
{
Contract.Requires<ArgumentNullException>(parameterDefinition != null);
parameter = parameterDefinition;
cache = componentCache;
}
开发者ID:artur02,项目名称:Dependency,代码行数:7,代码来源:Parameter.cs
示例10: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly()
{
var name = new AssemblyNameDefinition("TestBranchConditionTurtle", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestBranchConditionTurtle", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var boolType = assembly.MainModule.Import(typeof(bool));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
method.Parameters.Add(leftParam);
method.Parameters.Add(rightParam);
var resultVariable = new VariableDefinition(boolType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
Instruction storeTrueInReturnValueInstruction = processor.Create(OpCodes.Ldc_I4, -1);
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, leftParam));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, rightParam));
method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
method.Body.Instructions.Add(processor.Create(OpCodes.Brtrue_S, storeTrueInReturnValueInstruction));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Br_S, loadReturnValueInstruction));
method.Body.Instructions.Add(storeTrueInReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(loadReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
开发者ID:dbremner,项目名称:ninjaturtles,代码行数:35,代码来源:BranchConditionTurtleTests.cs
示例11: CheckForExistingGuard
private static bool CheckForExistingGuard(Collection<Instruction> instructions, ParameterDefinition parameter)
{
for (var i = 1; i < instructions.Count - 1; i++)
{
if (instructions[i].OpCode == OpCodes.Newobj)
{
var newObjectMethodRef = instructions[i].Operand as MethodReference;
if (newObjectMethodRef == null || instructions[i + 1].OpCode != OpCodes.Throw)
continue;
// Checks for throw new ArgumentNullException("x");
if (newObjectMethodRef.FullName == ReferenceFinder.ArgumentNullExceptionConstructor.FullName &&
instructions[i - 1].OpCode == OpCodes.Ldstr &&
(string)(instructions[i - 1].Operand) == parameter.Name)
return true;
// Checks for throw new ArgumentNullException("x", "some message");
if (newObjectMethodRef.FullName == ReferenceFinder.ArgumentNullExceptionWithMessageConstructor.FullName &&
i > 1 &&
instructions[i - 2].OpCode == OpCodes.Ldstr &&
(string)(instructions[i - 2].Operand) == parameter.Name)
return true;
}
}
return false;
}
开发者ID:JakeGinnivan,项目名称:NullGuard,代码行数:28,代码来源:MethodProcessor.cs
示例12: LoadArgumentOntoStack
public static void LoadArgumentOntoStack(List<Instruction> instructions, ParameterDefinition parameter)
{
// Load the argument onto the stack
instructions.Add(Instruction.Create(OpCodes.Ldarg, parameter));
var elementType = parameter.ParameterType.GetElementType();
if (parameter.ParameterType.IsByReference)
{
if (elementType.IsGenericParameter)
{
// Loads an object reference onto the stack
instructions.Add(Instruction.Create(OpCodes.Ldobj, elementType));
// Box the type to an object
instructions.Add(Instruction.Create(OpCodes.Box, elementType));
}
else
{
// Loads an object reference onto the stack
instructions.Add(Instruction.Create(OpCodes.Ldind_Ref));
}
}
else if (elementType.IsGenericParameter)
{
// Box the type to an object
instructions.Add(Instruction.Create(OpCodes.Box, parameter.ParameterType));
}
}
开发者ID:dpisanu,项目名称:NullGuard,代码行数:29,代码来源:InstructionPatterns.cs
示例13: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly()
{
var name = new AssemblyNameDefinition("TestArithmeticOperatorTurtleAdd", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestArithmeticOperatorTurtleAdd", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
method.Parameters.Add(leftParam);
method.Parameters.Add(rightParam);
var resultVariable = new VariableDefinition(intType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg_1));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg_2));
method.Body.Instructions.Add(processor.Create(OpCodes.Add));
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
开发者ID:dbremner,项目名称:ninjaturtles,代码行数:27,代码来源:MethodTurtleBaseTests.cs
示例14: ImplementISetThis
/// <summary>
/// Implement IAsyncSetThis.
/// </summary>
private static void ImplementISetThis(TypeDefinition type, ReachableContext reachableContext)
{
var thisField = type.Fields.FirstOrDefault(x => x.Name.StartsWith("<>") && x.Name.EndsWith("__this"));
if (thisField == null)
return;
// Add interface
var intfType = type.Module.Import(new TypeReference(InternalConstants.Dot42InternalNamespace, "IAsyncSetThis", type.Module, type.Module.Assembly.Name));
type.Interfaces.Add(new InterfaceImpl(intfType));
// Add "SetThis(object)" method
var method = new MethodDefinition("SetThis", MethodAttributes.Public, type.Module.TypeSystem.Void);
method.SetReachable(reachableContext);
type.Methods.Add(method);
var valueParam = new ParameterDefinition(type.Module.TypeSystem.Object);
method.Parameters.Add(valueParam);
method.Body = new MethodBody(method) { InitLocals = true };
var seq = new ILSequence();
seq.Emit(OpCodes.Ldarg_0); // this
seq.Emit(OpCodes.Ldarg, valueParam);
seq.Emit(OpCodes.Castclass, thisField.FieldType);
seq.Emit(OpCodes.Stfld, thisField);
seq.Emit(OpCodes.Ret);
seq.AppendTo(method.Body);
}
开发者ID:rfcclub,项目名称:dot42,代码行数:28,代码来源:AsyncStateMachineConverter.cs
示例15: Execute
public static MethodDefinition Execute(PropertyDefinition property_definition, MethodDefinition notify_method, DependencyMap map)
{
log.Trace("\t\t\t\t\tAdding collection notification method for " + property_definition.Name);
// Create method
TypeReference return_type = property_definition.Module.Import(typeof (void));
MethodDefinition collection_notification = new MethodDefinition(property_definition.Name + "CollectionNotification", Mono.Cecil.MethodAttributes.Private | Mono.Cecil.MethodAttributes.HideBySig, return_type);
// Add parameters
TypeReference sender_type = property_definition.Module.Import(typeof(object));
TypeReference args_type = property_definition.Module.Import(typeof(NotifyCollectionChangedEventArgs));
ParameterDefinition sender = new ParameterDefinition("sender", Mono.Cecil.ParameterAttributes.None, sender_type);
ParameterDefinition args = new ParameterDefinition("args", Mono.Cecil.ParameterAttributes.None, args_type);
collection_notification.Parameters.Add(sender);
collection_notification.Parameters.Add(args);
// Add notifications for dependent properties
ILProcessor processor = collection_notification.Body.GetILProcessor();
foreach (var target in map.GetDependenciesFor(property_definition.Name))
{
log.Trace("\t\t\t\t\t\tAdding dependency " + target);
processor.Emit(OpCodes.Ldarg_0);
processor.Emit(OpCodes.Ldstr, target);
processor.Emit(OpCodes.Call, notify_method);
}
processor.Emit(OpCodes.Ret);
// Add method to class
property_definition.DeclaringType.Methods.Add(collection_notification);
return collection_notification;
}
开发者ID:lycilph,项目名称:Projects,代码行数:33,代码来源:AddCollectionNotificationMethodTask.cs
示例16: Run
public override void Run()
{
//Import TerrariaEntity as the base type of Terraria.Entity
this.Type<Terraria.Entity>().BaseType = SourceDefinition.MainModule.Import(
this.Type<OTAPI.TerrariaEntity>()
);
var switchTiles = this.SourceDefinition.Type("Terraria.Collision").Method("SwitchTiles");
var iEntity = switchTiles.Module.Import(
this.Type<IEntity>()
);
//Add the sender parameter to the vanilla method
ParameterDefinition prmSender;
switchTiles.Parameters.Add(prmSender = new ParameterDefinition("sender", ParameterAttributes.None, iEntity)
{
HasDefault = true,
IsOptional = true,
Constant = null
});
//Update all references to the method so the caller adds themselves (currently they are all senders, woo!)
this.SourceDefinition.MainModule.ForEachInstruction((mth, ins) =>
{
if (ins.OpCode == OpCodes.Call && ins.Operand == switchTiles)
{
var cil = mth.Body.GetILProcessor();
cil.InsertBefore(ins, cil.Create(OpCodes.Ldarg_0));
}
});
}
开发者ID:DeathCradle,项目名称:Open-Terraria-API,代码行数:31,代码来源:SwitchTilesEntity.cs
示例17: CreateDisposeBoolMethod
void CreateDisposeBoolMethod()
{
DisposeBoolMethod = new MethodDefinition("Dispose", MethodAttributes.HideBySig | MethodAttributes.Private, typeSystem.Void);
var disposingParameter = new ParameterDefinition("disposing", ParameterAttributes.None, typeSystem.Boolean);
DisposeBoolMethod.Parameters.Add(disposingParameter);
var instructions = DisposeBoolMethod.Body.Instructions;
instructions.Add(TypeProcessor.GetDisposeEscapeInstructions());
var skipDisposeManaged = Instruction.Create(OpCodes.Nop);
instructions.Add(
Instruction.Create(OpCodes.Ldarg, disposingParameter),
Instruction.Create(OpCodes.Brfalse, skipDisposeManaged),
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Call, DisposeManagedMethod),
skipDisposeManaged,
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Call, DisposeUnmanagedMethod)
);
instructions.Add(TypeProcessor.GetDisposedInstructions());
instructions.Add(Instruction.Create(OpCodes.Ret));
TypeProcessor.TargetType.Methods.Add(DisposeBoolMethod);
}
开发者ID:petarvucetin,项目名称:Janitor,代码行数:25,代码来源:ManagedAndUnmanagedProcessor.cs
示例18: GetKind
private static XParameterKind GetKind(ParameterDefinition p)
{
if (p.IsIn && p.IsOut)
return XParameterKind.ByReference;
if (p.IsOut) return XParameterKind.Output;
return XParameterKind.Input;
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:7,代码来源:XBuilder.Parameter.cs
示例19: CreateCopyFromMethod
/// <summary>
/// Create a CopyFrom method.
/// </summary>
private static MethodDefinition CreateCopyFromMethod(ReachableContext reachableContext, TypeDefinition type)
{
var typeSystem = type.Module.TypeSystem;
var method = new MethodDefinition(NameConstants.Struct.CopyFromMethodName, MethodAttributes.Public, type);
var sourceParam = new ParameterDefinition(type);
method.Parameters.Add(sourceParam);
method.DeclaringType = type;
var body = new MethodBody(method);
body.InitLocals = true;
method.Body = body;
// Prepare code
var seq = new ILSequence();
seq.Emit(OpCodes.Nop);
// Call base CopyFrom
var baseType = (type.BaseType != null) ? type.BaseType.GetElementType().Resolve() : null;
if ((baseType != null) && baseType.IsValueType && (baseType.FullName != "System.ValueType"))
{
var baseMethod = new MethodReference(NameConstants.Struct.CopyFromMethodName, baseType, baseType) { HasThis = true };
baseMethod.Parameters.Add(new ParameterDefinition(baseType));
seq.Emit(OpCodes.Ldarg, sourceParam);
seq.Emit(OpCodes.Call, baseMethod);
}
// Copy all fields
foreach (var field in type.Fields.Where(x => !x.IsStatic))
{
// Not need to bother with cloning struct-type fields here,
// as this will be done automatically by one of the Converters.
// Prepare for stfld
seq.Emit(OpCodes.Ldarg, body.ThisParameter);
// Load from source
seq.Emit(OpCodes.Ldarg, sourceParam);
seq.Emit(OpCodes.Ldfld, field);
// Save in this
seq.Emit(OpCodes.Stfld, field);
}
// Return this
seq.Emit(OpCodes.Ldarg, body.ThisParameter);
seq.Emit(OpCodes.Ret);
// Append ret sequence
seq.AppendTo(body);
// Update offsets
body.ComputeOffsets();
// Add method
type.Methods.Add(method);
method.SetReachable(reachableContext);
return method;
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:62,代码来源:StructSemanticsMethods.cs
示例20: DocumentedParameter
/// <summary>
/// Initializes a new instance of the <see cref="DocumentedParameter"/> class.
/// </summary>
/// <param name="definition">The parameter definition.</param>
/// <param name="comment">The parameter comment.</param>
/// <param name="metadata">The associated metadata.</param>
public DocumentedParameter(ParameterDefinition definition, ParamComment comment, IDocumentationMetadata metadata)
: base(MemberClassification.Parameter, null, null, null, metadata)
{
_definition = definition;
_comment = comment;
_isOutParameter = definition.IsOut;
_isRefParameter = definition.ParameterType is ByReferenceType;
}
开发者ID:naasking,项目名称:website,代码行数:14,代码来源:DocumentedParameter.cs
注:本文中的Mono.Cecil.ParameterDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论