本文整理汇总了C#中Microsoft.Cci.AsDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Cci.AsDefinition方法的具体用法?C# Microsoft.Cci.AsDefinition怎么用?C# Microsoft.Cci.AsDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Cci
的用法示例。
在下文中一共展示了Microsoft.Cci.AsDefinition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveConstructor
private MethodBase ResolveConstructor(Cci.IMethodReference methodRef)
{
Debug.Assert(!methodRef.IsGeneric);
// A method ref to a varargs method is always resolved as an entry in the method
// ref table, never in the method def table, *even if the method is locally declared.*
// (We could in theory resolve it as a method def if there were no extra arguments,
// but in practice we do not.)
var methodDef = (Cci.IMethodDefinition)methodRef.AsDefinition(_context);
if (methodDef != null && IsLocal(methodRef.GetContainingType(_context)) && !methodRef.AcceptsExtraArguments)
{
return _constructorBuilders[methodDef];
}
MethodBase result;
if (_methodRefs.TryGetValue(methodRef, out result))
{
return result;
}
Debug.Assert(methodRef.AsGenericMethodInstanceReference == null);
Cci.ISpecializedMethodReference specializedRef = methodRef.AsSpecializedMethodReference;
if (specializedRef != null &&
IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
{
// get declaring type (TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built):
Type declaringType = ResolveType(methodRef.GetContainingType(_context));
ConstructorBuilder ctorBuilder = _constructorBuilders[(Cci.IMethodDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
result = TypeBuilder.GetConstructor(declaringType, ctorBuilder);
}
else
{
result = MakeMethodRef(methodRef, specializedRef, isConstructor: true);
}
_methodRefs.Add(methodRef, result);
return result;
}
示例2: ResolveMethod
private MethodInfo ResolveMethod(Cci.IMethodReference methodRef)
{
var methodDef = (Cci.IMethodDefinition)methodRef.AsDefinition(_context);
// A method ref to a varargs method is always resolved as an entry in the method
// ref table, never in the method def table, *even if the method is locally declared.*
// (We could in theory resolve it as a method def if there were no extra arguments,
// but in practice we do not.)
if (methodDef != null && IsLocal(methodRef.GetContainingType(_context)) && !methodRef.AcceptsExtraArguments)
{
return _methodBuilders[methodDef];
}
MethodBase methodBase;
if (_methodRefs.TryGetValue(methodRef, out methodBase))
{
return (MethodInfo)methodBase;
}
MethodInfo result;
Cci.ISpecializedMethodReference specializedRef = methodRef.AsSpecializedMethodReference;
Cci.IGenericMethodInstanceReference genericRef = methodRef.AsGenericMethodInstanceReference;
if (specializedRef != null &&
IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
{
// get declaring type (TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built):
Type type = ResolveType(specializedRef.GetContainingType(_context));
MethodBuilder methodBuilder = _methodBuilders[(Cci.IMethodDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
MethodInfo methodOnTypeBuilder = TypeBuilder.GetMethod(type, methodBuilder);
if (genericRef != null)
{
Type[] typeArgs = genericRef.GetGenericArguments(_context).Select(arg => ResolveType(arg)).ToArray();
result = methodOnTypeBuilder.MakeGenericMethod(typeArgs);
}
else
{
result = methodOnTypeBuilder;
}
}
else if (genericRef != null)
{
MethodInfo genericMethod = ResolveMethod(genericRef.GetGenericMethod(_context));
Type[] typeArgs = genericRef.GetGenericArguments(_context).Select((arg) => ResolveType(arg)).ToArray();
if (genericMethod is MethodRef)
{
result = new MethodSpec(genericMethod, typeArgs);
}
else
{
result = genericMethod.MakeGenericMethod(typeArgs);
}
}
else
{
result = MakeMethodRef(methodRef, specializedRef, isConstructor: false);
}
_methodRefs.Add(methodRef, result);
return result;
}