本文整理汇总了C#中Mono.Cecil.ImportContext类的典型用法代码示例。如果您正苦于以下问题:C# ImportContext类的具体用法?C# ImportContext怎么用?C# ImportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportContext类属于Mono.Cecil命名空间,在下文中一共展示了ImportContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ImportFieldReference
public virtual FieldReference ImportFieldReference(FieldReference fr, ImportContext context)
{
if (fr.DeclaringType.Module == m_module)
return fr;
FieldReference field = (FieldReference) GetMemberReference (fr);
if (field != null)
return field;
field = new FieldReference (
fr.Name,
ImportTypeReference (fr.DeclaringType, context),
ImportTypeReference (fr.FieldType, context));
m_module.MemberReferences.Add (field);
return field;
}
开发者ID:sidecut,项目名称:xaeios,代码行数:17,代码来源:DefaultImporter.cs
示例2: GetTypeSpec
TypeSpecification GetTypeSpec (TypeSpecification original, ImportContext context)
{
TypeSpecification typeSpec;
TypeReference elementType = ImportTypeReference (original.ElementType, context);
if (original is PointerType) {
typeSpec = new PointerType (elementType);
} else if (original is ArrayType) { // deal with complex arrays
typeSpec = new ArrayType (elementType);
} else if (original is ReferenceType) {
typeSpec = new ReferenceType (elementType);
} else if (original is GenericInstanceType) {
GenericInstanceType git = original as GenericInstanceType;
GenericInstanceType genElemType = new GenericInstanceType (elementType);
context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);
foreach (TypeReference arg in git.GenericArguments)
genElemType.GenericArguments.Add (ImportTypeReference (arg, context));
typeSpec = genElemType;
} else if (original is ModifierOptional) {
TypeReference mt = (original as ModifierOptional).ModifierType;
typeSpec = new ModifierOptional (elementType, ImportTypeReference (mt, context));
} else if (original is ModifierRequired) {
TypeReference mt = (original as ModifierRequired).ModifierType;
typeSpec = new ModifierRequired (elementType, ImportTypeReference (mt, context));
} else if (original is SentinelType) {
typeSpec = new SentinelType (elementType);
} else if (original is FunctionPointerType) {
FunctionPointerType ori = original as FunctionPointerType;
FunctionPointerType fnptr = new FunctionPointerType (
ori.HasThis,
ori.ExplicitThis,
ori.CallingConvention,
new MethodReturnType (ImportTypeReference (ori.ReturnType.ReturnType, context)));
foreach (ParameterDefinition parameter in ori.Parameters)
fnptr.Parameters.Add (new ParameterDefinition (ImportTypeReference (parameter.ParameterType, context)));
typeSpec = fnptr;
} else
throw new ReflectionException ("Unknown element type: {0}", original.GetType ().Name);
return typeSpec;
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:46,代码来源:DefaultImporter.cs
示例3: GetGenericParameter
static GenericParameter GetGenericParameter(Type t, ImportContext context)
{
int pos = (int) t.GetType ().GetProperty ("GenericParameterPosition").GetValue (t, null);
if (GenericParameterOfMethod (t))
return context.GenericContext.Method.GenericParameters [pos];
else
return context.GenericContext.Type.GenericParameters [pos];
}
开发者ID:NALSS,项目名称:Telegraph,代码行数:8,代码来源:ReflectionHelper.cs
示例4: ImportMethodDefinition
public MethodDefinition ImportMethodDefinition(MethodDefinition meth, ImportContext context)
{
return MethodDefinition.Clone (meth, context);
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:4,代码来源:ReflectionHelper.cs
示例5: Clone
internal static EventDefinition Clone(EventDefinition evt, ImportContext context)
{
EventDefinition ne = new EventDefinition (
evt.Name,
context.Import (evt.EventType),
evt.Attributes);
if (context != null && context.GenericContext.Type is TypeDefinition) {
TypeDefinition type = context.GenericContext.Type as TypeDefinition;
if (evt.AddMethod != null)
ne.AddMethod = type.Methods.GetMethod (evt.AddMethod.Name) [0];
if (evt.InvokeMethod != null)
ne.InvokeMethod = type.Methods.GetMethod (evt.InvokeMethod.Name) [0];
if (evt.RemoveMethod != null)
ne.RemoveMethod = type.Methods.GetMethod (evt.RemoveMethod.Name) [0];
}
foreach (CustomAttribute ca in evt.CustomAttributes)
ne.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
return ne;
}
开发者ID:leftouterjoin,项目名称:loj-prj1,代码行数:22,代码来源:EventDefinition.cs
示例6: ImportFieldInfo
public FieldReference ImportFieldInfo (SR.FieldInfo fi, ImportContext context)
{
string sig = GetFieldSignature (fi);
FieldReference f = (FieldReference) GetMemberReference (sig);
if (f != null)
return f;
f = new FieldReference (
fi.Name,
ImportSystemType (fi.DeclaringType, context),
ImportSystemType (fi.FieldType, context));
m_module.MemberReferences.Add (f);
return f;
}
开发者ID:nobled,项目名称:mono,代码行数:15,代码来源:ReflectionHelper.cs
示例7: Clone
internal static GenericParameter Clone(GenericParameter gp, ImportContext context)
{
GenericParameter ngp;
if (gp.Owner is TypeReference)
ngp = new GenericParameter (gp.m_name, context.GenericContext.Type);
else if (gp.Owner is MethodReference)
ngp = new GenericParameter (gp.m_name, context.GenericContext.Method);
else
throw new NotSupportedException ();
ngp.Position = gp.Owner.GenericParameters.IndexOf (gp);
ngp.Attributes = gp.Attributes;
foreach (TypeReference constraint in gp.Constraints)
ngp.Constraints.Add (context.Import (constraint));
foreach (CustomAttribute ca in gp.CustomAttributes)
ngp.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
return ngp;
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:20,代码来源:GenericParameter.cs
示例8: GetTypeSpec
TypeReference GetTypeSpec (Type t, ImportContext context)
{
Stack s = new Stack ();
while (t.HasElementType || IsGenericTypeSpec (t)) {
s.Push (t);
if (t.HasElementType)
t = t.GetElementType ();
else if (IsGenericTypeSpec (t)) {
t = (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null);
break;
}
}
TypeReference elementType = ImportSystemType (t, context);
while (s.Count > 0) {
t = (Type) s.Pop ();
if (t.IsPointer)
elementType = new PointerType (elementType);
else if (t.IsArray)
elementType = new ArrayType (elementType, t.GetArrayRank ());
else if (t.IsByRef)
elementType = new ReferenceType (elementType);
else if (IsGenericTypeSpec (t))
elementType = GetGenericType (t, elementType, context);
else
throw new ReflectionException ("Unknown element type");
}
return elementType;
}
开发者ID:nobled,项目名称:mono,代码行数:30,代码来源:ReflectionHelper.cs
示例9: ImportTypeDefinition
public TypeDefinition ImportTypeDefinition(TypeDefinition type, ImportContext context)
{
return TypeDefinition.Clone (type, context);
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:4,代码来源:ReflectionHelper.cs
示例10: GetGenericParameter
protected static GenericParameter GetGenericParameter(GenericParameter gp, ImportContext context)
{
// walk generic context stack, looking for the generic parameter
GenericParameter p = null;
context.SearchGenericContextStack(delegate(GenericContext genericContext)
{
if (gp.Owner is TypeReference && genericContext.Type.GenericParameters.Count > gp.Position)
{
p = genericContext.Type.GenericParameters[gp.Position];
return true;
}
else if (gp.Owner is MethodReference && genericContext.Method.GenericParameters.Count > gp.Position)
{
p = genericContext.Method.GenericParameters[gp.Position];
return true;
}
else
{
return false;
}
});
if (p == null)
{
throw new NotSupportedException("Unable to find generic parameter " + gp + " in context " + context);
}
return p;
}
开发者ID:sidecut,项目名称:xaeios,代码行数:29,代码来源:DefaultImporter.cs
示例11: GetMethodSpec
protected MethodReference GetMethodSpec(MethodReference meth, ImportContext context)
{
if (!(meth is GenericInstanceMethod))
return null;
GenericInstanceMethod gim = meth as GenericInstanceMethod;
GenericInstanceMethod ngim = new GenericInstanceMethod (
ImportMethodReference (gim.ElementMethod, context));
context.GenericContext.CheckProvider (ngim.GetOriginalMethod (), gim.GenericArguments.Count);
foreach (TypeReference arg in gim.GenericArguments)
ngim.GenericArguments.Add (ImportTypeReference (arg, context));
return ngim;
}
开发者ID:sidecut,项目名称:xaeios,代码行数:15,代码来源:DefaultImporter.cs
示例12: Clone
internal static MethodBody Clone (MethodBody body, MethodDefinition parent, ImportContext context)
{
MethodBody nb = new MethodBody (parent);
nb.MaxStack = body.MaxStack;
nb.InitLocals = body.InitLocals;
nb.CodeSize = body.CodeSize;
CilWorker worker = nb.CilWorker;
if (body.HasVariables) {
foreach (VariableDefinition var in body.Variables)
nb.Variables.Add (new VariableDefinition (
var.Name, var.Index, parent,
context.Import (var.VariableType)));
}
foreach (Instruction instr in body.Instructions) {
Instruction ni = new Instruction (instr.OpCode);
switch (instr.OpCode.OperandType) {
case OperandType.InlineParam :
case OperandType.ShortInlineParam :
if (instr.Operand == body.Method.This)
ni.Operand = nb.Method.This;
else {
int param = body.Method.Parameters.IndexOf ((ParameterDefinition) instr.Operand);
ni.Operand = parent.Parameters [param];
}
break;
case OperandType.InlineVar :
case OperandType.ShortInlineVar :
int var = body.Variables.IndexOf ((VariableDefinition) instr.Operand);
ni.Operand = nb.Variables [var];
break;
case OperandType.InlineField :
ni.Operand = context.Import ((FieldReference) instr.Operand);
break;
case OperandType.InlineMethod :
ni.Operand = context.Import ((MethodReference) instr.Operand);
break;
case OperandType.InlineType :
ni.Operand = context.Import ((TypeReference) instr.Operand);
break;
case OperandType.InlineTok :
if (instr.Operand is TypeReference)
ni.Operand = context.Import ((TypeReference) instr.Operand);
else if (instr.Operand is FieldReference)
ni.Operand = context.Import ((FieldReference) instr.Operand);
else if (instr.Operand is MethodReference)
ni.Operand = context.Import ((MethodReference) instr.Operand);
break;
case OperandType.ShortInlineBrTarget :
case OperandType.InlineBrTarget :
case OperandType.InlineSwitch :
break;
default :
ni.Operand = instr.Operand;
break;
}
worker.Append (ni);
}
for (int i = 0; i < body.Instructions.Count; i++) {
Instruction instr = nb.Instructions [i];
Instruction oldi = body.Instructions [i];
if (instr.OpCode.OperandType == OperandType.InlineSwitch) {
Instruction [] olds = (Instruction []) oldi.Operand;
Instruction [] targets = new Instruction [olds.Length];
for (int j = 0; j < targets.Length; j++)
targets [j] = GetInstruction (body, nb, olds [j]);
instr.Operand = targets;
} else if (instr.OpCode.OperandType == OperandType.ShortInlineBrTarget || instr.OpCode.OperandType == OperandType.InlineBrTarget)
instr.Operand = GetInstruction (body, nb, (Instruction) oldi.Operand);
}
if (!body.HasExceptionHandlers)
return nb;
foreach (ExceptionHandler eh in body.ExceptionHandlers) {
ExceptionHandler neh = new ExceptionHandler (eh.Type);
neh.TryStart = GetInstruction (body, nb, eh.TryStart);
neh.TryEnd = GetInstruction (body, nb, eh.TryEnd);
neh.HandlerStart = GetInstruction (body, nb, eh.HandlerStart);
neh.HandlerEnd = GetInstruction (body, nb, eh.HandlerEnd);
switch (eh.Type) {
case ExceptionHandlerType.Catch :
neh.CatchType = context.Import (eh.CatchType);
break;
case ExceptionHandlerType.Filter :
neh.FilterStart = GetInstruction (body, nb, eh.FilterStart);
neh.FilterEnd = GetInstruction (body, nb, eh.FilterEnd);
break;
}
nb.ExceptionHandlers.Add (neh);
//.........这里部分代码省略.........
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:101,代码来源:MethodBody.cs
示例13: ImportTypeReference
public virtual TypeReference ImportTypeReference(TypeReference t, ImportContext context)
{
if (t.Module == m_module)
return t;
if (t is TypeSpecification)
return GetTypeSpec (t as TypeSpecification, context);
if (t is GenericParameter)
return GetGenericParameter (t as GenericParameter, context);
TypeReference type = m_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
throw new NotImplementedException ();
if (t.DeclaringType != null) {
type = new TypeReference (t.Name, string.Empty, asm, t.IsValueType);
type.DeclaringType = ImportTypeReference (t.DeclaringType, context);
} else
type = new TypeReference (t.Name, t.Namespace, asm, t.IsValueType);
context.GenericContext.Type = type;
foreach (GenericParameter gp in t.GenericParameters)
type.GenericParameters.Add (GenericParameter.Clone (gp, context));
m_module.TypeReferences.Add (type);
return type;
}
开发者ID:sidecut,项目名称:xaeios,代码行数:37,代码来源:DefaultImporter.cs
示例14: GetTypeSpec
TypeReference GetTypeSpec(TypeReference t, ImportContext context)
{
Stack s = new Stack ();
while (t is TypeSpecification) {
s.Push (t);
t = (t as TypeSpecification).ElementType;
}
TypeReference elementType = ImportTypeReference (t, context);
while (s.Count > 0) {
t = s.Pop () as TypeReference;
if (t is PointerType)
elementType = new PointerType (elementType);
else if (t is ArrayType) // deal with complex arrays
elementType = new ArrayType (elementType);
else if (t is ReferenceType)
elementType = new ReferenceType (elementType);
else if (t is GenericInstanceType) {
GenericInstanceType git = t as GenericInstanceType;
GenericInstanceType genElemType = new GenericInstanceType (elementType);
foreach (TypeReference arg in git.GenericArguments)
genElemType.GenericArguments.Add (ImportTypeReference (arg, context));
elementType = genElemType;
} else
throw new ReflectionException ("Unknown element type: {0}", t.GetType ().Name);
}
return elementType;
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:30,代码来源:ReflectionHelper.cs
示例15: GetMethodSpec
MethodReference GetMethodSpec(MethodReference meth, ImportContext context)
{
if (!(meth is GenericInstanceMethod))
return null;
GenericInstanceMethod gim = meth as GenericInstanceMethod;
GenericInstanceMethod ngim = new GenericInstanceMethod (
ImportMethodReference (gim.ElementMethod, context));
foreach (TypeReference arg in gim.GenericArguments)
ngim.GenericArguments.Add (ImportTypeReference (arg, context));
return ngim;
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:14,代码来源:ReflectionHelper.cs
示例16: GetGenericParameter
static GenericParameter GetGenericParameter(GenericParameter gp, ImportContext context)
{
GenericParameter p;
if (gp.Owner is TypeReference)
p = context.GenericContext.Type.GenericParameters [gp.Position];
else if (gp.Owner is MethodReference)
p = context.GenericContext.Method.GenericParameters [gp.Position];
else
throw new NotSupportedException ();
return p;
}
开发者ID:KenMacD,项目名称:deconfuser,代码行数:12,代码来源:ReflectionHelper.cs
示例17: GetGenericType
GenericInstanceType GetGenericType (Type t, TypeReference element, ImportContext context)
{
GenericInstanceType git = new GenericInstanceType (element);
foreach (Type genArg in GetGenericArguments (t))
git.GenericArguments.Add (ImportSystemType (genArg, context));
return git;
}
开发者ID:nobled,项目名称:mono,代码行数:8,代码来源:ReflectionHelper.cs
示例18: ImportGenericInstanceMethod
MethodReference ImportGenericInstanceMethod (SR.MethodInfo mi, ImportContext context)
{
SR.MethodInfo gmd = (SR.MethodInfo) mi.GetType ().GetMethod ("GetGenericMethodDefinition").Invoke (mi, null);
GenericInstanceMethod gim = new GenericInstanceMethod (
ImportMethodBase (gmd, gmd.ReturnType, context));
foreach (Type genArg in GetGenericArguments (mi))
gim.GenericArguments.Add (ImportSystemType (genArg, context));
return gim;
}
开发者ID:nobled,项目名称:mono,代码行数:11,代码来源:ReflectionHelper.cs
示例19: GetGenericParameter
static GenericParameter GetGenericParameter (Type t, ImportContext context)
{
int pos = (int) t.GetType ().GetProperty ("GenericParameterPosition").GetValue (t, null);
IGenericParameterProvider provider;
if (GenericParameterOfMethod (t))
provider = context.GenericContext.Method;
else
provider = context.GenericContext.Type;
if (provider == null)
throw new InvalidOperationException ("Invalid context");
return provider.GenericParameters [pos];
}
开发者ID:nobled,项目名称:mono,代码行数:14,代码来源:ReflectionHelper.cs
示例20: ImportConstructorInfo
public MethodReference ImportConstructorInfo (SR.ConstructorInfo ci, ImportContext context)
{
return ImportMethodBase (ci, typeof (void), context);
}
开发者ID:nobled,项目名称:mono,代码行数:4,代码来源:ReflectionHelper.cs
注:本文中的Mono.Cecil.ImportContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论