本文整理汇总了C#中Mono.Cecil.TypeReference.MakeGenericInstanceType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.MakeGenericInstanceType方法的具体用法?C# TypeReference.MakeGenericInstanceType怎么用?C# TypeReference.MakeGenericInstanceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeReference
的用法示例。
在下文中一共展示了TypeReference.MakeGenericInstanceType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportRuntimeModuleDictionary
private void ImportRuntimeModuleDictionary(ModuleDefinition module, TypeReference tDict)
{
var tFuncOfModule = FuncOfT.MakeGenericInstanceType(RuntimeModule);
var tModuleDict = tDict.MakeGenericInstanceType(Type, tFuncOfModule);
DictionaryOfTypeToModuleFn = module.Import(tModuleDict);
DictionaryOfTypeToModuleFn_New =
module.Import(tModuleDict.Resolve()
.GetDefaultConstructor())
.MakeHostInstanceGeneric(Type, tFuncOfModule);
DictionaryOfTypeToModuleFn_Add =
module.Import(tModuleDict.Resolve().GetMethod("Add")).MakeHostInstanceGeneric(Type, tFuncOfModule);
DictionaryOfTypeToModuleFn_TryGetValue =
module.Import(tModuleDict.Resolve().GetMethod("TryGetValue"))
.MakeHostInstanceGeneric(Type, tFuncOfModule);
}
示例2: ImportProviderBindingDictionary
private void ImportProviderBindingDictionary(ModuleDefinition module, TypeReference tDict)
{
var tFuncOfProviderBinding = FuncOfT5.MakeGenericInstanceType(String, Object, Boolean, String, Binding);
var tProviderDict = tDict.MakeGenericInstanceType(String, tFuncOfProviderBinding);
DictionaryOfStringToProviderBindingFn = tProviderDict;
DictionaryOfStringToProviderBindingFn_New =
module.Import(tProviderDict.Resolve()
.GetConstructors()
.First(
c =>
c.Parameters.Count == 1 &&
c.Parameters[0].ParameterType.Name.StartsWith("IEqualityComparer")))
.MakeHostInstanceGeneric(String, tFuncOfProviderBinding);
DictionaryOfStringToProviderBindingFn_Add =
module.Import(tProviderDict.Resolve().GetMethod("Add"))
.MakeHostInstanceGeneric(String, tFuncOfProviderBinding);
DictionaryOfStringToProviderBindingFn_TryGetValue =
module.Import(tProviderDict.Resolve().GetMethod("TryGetValue"))
.MakeHostInstanceGeneric(String, tFuncOfProviderBinding);
}
示例3: ImportGeneric
/// <summary>
/// Imports a method of a generic type.
/// </summary>
/// <returns>
/// Returns an imported method with the given generic arguments applied to the declaring type.
/// </returns>
/// <param name="t">The type declaring the desired method.</param>
/// <param name="predicate">A predicate identifying the desired method. Must match one and only one method.</param>
/// <param name="genericArguments">The generic arguments to be applied.</param>
protected MethodReference ImportGeneric(TypeReference t, Func<MethodDefinition, bool> predicate, params TypeReference[] genericArguments)
{
var gt = t.MakeGenericInstanceType(genericArguments);
return ModuleDefinition
.Import(gt.Resolve().Methods.FirstOrDefault(predicate))
.MakeHostInstanceGeneric(genericArguments);
}
示例4: ImportInjectBindingDictionary
private void ImportInjectBindingDictionary(ModuleDefinition module, TypeReference tDict)
{
var tFuncOfBinding = FuncOfT.MakeGenericInstanceType(Binding);
var tDictOfStringToBindingFn = tDict.MakeGenericInstanceType(
String, tFuncOfBinding);
DictionaryOfStringToBindingFn = tDictOfStringToBindingFn;
DictionaryOfStringToBindingFn_New =
module.Import(
tDictOfStringToBindingFn.Resolve()
.Methods
.First(
c =>
c.Name == ".ctor" &&
c.Parameters.Count == 1 &&
c.Parameters[0].ParameterType.Name.StartsWith("IEqualityComparer")))
.MakeHostInstanceGeneric(String, tFuncOfBinding);
DictionaryOfStringToBindingFn_Add =
module.Import(tDictOfStringToBindingFn.Resolve().GetMethod("Add"))
.MakeHostInstanceGeneric(String, tFuncOfBinding);
DictionaryOfStringToBindingFn_TryGetValue =
module.Import(tDictOfStringToBindingFn.Resolve().GetMethod("TryGetValue"))
.MakeHostInstanceGeneric(String, tFuncOfBinding);
}
示例5: GetFnMethods
private Tuple<TypeReference, MethodReference, MethodReference> GetFnMethods(
TypeReference tFn,
params TypeReference[] generics)
{
var t = Import(tFn.MakeGenericInstanceType(generics));
var ctor = ImportGeneric(
tFn,
m => m.IsConstructor
&& (m.Attributes & MethodAttributes.Public) == MethodAttributes.Public
&& m.Parameters.Count == 2,
generics);
var invoke = ImportGeneric(
tFn,
m => m.Name == "Invoke",
generics);
return Tuple.Create(t, ctor, invoke);
}