本文整理汇总了C#中Mono.Cecil.TypeReference类的典型用法代码示例。如果您正苦于以下问题:C# TypeReference类的具体用法?C# TypeReference怎么用?C# TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeReference类属于Mono.Cecil命名空间,在下文中一共展示了TypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwapParameterTypes
private static void SwapParameterTypes(MethodDefinition method,
TypeDefinition targetDependency,
TypeReference interfaceType,
HashSet<MethodReference> modifiedMethods)
{
if (method.IsAbstract || !method.HasBody)
return;
bool modified = false;
var parameters = method.Parameters.Cast<ParameterDefinition>();
foreach (var parameter in parameters)
{
var parameterType = parameter.ParameterType;
if (parameterType != targetDependency)
continue;
parameter.ParameterType = interfaceType;
modified = true;
}
if (!modified)
return;
modifiedMethods.Add(method);
}
示例2: InsertInstruction
public void InsertInstruction()
{
var object_ref = new TypeReference ("System", "Object", null, false);
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref);
var body = new MethodBody (method);
var il = body.GetILProcessor ();
var first = il.Create (OpCodes.Nop);
var second = il.Create (OpCodes.Nop);
var third = il.Create (OpCodes.Nop);
body.Instructions.Add (first);
body.Instructions.Add (third);
Assert.IsNull (first.Previous);
Assert.AreEqual (third, first.Next);
Assert.AreEqual (first, third.Previous);
Assert.IsNull (third.Next);
body.Instructions.Insert (1, second);
Assert.IsNull (first.Previous);
Assert.AreEqual (second, first.Next);
Assert.AreEqual (first, second.Previous);
Assert.AreEqual (third, second.Next);
Assert.AreEqual (second, third.Previous);
Assert.IsNull (third.Next);
}
示例3: Resolve
public static TypeDefinition Resolve(IAssemblyResolver resolver, TypeReference type)
{
type = type.GetElementType ();
var scope = type.Scope;
switch (scope.MetadataScopeType) {
case MetadataScopeType.AssemblyNameReference:
var assembly = resolver.Resolve ((AssemblyNameReference) scope);
if (assembly == null)
return null;
return GetType (assembly.MainModule, type);
case MetadataScopeType.ModuleDefinition:
return GetType ((ModuleDefinition) scope, type);
case MetadataScopeType.ModuleReference:
var modules = type.Module.Assembly.Modules;
var module_ref = (ModuleReference) scope;
for (int i = 0; i < modules.Count; i++) {
var netmodule = modules [i];
if (netmodule.Name == module_ref.Name)
return GetType (netmodule, type);
}
break;
}
throw new NotSupportedException ();
}
示例4: EventDefinition
public EventDefinition(string name, TypeReference eventType,
EventAttributes attrs)
: base(name)
{
m_eventType = eventType;
m_attributes = attrs;
}
示例5:
public Tuple<TypeDefinition, AssemblyDefinition> this[TypeReference typ, AssemblyDefinition assembly]
{
get
{
return this[typ, assembly.Name];
}
}
示例6: TypeNode
public TypeNode(string name, string parent = "", bool builtIn = false, TypeReference type = null)
{
Name = name;
Type = type;
Parent = parent;
BuiltIn = builtIn;
}
示例7: addType
public TypeDefinition addType(String sTypeNameSpace, String sTypeName, TypeAttributes taTypeAttributes,
TypeReference trTypeReference)
{
var tdNewType = new TypeDefinition(sTypeName, sTypeNameSpace, taTypeAttributes, trTypeReference);
mainModule.Types.Add(tdNewType);
return tdNewType;
}
示例8: BinaryExpression
public BinaryExpression(BinaryOperator @operator, Expression left, Expression right,
TypeReference expressionType, TypeSystem typeSystem, IEnumerable<Instruction> instructions, bool isOverridenOperation = false)
: this(@operator, left, right, DetermineIsChecked(instructions), instructions, isOverridenOperation)
{
this.ExpressionType = expressionType;
this.typeSystem = typeSystem;
}
示例9: CreateInstanceOfType
public JSInvocationExpression CreateInstanceOfType(TypeReference type)
{
return JSInvocationExpression.InvokeStatic(
Dot(new JSFakeMethod("CreateInstanceOfType", type, new[] { TypeSystem.Object }, MethodTypes)),
new[] { new JSTypeOfExpression(type) }
);
}
示例10: Coalesce
public JSInvocationExpression Coalesce(JSExpression left, JSExpression right, TypeReference expectedType)
{
return JSInvocationExpression.InvokeStatic(
Dot("Coalesce", expectedType),
new[] { left, right }, true
);
}
示例11: DynamicIndexerExpression
private DynamicIndexerExpression(Expression target, ExpressionCollection indices, TypeReference expressionType, IEnumerable<Instruction> instructions)
:base(instructions)
{
this.Target = target;
this.Indices = indices;
this.ExpressionType = expressionType;
}
示例12: PickTypeKeyword
public static string PickTypeKeyword(TypeReference type)
{
// FIXME
switch (type.FullName) {
case "System.Void":
return "void";
case "System.Boolean":
case "System.Int32":
case "System.UInt32":
return "i32";
case "System.Int64":
case "System.UInt64":
return "i64";
case "System.Single":
return "f32";
case "System.Double":
return "f64";
case "System.Byte":
case "System.UInt16":
case "System.SByte":
case "System.Int16":
return "i32";
}
return null;
}
示例13: ShouldAddCast
private bool ShouldAddCast(Expression argument, List<MethodDefinition> sameNameMethods, int argumentIndex, TypeReference calledMethodParamType)
{
if (!argument.HasType)
{
return true;
}
TypeReference expressionType = argument.ExpressionType;
//if (argument.ExpressionType.IsGenericParameter)
//{
// return false;
//}
foreach (MethodDefinition method in sameNameMethods)
{
TypeReference parameterType = method.Parameters[argumentIndex].ParameterType;
if (IsTypeDescendantOf(calledMethodParamType, parameterType) || calledMethodParamType.FullName == parameterType.FullName)
{
/// Either the called method has more specific type,
/// or the types match.
continue;
}
if (IsTypeDescendantOf(expressionType, parameterType) || expressionType.FullName == parameterType.FullName)
{
return true;
}
if (argument.CodeNodeType == CodeNodeType.LiteralExpression && ((LiteralExpression)argument).Value == null)
{
if (!parameterType.IsValueType)
{
return true;
}
}
}
return false;
}
示例14: FindDerivedFrom
public void FindDerivedFrom(TypeReference baseTypeRef)
{
foreach (var td in _module.Types) {
if(IsDerivedFrom(td, baseTypeRef))
Console.WriteLine (td.FullName);
}
}
示例15: ArrayCreationExpression
public ArrayCreationExpression(TypeReference type, InitializerExpression initializer, IEnumerable<Instruction> instructions)
:base(instructions)
{
this.ElementType = type;
this.Initializer = initializer;
this.Dimensions = new ExpressionCollection();
}