本文整理汇总了C#中dnlib.DotNet.TypeRef类的典型用法代码示例。如果您正苦于以下问题:C# TypeRef类的具体用法?C# TypeRef怎么用?C# TypeRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeRef类属于dnlib.DotNet命名空间,在下文中一共展示了TypeRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetColor
/// <summary>
/// Gets a type color
/// </summary>
/// <param name="type">Type</param>
/// <returns></returns>
public virtual object GetColor(TypeRef type) {
if (type == null)
return BoxedTextColor.Text;
var td = type.Resolve();
if (td != null)
return GetColor(td);
return BoxedTextColor.Type;
}
示例2: ResolveExportedType
TypeDef ResolveExportedType(IList<ModuleDef> modules, TypeRef typeRef) {
var exportedType = FindExportedType(modules, typeRef);
if (exportedType == null)
return null;
var asmResolver = modules[0].Context.AssemblyResolver;
var etAsm = asmResolver.Resolve(exportedType.DefinitionAssembly, typeRef.Module);
if (etAsm == null)
return null;
return etAsm.Find(typeRef);
}
示例3: CheckType
/// <summary>
/// Checks whether the type matches an expected type
/// </summary>
/// <param name="module">Module</param>
/// <param name="name">Type name</param>
/// <param name="expectedType">Expected type</param>
/// <returns></returns>
public static bool CheckType(ModuleDef module, string name, TypeRef expectedType) {
if (module == null)
module = new ModuleDefUser();
var tr = TypeNameParser.ParseReflection(module, name, null);
if (tr == null)
return false;
var flags = AssemblyNameComparerFlags.All & ~AssemblyNameComparerFlags.Version;
if (!new AssemblyNameComparer(flags).Equals(tr.DefinitionAssembly, expectedType.DefinitionAssembly))
return false;
if (!new SigComparer().Equals(tr, expectedType))
return false;
return true;
}
示例4: ResolveExportedType
TypeDef ResolveExportedType(IList<ModuleDef> modules, TypeRef typeRef, ModuleDef sourceModule) {
for (int i = 0; i < 30; i++) {
var exportedType = FindExportedType(modules, typeRef);
if (exportedType == null)
return null;
var asmResolver = modules[0].Context.AssemblyResolver;
var etAsm = asmResolver.Resolve(exportedType.DefinitionAssembly, sourceModule ?? typeRef.Module);
if (etAsm == null)
return null;
var td = etAsm.Find(typeRef);
if (td != null)
return td;
modules = etAsm.Modules;
}
return null;
}
示例5: Resolve
/// <inheritdoc/>
public TypeDef Resolve(TypeRef typeRef, ModuleDef sourceModule) {
if (typeRef == null)
return null;
if (ProjectWinMDRefs)
typeRef = WinMDHelpers.ToCLR(typeRef.Module ?? sourceModule, typeRef) ?? typeRef;
var nonNestedTypeRef = TypeRef.GetNonNestedTypeRef(typeRef);
if (nonNestedTypeRef == null)
return null;
var nonNestedResolutionScope = nonNestedTypeRef.ResolutionScope;
var nonNestedModule = nonNestedTypeRef.Module;
var asmRef = nonNestedResolutionScope as AssemblyRef;
if (asmRef != null) {
var asm = assemblyResolver.Resolve(asmRef, sourceModule ?? nonNestedModule);
return asm == null ? null : asm.Find(typeRef) ?? ResolveExportedType(asm.Modules, typeRef, sourceModule);
}
var moduleDef = nonNestedResolutionScope as ModuleDef;
if (moduleDef != null)
return moduleDef.Find(typeRef) ??
ResolveExportedType(new ModuleDef[] { moduleDef }, typeRef, sourceModule);
var moduleRef = nonNestedResolutionScope as ModuleRef;
if (moduleRef != null) {
if (nonNestedModule == null)
return null;
if (new SigComparer().Equals(moduleRef, nonNestedModule))
return nonNestedModule.Find(typeRef) ??
ResolveExportedType(new ModuleDef[] { nonNestedModule }, typeRef, sourceModule);
var nonNestedAssembly = nonNestedModule.Assembly;
if (nonNestedAssembly == null)
return null;
var resolvedModule = nonNestedAssembly.FindModule(moduleRef.Name);
return resolvedModule == null ? null : resolvedModule.Find(typeRef) ??
ResolveExportedType(new ModuleDef[] { resolvedModule }, typeRef, sourceModule);
}
return null;
}
示例6: FindAssemblyRef
/// <inheritdoc/>
public AssemblyRef FindAssemblyRef(TypeRef nonNestedTypeRef) {
var modAsm = module.Assembly;
if (modAsm != null) {
var type = modAsm.Find(nonNestedTypeRef);
if (type != null)
return module.UpdateRowId(new AssemblyRefUser(modAsm));
}
else if (module.Find(nonNestedTypeRef) != null)
return AssemblyRef.CurrentAssembly;
var corLibAsm = module.Context.AssemblyResolver.Resolve(module.CorLibTypes.AssemblyRef, module);
if (corLibAsm != null) {
var type = corLibAsm.Find(nonNestedTypeRef);
if (type != null)
return module.CorLibTypes.AssemblyRef;
}
if (modAsm != null)
return module.UpdateRowId(new AssemblyRefUser(modAsm));
return AssemblyRef.CurrentAssembly;
}
示例7: CreateFullName
void CreateFullName(TypeRef typeRef) {
if (typeRef == null) {
sb.Append(NULLVALUE);
return;
}
if (!recursionCounter.Increment()) {
sb.Append(RECURSION_ERROR_RESULT_STRING);
return;
}
var declaringTypeRef = typeRef.ResolutionScope as TypeRef;
if (declaringTypeRef != null) {
CreateFullName(declaringTypeRef);
AddNestedTypeSeparator();
}
if (AddNamespace(typeRef.Namespace))
sb.Append('.');
AddName(typeRef.Name);
recursionCounter.Decrement();
}
示例8: OwnerModule
/// <summary>
/// Returns the owner module. The type was created from metadata in this module.
/// </summary>
/// <param name="typeRef">The <c>TypeRef</c></param>
/// <returns>A <see cref="ModuleDef"/> or <c>null</c> if none found</returns>
public static ModuleDef OwnerModule(TypeRef typeRef) {
return new FullNameCreator().GetOwnerModule(typeRef);
}
示例9: DefinitionAssembly
/// <summary>
/// Returns the assembly where this type is defined
/// </summary>
/// <param name="typeRef">The <c>TypeRef</c></param>
/// <returns>A <see cref="IAssembly"/> or <c>null</c> if none found</returns>
public static IAssembly DefinitionAssembly(TypeRef typeRef) {
return new FullNameCreator().GetDefinitionAssembly(typeRef);
}
示例10: AssemblyQualifiedName
/// <summary>
/// Returns the assembly qualified full name of a <see cref="TypeRef"/>
/// </summary>
/// <param name="typeRef">The <c>TypeRef</c></param>
/// <returns>The assembly qualified full name</returns>
public static string AssemblyQualifiedName(TypeRef typeRef) {
return AssemblyQualifiedName(typeRef, null);
}
示例11: FullName
/// <summary>
/// Returns the full name of a <see cref="TypeRef"/>
/// </summary>
/// <param name="typeRef">The <c>TypeRef</c></param>
/// <param name="isReflection">Set if output should be compatible with reflection</param>
/// <returns>The full name</returns>
public static string FullName(TypeRef typeRef, bool isReflection) {
return FullName(typeRef, isReflection, null);
}
示例12: GetOwnerModule
ModuleDef GetOwnerModule(TypeRef typeRef) {
if (typeRef == null)
return null;
return typeRef.Module;
}
示例13: FindSlow
TypeDef FindSlow(TypeRef typeRef) {
InitializeTypeEnumerator();
var comparer = new SigComparer { Options = TypeComparerOptions };
while (true) {
var type = GetNextTypeDef();
if (type == null || comparer.Equals(type, typeRef))
return type;
}
}
示例14: FindCache
TypeDef FindCache(TypeRef typeRef) {
TypeDef cachedType;
if (typeRefCache.TryGetValue(typeRef, out cachedType))
return cachedType;
// Build the cache lazily
var comparer = new SigComparer { Options = TypeComparerOptions };
while (true) {
cachedType = GetNextTypeDefCache();
if (cachedType == null || comparer.Equals(cachedType, typeRef))
return cachedType;
}
}
示例15: Find
/// <inheritdoc/>
public TypeDef Find(TypeRef typeRef) {
if (typeRef == null)
return null;
return isCacheEnabled ? FindCache(typeRef) : FindSlow(typeRef);
}