本文整理汇总了C#中MethodDefinition类的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition类的具体用法?C# MethodDefinition怎么用?C# MethodDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodDefinition类属于命名空间,在下文中一共展示了MethodDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ProcessMethod
void ProcessMethod(MethodDefinition method)
{
if (method == null)
{
return;
}
if (method.IsFinal)
{
return;
}
if (method.IsStatic)
{
return;
}
if (method.IsVirtual)
{
return;
}
if (method.IsPrivate)
{
return;
}
method.IsVirtual = true;
method.IsNewSlot = true;
}
开发者ID:rwecho,项目名称:Experiments,代码行数:25,代码来源:TypeProcessor.cs
示例2: ProcessMethod
void ProcessMethod(MethodDefinition method)
{
var asyncAttribute = method.CustomAttributes.FirstOrDefault(_ => _.AttributeType.Name == "AsyncStateMachineAttribute");
if (asyncAttribute == null)
{
var methodProcessor = new MethodProcessor
{
ModuleWeaver = this,
TypeSystem = ModuleDefinition.TypeSystem,
Method = method,
};
methodProcessor.InnerProcess();
return;
}
LogError(string.Format("Could not process '{0}'. async methods are not currently supported. Feel free to submit a pull request if you want this feature.", method.FullName));
//var fullName = method.FullName;
//var customAttributeArgument = asyncAttribute.ConstructorArguments.First();
//var typeReference = (TypeReference) customAttributeArgument.Value;
//var asyncTypeDefinition = typeReference.Resolve();
//var methodProcessorAsync = new MethodProcessorAsync
// {
// ModuleWeaver = this,
// TypeSystem = ModuleDefinition.TypeSystem,
// AsyncTypeReference = asyncTypeDefinition,
// OriginalMethod = method
// };
//methodProcessorAsync.Process();
}
开发者ID:GavinOsborn,项目名称:MethodTimer,代码行数:30,代码来源:AssemblyProcessor.cs
示例3: AddGetItem
void AddGetItem()
{
var method = new MethodDefinition(DataErrorInfoFinder.InterfaceRef.FullName + ".get_Item", MethodAttributes, TypeSystem.String)
{
IsGetter = true,
IsPrivate = true,
SemanticsAttributes = MethodSemanticsAttributes.Getter,
};
method.Overrides.Add(DataErrorInfoFinder.GetItemMethod);
method.Parameters.Add(new ParameterDefinition(TypeSystem.String));
method.Body.Instructions.Append(
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Ldfld, ValidationTemplateField),
Instruction.Create(OpCodes.Ldarg_1),
Instruction.Create(OpCodes.Callvirt, DataErrorInfoFinder.GetItemMethod),
Instruction.Create(OpCodes.Ret));
var property = new PropertyDefinition(DataErrorInfoFinder.InterfaceRef.FullName + ".Item", PropertyAttributes.None, TypeSystem.String)
{
GetMethod = method,
};
TypeDefinition.Methods.Add(method);
TypeDefinition.Properties.Add(property);
}
开发者ID:kedarvaidya,项目名称:Validar,代码行数:25,代码来源:DataErrorInfoInjector.cs
示例4: FindIsChangedEventInvokerMethodDefinition
bool FindIsChangedEventInvokerMethodDefinition(TypeDefinition type, out MethodDefinition methodDefinition)
{
//todo: check bool type
methodDefinition = null;
var propertyDefinition = type.Properties
.FirstOrDefault(x =>
x.Name == isChangedPropertyName &&
x.SetMethod != null &&
x.SetMethod.IsPublic
);
if (propertyDefinition != null)
{
if (propertyDefinition.PropertyType.FullName != ModuleDefinition.TypeSystem.Boolean.FullName)
{
LogWarning(string.Format("Found '{0}' but is was of type '{1}' instead of '{2}' so it will not be used.", propertyDefinition.GetName(), propertyDefinition.PropertyType.Name, ModuleDefinition.TypeSystem.Boolean.Name));
return false;
}
if (propertyDefinition.SetMethod.IsStatic)
{
throw new WeavingException(string.Format("Found '{0}' but is was static. Change it to non static.", propertyDefinition.GetName()));
}
methodDefinition = propertyDefinition.SetMethod;
}
return methodDefinition != null;
}
开发者ID:jbruening,项目名称:PropertyChanged,代码行数:26,代码来源:IsChangedMethodFinder.cs
示例5: Process
public void Process(MethodDefinition method)
{
method.Body.SimplifyMacros();
var instructions = method.Body.Instructions;
for (var index = 0; index < instructions.Count; index++)
{
var line = instructions[index];
if (line.OpCode != OpCodes.Call)
{
continue;
}
var methodReference = line.Operand as MethodReference;
if (methodReference == null)
{
continue;
}
if (IsSetExceptionMethod(methodReference))
{
var previous = instructions[index-1];
instructions.Insert(index, Instruction.Create(OpCodes.Call, HandleMethodFinder.HandleMethod));
index++;
instructions.Insert(index, Instruction.Create(previous.OpCode, (VariableDefinition)previous.Operand));
index++;
}
}
method.Body.OptimizeMacros();
}
开发者ID:krtrego,项目名称:AsyncErrorHandler,代码行数:30,代码来源:MethodProcessor.cs
示例6: CloneMethodWithDeclaringType
private static MethodReference CloneMethodWithDeclaringType(MethodDefinition methodDef, TypeReference declaringTypeRef)
{
if (!declaringTypeRef.IsGenericInstance || methodDef == null)
{
return methodDef;
}
var methodRef = new MethodReference(methodDef.Name, methodDef.ReturnType, declaringTypeRef)
{
CallingConvention = methodDef.CallingConvention,
HasThis = methodDef.HasThis,
ExplicitThis = methodDef.ExplicitThis
};
foreach (var paramDef in methodDef.Parameters)
{
methodRef.Parameters.Add(new ParameterDefinition(paramDef.Name, paramDef.Attributes, paramDef.ParameterType));
}
foreach (var genParamDef in methodDef.GenericParameters)
{
methodRef.GenericParameters.Add(new GenericParameter(genParamDef.Name, methodRef));
}
return methodRef;
}
开发者ID:mdabbagh88,项目名称:Ionad,代码行数:26,代码来源:CecilExtensions.cs
示例7: CodeReader
public CodeReader (MethodDefinition method, MetadataReader reader)
: base (reader.image.Stream)
{
this.reader = reader;
this.reader.context = method;
this.Position = (int) reader.image.ResolveVirtualAddress ((uint) method.RVA);
}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:7,代码来源:CodeReader.cs
示例8: CreateDefaultConstructor
/// <summary>
/// Creates the default constructor.
/// </summary>
public MethodDefinition CreateDefaultConstructor(TypeDefinition type)
{
_logInfo("AddDefaultConstructor() " + type.Name);
// Create method for a constructor
var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
var method = new MethodDefinition(".ctor", methodAttributes, _moduleDefinition.TypeSystem.Void);
// Set parameters for constructor, and add corresponding assignment in method body:
// 1. Add each property in the class as a parameter for the constructor
// 2. Set the properties in the class from the constructor parameters
// Properties marked with the [ImmutableClassIgnore] attribute are ignored
foreach (var prop in type.Properties)
{
if (prop.CustomAttributes.ContainsAttribute("ImmutableClassIgnoreAttribute"))
{
_logInfo("Ignoring property " + prop.Name);
continue;
}
string paramName = Char.ToLowerInvariant(prop.Name [0]) + prop.Name.Substring (1); // convert first letter of name to lowercase
_logInfo("Adding parameter " + paramName + " to ctor");
var pd = (new ParameterDefinition(paramName, ParameterAttributes.HasDefault, prop.PropertyType));
method.Parameters.Add(pd);
_logInfo("Setting property " + prop.Name);
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg, pd));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, prop.SetMethod));
}
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
return method;
}
开发者ID:taiste,项目名称:ImmutableClass.Fody,代码行数:35,代码来源:MethodCreator.cs
示例9: PInvokeInfo
public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs,
string entryPoint, ModuleReference mod) : this (meth)
{
m_attributes = attrs;
m_entryPoint = entryPoint;
m_module = mod;
}
开发者ID:pusp,项目名称:o2platform,代码行数:7,代码来源:PInvokeInfo.cs
示例10: IsAssertMethod
public bool IsAssertMethod(MethodDefinition method, out int usefulParameters)
{
SafeDebug.AssumeNotNull(method, "method");
TypeDefinition type;
if (method.TryGetDeclaringType(out type))
{
if (type.SerializableName == NUnitTestFrameworkMetadata.AssertTypeDefinition)
{
switch (method.ShortName)
{
case "IsEmpty":
case "IsNotEmpty":
case "False":
case "IsFalse":
case "True":
case "IsTrue":
case "IsAssignableFrom":
case "IsNotAssignableFrom":
case "IsNull":
case "IsNotNull":
case "Null":
case "NotNull":
case "IsNotNullOrEmpty":
case "IsNullOrEmpty":
case "IsNan":
case "IsInstanceOf": //not entirely correct
case "IsNotInstanceOf": //not entirely correct
usefulParameters = 1;
return true;
case "AreEqual":
case "AssertDoublesAreEqual":
case "AreNotEqual":
case "Contains":
case "AreSame":
case "AreNotSame":
case "Greater":
case "GreaterOrEqual":
case "Less":
case "LessOrEqual":
usefulParameters = 2;
return true;
}
}
else if (type.SerializableName == NUnitTestFrameworkMetadata.CollectionAssertTypeDefinition)
{
switch (method.ShortName)
{
case "Equals":
case "ReferenceEquals":
usefulParameters = -1;
return false;
default:
usefulParameters = 0;
return true;
}
}
}
usefulParameters = -1;
return false;
}
开发者ID:ChrisMaddock,项目名称:nunit-vs-testgenerator,代码行数:60,代码来源:NUnitAssertMethodFilter.cs
示例11: IsSecurityCritical
public bool IsSecurityCritical (MethodDefinition method)
{
string entry = method.GetFullName ();
if (critical.Contains (entry))
return true;
TypeDefinition type = method.DeclaringType;
if (!IsSecurityCritical (type))
return false;
switch (method.Name) {
// e.g. everything we override from System.Object (which is transparent)
case "Equals":
return (method.Parameters.Count != 1 || method.Parameters [0].ParameterType.FullName != "System.Object");
case "Finalize":
case "GetHashCode":
case "ToString":
return method.HasParameters;
// e.g. some transparent interfaces, like IDisposable (implicit or explicit)
// downgrade some SC into SSC to respect the override/inheritance rules
case "System.IDisposable.Dispose":
case "Dispose":
return method.HasParameters;
default:
return true;
}
}
开发者ID:dfr0,项目名称:moon,代码行数:27,代码来源:detect.cs
示例12: 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
示例13: GetSingleField
static FieldDefinition GetSingleField(PropertyDefinition property, Code code, MethodDefinition methodDefinition)
{
if (methodDefinition?.Body == null)
{
return null;
}
FieldReference fieldReference = null;
foreach (var instruction in methodDefinition.Body.Instructions)
{
if (instruction.OpCode.Code == code)
{
//if fieldReference is not null then we are at the second one
if (fieldReference != null)
{
return null;
}
var field = instruction.Operand as FieldReference;
if (field != null)
{
if (field.DeclaringType != property.DeclaringType)
{
continue;
}
if (field.FieldType != property.PropertyType)
{
continue;
}
fieldReference = field;
}
}
}
return fieldReference?.Resolve();
}
开发者ID:Fody,项目名称:PropertyChanging,代码行数:33,代码来源:MappingFinder.cs
示例14: Parse
public static void Parse (MethodDefinition method, IILVisitor visitor)
{
if (method == null)
throw new ArgumentNullException ("method");
if (visitor == null)
throw new ArgumentNullException ("visitor");
if (!method.HasBody || !method.HasImage)
throw new ArgumentException ();
var context = CreateContext (method, visitor);
var code = context.Code;
code.MoveTo (method.RVA);
var flags = code.ReadByte ();
switch (flags & 0x3) {
case 0x2: // tiny
int code_size = flags >> 2;
ParseCode (code_size, context);
break;
case 0x3: // fat
code.position--;
ParseFatMethod (context);
break;
default:
throw new NotSupportedException ();
}
}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:29,代码来源:ILParser.cs
示例15: CodeReader
/// <summary>
/// Default ctor
/// </summary>
internal CodeReader(MethodDefinition method, CodeAttribute codeAttribute, byte[] code, ConstantPool cp)
{
this.method = method;
this.codeAttribute = codeAttribute;
this.code = code;
this.cp = cp;
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:CodeReader.cs
示例16: Execute
public void Execute(MethodDefinition getMethod)
{
processedMethods.Add(getMethod);
if (getMethod.Body == null)
{
return;
}
foreach (var instruction in getMethod.Body.Instructions)
{
Instructions.Add(instruction);
if (!IsCall(instruction.OpCode))
{
continue;
}
var methodDefinition = instruction.Operand as MethodDefinition;
if (methodDefinition == null)
{
continue;
}
if (methodDefinition.IsGetter || methodDefinition.IsSetter)
{
continue;
}
if (processedMethods.Contains(methodDefinition))
{
continue;
}
if (methodDefinition.DeclaringType != typeDefinition)
{
continue;
}
Execute(methodDefinition);
}
}
开发者ID:chantsunman,项目名称:PropertyChanged,代码行数:34,代码来源:RecursiveIlFinder.cs
示例17: ProcessMethod
void ProcessMethod(MethodDefinition method)
{
if (method.IsYield())
{
if (method.ContainsTimeAttribute())
{
LogError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
return;
}
LogInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
return;
}
if (method.IsAsync())
{
var asyncProcessor = new AsyncMethodProcessor
{
ModuleWeaver = this,
Method = method,
};
asyncProcessor.Process();
return;
}
var methodProcessor = new MethodProcessor
{
ModuleWeaver = this,
Method = method,
};
methodProcessor.Process();
}
开发者ID:roberocity,项目名称:MethodTimer,代码行数:32,代码来源:AssemblyProcessor.cs
示例18: IsBeforeAfterOnChangedMethod
public static bool IsBeforeAfterOnChangedMethod(MethodDefinition method)
{
var parameters = method.Parameters;
return parameters.Count == 2
&& parameters[0].ParameterType.FullName == "System.Object"
&& parameters[1].ParameterType.FullName == "System.Object";
}
开发者ID:jbruening,项目名称:PropertyChanged,代码行数:7,代码来源:OnChangedWalker.cs
示例19: Replace
void Replace(MethodDefinition methodDefinition)
{
if (methodDefinition == null)
{
return;
}
if (methodDefinition.IsAbstract)
{
return;
}
//for delegates
if (methodDefinition.Body == null)
{
return;
}
foreach (var instruction in methodDefinition.Body.Instructions)
{
if (instruction.OpCode != OpCodes.Call)
{
continue;
}
foreach (var method in MethodCache)
{
if (instruction.Operand == method)
{
instruction.OpCode = OpCodes.Callvirt;
}
}
}
}
开发者ID:philippdolder,项目名称:Virtuosity,代码行数:31,代码来源:CallToCallVirtConverter.cs
示例20: Read
public MethodDebugInformation Read(MethodDefinition method)
{
var method_token = method.MetadataToken;
PdbFunction function;
if (!functions.TryGetValue (method_token.ToUInt32 (), out function))
return null;
var symbol = new MethodDebugInformation (method);
ReadSequencePoints (function, symbol);
if (!function.scopes.IsNullOrEmpty())
symbol.scope = ReadScopeAndLocals (function.scopes [0], symbol);
if (function.scopes.Length > 1) {
for (int i = 1; i < function.scopes.Length; i++) {
var s = ReadScopeAndLocals (function.scopes [i], symbol);
if (!AddScope (symbol.scope.Scopes, s))
symbol.scope.Scopes.Add (s);
}
}
return symbol;
}
开发者ID:jbevain,项目名称:cecil,代码行数:25,代码来源:PdbReader.cs
注:本文中的MethodDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论