本文整理汇总了C#中Mono.Cecil.ImportContext.PushGenericContext方法的典型用法代码示例。如果您正苦于以下问题:C# ImportContext.PushGenericContext方法的具体用法?C# ImportContext.PushGenericContext怎么用?C# ImportContext.PushGenericContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.ImportContext
的用法示例。
在下文中一共展示了ImportContext.PushGenericContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportTypeReference
public override TypeReference ImportTypeReference(TypeReference t, ImportContext context)
{
try
{
if (t.Module == Module)
return t;
TypeReference type;
if (Handler.TryGetReplacement(t, out type))
{
// generic?
GenericInstanceType genericInstanceType = t as GenericInstanceType;
if (genericInstanceType != null) // yes generic!
{
// add generic parameters and import generic arguments
GenericInstanceType replacementGenericInstanceType = new GenericInstanceType(type);
foreach (GenericParameter genericParameter in genericInstanceType.GenericParameters)
{
replacementGenericInstanceType.GenericParameters.Add(genericParameter);
}
foreach (TypeReference genericArgument in genericInstanceType.GenericArguments)
{
replacementGenericInstanceType.GenericArguments.Add(ImportTypeReference(genericArgument, context));
}
t = replacementGenericInstanceType;
}
else // not generic.
{
t = type;
}
}
if (t is TypeSpecification)
return GetTypeSpec((TypeSpecification)t, context);
if (t is GenericParameter)
{
// TODO: HACK!!!
return t;
//return GetGenericParameter((GenericParameter)t, context);
}
type = Module.TypeReferences[t.FullName];
if (type != null)
return type;
AssemblyNameReference asm;
if (t.Scope is AssemblyNameReference)
{
asm = ImportAssembly((AssemblyNameReference)t.Scope);
}
else if (t.Scope is ModuleDefinition)
{
asm = ImportAssembly(((ModuleDefinition)t.Scope).Assembly.Name);
}
else if (t.Namespace == "System")
{
// TODO: Use lookup table rather than checking for "System" namespace
asm = Handler._mscorlib;
}
else
{
throw new NotImplementedException();
}
type = new TypeReference(t.Name, t.Namespace, asm, t.IsValueType);
if (t.DeclaringType != null)
{
type.DeclaringType = ImportTypeReference(t.DeclaringType, context);
}
context.PushGenericContext(type);
foreach (GenericParameter gp in t.GenericParameters)
type.GenericParameters.Add(GenericParameter.Clone(gp, context));
context.PopGenericContext();
Module.TypeReferences.Add(type);
return type;
}
catch (Exception e)
{
throw new CompilerException("Unable to import type reference " + t + ". Import context is " + context + ".", e);
}
}
示例2: ImportMethodReference
public override MethodReference ImportMethodReference(MethodReference mr, ImportContext context)
{
if (mr.DeclaringType.Module == Module)
return mr;
if (mr is MethodSpecification)
return GetMethodSpec(mr, context);
MethodReference meth = (MethodReference)GetMemberReference(mr);
if (meth != null)
return meth;
meth = new MethodReference(
mr.Name,
null,
null,
mr.HasThis,
mr.ExplicitThis,
mr.CallingConvention);
meth.DeclaringType = ImportTypeReference(mr.DeclaringType, context);
//TypeReference contextType = meth.DeclaringType.GetOriginalType();
TypeReference contextType = meth.DeclaringType;
context.PushGenericContext(contextType, meth);
foreach (GenericParameter gp in mr.GenericParameters)
meth.GenericParameters.Add(GenericParameter.Clone(gp, context));
meth.ReturnType.ReturnType = ImportTypeReference(mr.ReturnType.ReturnType, context);
foreach (ParameterDefinition param in mr.Parameters)
meth.Parameters.Add(new ParameterDefinition(
ImportTypeReference(param.ParameterType, context)));
context.PopGenericContext();
Module.MemberReferences.Add(meth);
return meth;
}