本文整理汇总了C#中Mono.Cecil.TypeReference.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.Resolve方法的具体用法?C# TypeReference.Resolve怎么用?C# TypeReference.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeReference
的用法示例。
在下文中一共展示了TypeReference.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
internal static void Initialize(ModuleDefinition moduleDefinition)
{
ModuleDefinition = moduleDefinition;
typeType = ModuleDefinition.Import(typeof(Type));
taskType = ModuleDefinition.Import(typeof(Task));
getTypeFromRuntimeHandleMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetTypeFromHandle"));
typeGetMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetMethod" && x.Parameters.Count == 5));
taskTType = ModuleDefinition.Import(typeof(Task<>));
taskFromResult = ModuleDefinition.Import(taskType.Resolve().Methods.Single(x => x.Name == "FromResult"));
}
示例2: Process
/// <summary>
/// Transform open generic types to closed instantiation using context information.
/// As an example, if B{T} inherits from A{T}, running it with B{C} as context and A{B.T} as type, ti will return A{C}.
/// </summary>
public static TypeReference Process(TypeReference context, TypeReference type)
{
if (type == null)
return null;
var genericInstanceTypeContext = context as GenericInstanceType;
if (genericInstanceTypeContext == null)
return type;
if (genericInstanceTypeContext.ContainsGenericParameter())
return type;
// Build dictionary that will map generic type to their real implementation type
var resolvedType = context.Resolve();
var genericTypeMapping = new Dictionary<TypeReference, TypeReference>();
for (int i = 0; i < resolvedType.GenericParameters.Count; ++i)
{
var genericParameter = context.GetElementType().Resolve().GenericParameters[i];
genericTypeMapping.Add(genericParameter, genericInstanceTypeContext.GenericArguments[i]);
}
var visitor = new ResolveGenericsVisitor(genericTypeMapping);
var result = visitor.VisitDynamic(type);
// Make sure type is closed now
if (result.ContainsGenericParameter())
throw new InvalidOperationException("Unsupported generic resolution.");
return result;
}
示例3: IsAssignableFrom
public static bool IsAssignableFrom(this TypeReference baseType, TypeReference type, Action<string> logger = null)
{
if (type.IsGenericParameter)
return baseType.CompareTo(type);
return baseType.Resolve().IsAssignableFrom(type.Resolve(), logger);
}
示例4: IsValueTypeBlittable
/// <summary>
/// Determines whether the specified value type is blittable.
/// </summary>
/// <param name="typeReference">The type reference.</param>
/// <param name="marshalInfo">The marshal information.</param>
/// <returns></returns>
private static bool IsValueTypeBlittable(TypeReference typeReference, MarshalInfo marshalInfo)
{
bool isBlittable;
if (blittableValueTypes.TryGetValue(typeReference, out isBlittable))
return isBlittable;
var typeDefinition = typeReference.Resolve();
// Only value types are blittable
if (typeDefinition.IsValueType)
{
isBlittable = true;
if (!typeDefinition.IsEnum && !typeDefinition.IsExplicitLayout)
{
// Check if every field is blittable
foreach (var field in typeDefinition.Fields)
{
if (field.IsStatic)
continue;
var fieldType = ResolveGenericsVisitor.Process(typeReference, field.FieldType);
if (!IsBlittable(fieldType, field.HasMarshalInfo ? field.MarshalInfo : null))
{
isBlittable = false;
break;
}
}
}
}
blittableValueTypes[typeReference] = isBlittable;
return isBlittable;
}
示例5: AddRole
private void AddRole(TypeReference role)
{
var memberReader = new MemberReaderVisitor();
role.Resolve().Accept(memberReader);
var roleMembers = memberReader.Members.Select(member => MakeRoleMember(role, member));
AddRoleMembers(role, roleMembers);
}
示例6: AspectWeaver
public AspectWeaver(TypeReference aspectType)
{
_type = aspectType.Resolve();
_onExecute = _type.Methods.FirstOrDefault(m => m.Name == "OnExecute");
_onComplete = _type.Methods.FirstOrDefault(m => m.Name == "OnComplete");
_onException = _type.Methods.FirstOrDefault(m => m.Name == "OnException");
_requiresAspectInstance = (_onExecute != null && !_onExecute.IsStatic)
|| (_onComplete != null && !_onComplete.IsStatic)
|| (_onException != null && !_onException.IsStatic);
if (_requiresAspectInstance)
{
_aspectCtor = _type.Methods.FirstOrDefault(m => m.IsConstructor && !m.HasParameters);
if (_aspectCtor == null)
{
throw new Exception(String.Format("Parameterless constructor required for {0}.", _type.Name));
}
}
_requiresCorrelationVariable = _onExecute != null
&& _onExecute.IsStatic
&& !_onExecute.ReturnType.TypeMatches(typeof(void));
if (_requiresCorrelationVariable)
{
_correlationType = _onExecute.ReturnType;
}
_aspectInstanceVariableName = String.Format("aspectInstance_{0}", _type.Name);
_correlationVariableName = String.Format("aspectCorrelation_{0}", _type.Name);
_exceptionVariableName = String.Format("aspectException_{0}", _type.Name);
}
示例7: ResolveType
private TypeDefinition ResolveType(TypeReference aRef)
{
var xDef = aRef as TypeDefinition;
if (xDef != null)
{
return xDef;
}
#if DEBUG
var xArray = aRef as ArrayType;
if (xArray != null)
{
throw new NotSupportedException("Reader.ResolveType doesnt support ArrayTypes");
}
var xPointer = aRef as PointerType;
if (xPointer != null)
{
throw new NotSupportedException("Reader.ResolveType doesnt support PointerTypes");
}
//var xReference = aRef as ReferenceType;
//if (xReference != null)
//{
// throw new NotSupportedException("Reader.ResolveType doesnt support ReferenceTypes");
//}
#endif
return aRef.Resolve();
}
示例8: Get
public static string Get(TypeReference type, Dictionary<FieldReference, string> fieldNames) {
if (!type.IsValueType || type.IsNullable()) {
return "null";
}
if (type.IsPrimitive) {
var mdt = type.MetadataType;
switch (mdt) {
case MetadataType.Boolean: return "false";
case MetadataType.IntPtr:
case MetadataType.UIntPtr:
case MetadataType.Int16:
case MetadataType.Int32:
case MetadataType.UInt16:
case MetadataType.UInt32:
case MetadataType.Byte:
case MetadataType.SByte:
case MetadataType.Single:
case MetadataType.Double:
case MetadataType.Char: return "0";
case MetadataType.Int64:
case MetadataType.UInt64: return "[0, 0]";
default: throw new NotImplementedException("Cannot handle: " + mdt);
}
}
if (type.Resolve().IsEnum) {
return "0";
}
var fields = type.EnumResolvedFields().Where(x => !x.Resolve().IsStatic).ToArray();
var defaultValue = "{" + string.Join(",",
fields.Where(x => fieldNames.ContainsKey(x))
.Select(x => fieldNames[x] + ":" + Get(x.FieldType, fieldNames))) + "}";
return defaultValue;
}
示例9: Visit
public override TypeReference Visit(TypeReference type)
{
var typeDefinition = type.Resolve();
if (typeDefinition.IsValueType && !type.IsValueType)
type.IsValueType = typeDefinition.IsValueType;
return base.Visit(type);
}
示例10: IsPublic
internal static bool IsPublic (TypeReference typeref)
{
if (typeref == null)
throw new ArgumentNullException ("typeref");
TypeDefinition td = typeref.Resolve ();
return td.IsPublic;
}
示例11: AddBaseTypes
internal static void AddBaseTypes(SharpTreeNodeCollection children, TypeReference type)
{
var def = type.Resolve();
if (def.BaseType != null)
children.Add(new BaseTypesEntryNode(ResolveWithTypes(def.BaseType, type), false));
foreach (TypeReference i in def.Interfaces)
children.Add(new BaseTypesEntryNode(ResolveWithTypes(i, type), true));
}
示例12: IsEnumOrStruct
/// <summary>
/// Is the given type an enum or struct?
/// </summary>
private static bool IsEnumOrStruct(TypeReference type)
{
if (type.IsPrimitive)
return false;
if (!type.IsDefinitionOrReference())
return false;
var typeDef = type.Resolve();
return (typeDef != null) && (typeDef.IsEnum || typeDef.IsValueType);
}
示例13: BaseTypesEntryNode
public BaseTypesEntryNode(TypeReference tr, bool isInterface)
{
if (tr == null)
throw new ArgumentNullException("tr");
this.tr = tr;
this.def = tr.Resolve();
this.isInterface = isInterface;
this.LazyLoading = true;
}
示例14: MemberResolver
public MemberResolver(TypeReference target, ModuleDefinition targetModule = null)
{
if (target == null) throw new ArgumentNullException("target");
Target = target;
Module = targetModule ?? Target.Module;
Source = Target.Resolve();
TargetWithArguments = Target as GenericInstanceType;
_map = new GenericParametersMap(Source, TargetWithArguments);
}
示例15: InterceptMethod
private void InterceptMethod(ILProcessor processor, TypeReference typeReference, Instruction instruction, string name)
{
var typeDefinition = typeReference.Resolve();
var attributeConstructor = typeDefinition.Methods.First(x => x.Name == ".ctor");
var attributeMethod = typeDefinition.Methods.First(x => x.Name == name);
processor.InsertBefore(instruction, processor.Create(OpCodes.Newobj, attributeConstructor));
processor.InsertBefore(instruction, processor.Create(OpCodes.Call, _getCurrentMethod));
processor.InsertBefore(instruction, processor.Create(OpCodes.Call, attributeMethod));
}