本文整理汇总了C#中System.Reflection.MethodBase.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.Clone方法的具体用法?C# MethodBase.Clone怎么用?C# MethodBase.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.Clone方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectMethod
[System.Security.SecuritySafeCritical] // auto-generated
public override MethodBase SelectMethod(BindingFlags bindingAttr,MethodBase[] match,Type[] types,ParameterModifier[] modifiers)
{
int i;
int j;
Type[] realTypes = new Type[types.Length];
for (i=0;i<types.Length;i++) {
realTypes[i] = types[i].UnderlyingSystemType;
if (!(realTypes[i] is RuntimeType))
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"types");
}
types = realTypes;
// We don't automatically jump out on exact match.
if (match == null || match.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
MethodBase[] candidates = (MethodBase[]) match.Clone();
// Find all the methods that can be described by the types parameter.
// Remove all of them that cannot.
int CurIdx = 0;
for (i=0;i<candidates.Length;i++) {
ParameterInfo[] par = candidates[i].GetParametersNoCopy();
if (par.Length != types.Length)
continue;
for (j=0;j<types.Length;j++) {
Type pCls = par[j].ParameterType;
if (pCls == types[j])
continue;
if (pCls == typeof(Object))
continue;
if (pCls.IsPrimitive) {
if (!(types[j].UnderlyingSystemType is RuntimeType) ||
!CanConvertPrimitive((RuntimeType)types[j].UnderlyingSystemType,(RuntimeType)pCls.UnderlyingSystemType))
break;
}
else {
if (!pCls.IsAssignableFrom(types[j]))
break;
}
}
if (j == types.Length)
candidates[CurIdx++] = candidates[i];
}
if (CurIdx == 0)
return null;
if (CurIdx == 1)
return candidates[0];
// Walk all of the methods looking the most specific method to invoke
int currentMin = 0;
bool ambig = false;
int[] paramOrder = new int[types.Length];
for (i=0;i<types.Length;i++)
paramOrder[i] = i;
for (i=1;i<CurIdx;i++) {
int newMin = FindMostSpecificMethod(candidates[currentMin], paramOrder, null, candidates[i], paramOrder, null, types, null);
if (newMin == 0)
ambig = true;
else {
if (newMin == 2) {
currentMin = i;
ambig = false;
currentMin = i;
}
}
}
if (ambig)
throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
return candidates[currentMin];
}
示例2: SelectMethod
// Given a set of methods that match the base criteria, select a method based
// upon an array of types. This method should return null if no method matchs
// the criteria.
public static MethodBase SelectMethod(MethodBase[] match, Type[] types)
{
int i;
int j;
MethodBase[] candidates = (MethodBase[])match.Clone();
// Find all the methods that can be described by the types parameter.
// Remove all of them that cannot.
int CurIdx = 0;
for (i = 0; i < candidates.Length; i++)
{
ParameterInfo[] par = candidates[i].GetParameters();
if (par.Length != types.Length)
continue;
for (j = 0; j < types.Length; j++)
{
Type pCls = par[j].ParameterType;
if (pCls == types[j])
{
continue;
}
if (pCls == typeof(Object))
{
continue;
}
if (pCls.GetTypeInfo().IsPrimitive)
{
if (!CanConvertPrimitive(types[j], pCls))
{
break;
}
}
else
{
if (!pCls.GetTypeInfo().IsAssignableFrom(types[j].GetTypeInfo()))
{
break;
}
}
}
if (j == types.Length)
{
candidates[CurIdx++] = candidates[i];
}
}
if (CurIdx == 0)
{
return null;
}
if (CurIdx == 1)
{
return candidates[0];
}
// Walk all of the methods looking the most specific method to invoke
int currentMin = 0;
bool ambig = false;
int[] paramOrder = new int[types.Length];
for (i = 0; i < types.Length; i++)
{
paramOrder[i] = i;
}
for (i = 1; i < CurIdx; i++)
{
int newMin = FindMostSpecificMethod(candidates[currentMin], paramOrder, null, candidates[i], paramOrder, null, types, null);
if (newMin == 0)
{
ambig = true;
}
else
{
if (newMin == 2)
{
currentMin = i;
ambig = false;
currentMin = i;
}
}
}
if (ambig)
{
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
}
return candidates[currentMin];
}
示例3: BindToMethod
[System.Security.SecuritySafeCritical] // auto-generated
public override MethodBase BindToMethod(
BindingFlags bindingAttr, MethodBase[] match, ref Object[] args,
ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, out Object state)
{
if (match == null || match.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
Contract.EndContractBlock();
MethodBase[] candidates = (MethodBase[]) match.Clone();
int i;
int j;
state = null;
#region Map named parameters to candidate parameter postions
// We are creating an paramOrder array to act as a mapping
// between the order of the args and the actual order of the
// parameters in the method. This order may differ because
// named parameters (names) may change the order. If names
// is not provided, then we assume the default mapping (0,1,...)
int[][] paramOrder = new int[candidates.Length][];
for (i = 0; i < candidates.Length; i++)
{
ParameterInfo[] par = candidates[i].GetParametersNoCopy();
// args.Length + 1 takes into account the possibility of a last paramArray that can be omitted
paramOrder[i] = new int[(par.Length > args.Length) ? par.Length : args.Length];
if (names == null)
{
// Default mapping
for (j = 0; j < args.Length; j++)
paramOrder[i][j] = j;
}
else
{
// Named parameters, reorder the mapping. If CreateParamOrder fails, it means that the method
// doesn't have a name that matchs one of the named parameters so we don't consider it any further.
if (!CreateParamOrder(paramOrder[i], par, names))
candidates[i] = null;
}
}
#endregion
Type[] paramArrayTypes = new Type[candidates.Length];
Type[] argTypes = new Type[args.Length];
#region Cache the type of the provided arguments
// object that contain a null are treated as if they were typeless (but match either object
// references or value classes). We mark this condition by placing a null in the argTypes array.
for (i = 0; i < args.Length; i++)
{
if (args[i] != null)
{
argTypes[i] = args[i].GetType();
}
}
#endregion
// Find the method that matches...
int CurIdx = 0;
bool defaultValueBinding = ((bindingAttr & BindingFlags.OptionalParamBinding) != 0);
Type paramArrayType = null;
#region Filter methods by parameter count and type
for (i = 0; i < candidates.Length; i++)
{
paramArrayType = null;
// If we have named parameters then we may have a hole in the candidates array.
if (candidates[i] == null)
continue;
// Validate the parameters.
ParameterInfo[] par = candidates[i].GetParametersNoCopy();
#region Match method by parameter count
if (par.Length == 0)
{
#region No formal parameters
if (args.Length != 0)
{
if ((candidates[i].CallingConvention & CallingConventions.VarArgs) == 0)
continue;
}
// This is a valid routine so we move it up the candidates list.
paramOrder[CurIdx] = paramOrder[i];
candidates[CurIdx++] = candidates[i];
continue;
#endregion
}
else if (par.Length > args.Length)
//.........这里部分代码省略.........
示例4: BindToMethod
// This method is passed a set of methods and must choose the best
// fit. The methods all have the same number of arguments and the object
// array args. On exit, this method will choice the best fit method
// and coerce the args to match that method. By match, we mean all primitive
// arguments are exact matchs and all object arguments are exact or subclasses
// of the target. If the target OR is an interface, the object must implement
// that interface. There are a couple of exceptions
// thrown when a method cannot be returned. If no method matchs the args and
// ArgumentException is thrown. If multiple methods match the args then
// an AmbiguousMatchException is thrown.
//
// The most specific match will be selected.
//
public static MethodBase BindToMethod(MethodBase[] match, ref object[] args)
{
if (match == null || match.Length == 0)
{
throw new ArgumentException(SR.Arg_EmptyArray, "match");
}
MethodBase[] candidates = (MethodBase[])match.Clone();
int i;
int j;
#region Map named parameters to candidate parameter postions
// We are creating an paramOrder array to act as a mapping
// between the order of the args and the actual order of the
// parameters in the method. This order may differ because
// named parameters (names) may change the order. If names
// is not provided, then we assume the default mapping (0,1,...)
int[][] paramOrder = new int[candidates.Length][];
for (i = 0; i < candidates.Length; i++)
{
ParameterInfo[] par = candidates[i].GetParameters();
// args.Length + 1 takes into account the possibility of a last paramArray that can be omitted
paramOrder[i] = new int[(par.Length > args.Length) ? par.Length : args.Length];
// Default mapping
for (j = 0; j < args.Length; j++)
{
paramOrder[i][j] = j;
}
}
#endregion
Type[] paramArrayTypes = new Type[candidates.Length];
Type[] argTypes = new Type[args.Length];
#region Cache the type of the provided arguments
// object that contain a null are treated as if they were typeless (but match either object
// references or value classes). We mark this condition by placing a null in the argTypes array.
for (i = 0; i < args.Length; i++)
{
if (args[i] != null)
{
argTypes[i] = args[i].GetType();
}
}
#endregion
// Find the method that matches...
int CurIdx = 0;
Type paramArrayType = null;
#region Filter methods by parameter count and type
for (i = 0; i < candidates.Length; i++)
{
paramArrayType = null;
// If we have named parameters then we may have a hole in the candidates array.
if (candidates[i] == null)
{
continue;
}
// Validate the parameters.
ParameterInfo[] par = candidates[i].GetParameters();
#region Match method by parameter count
if (par.Length == 0)
{
#region No formal parameters
if (args.Length != 0)
{
if ((candidates[i].CallingConvention & CallingConventions.VarArgs) == 0)
{
continue;
}
}
// This is a valid routine so we move it up the candidates list.
paramOrder[CurIdx] = paramOrder[i];
candidates[CurIdx++] = candidates[i];
//.........这里部分代码省略.........
示例5: BindToMethod
public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state)
{
int num;
int length;
if ((match == null) || (match.Length == 0))
{
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
}
MethodBase[] baseArray = (MethodBase[]) match.Clone();
state = null;
int[][] numArray = new int[baseArray.Length][];
for (num = 0; num < baseArray.Length; num++)
{
ParameterInfo[] pars = baseArray[num].GetParametersNoCopy();
numArray[num] = new int[(pars.Length > args.Length) ? pars.Length : args.Length];
if (names == null)
{
length = 0;
while (length < args.Length)
{
numArray[num][length] = length;
length++;
}
}
else if (!CreateParamOrder(numArray[num], pars, names))
{
baseArray[num] = null;
}
}
Type[] typeArray = new Type[baseArray.Length];
Type[] types = new Type[args.Length];
for (num = 0; num < args.Length; num++)
{
if (args[num] != null)
{
types[num] = args[num].GetType();
}
}
int index = 0;
bool flag = (bindingAttr & BindingFlags.OptionalParamBinding) != BindingFlags.Default;
Type elementType = null;
for (num = 0; num < baseArray.Length; num++)
{
elementType = null;
if (baseArray[num] != null)
{
ParameterInfo[] infoArray2 = baseArray[num].GetParametersNoCopy();
if (infoArray2.Length == 0)
{
if ((args.Length == 0) || ((baseArray[num].CallingConvention & CallingConventions.VarArgs) != 0))
{
numArray[index] = numArray[num];
baseArray[index++] = baseArray[num];
}
continue;
}
if (infoArray2.Length > args.Length)
{
length = args.Length;
while (length < (infoArray2.Length - 1))
{
if (infoArray2[length].DefaultValue == DBNull.Value)
{
break;
}
length++;
}
if (length != (infoArray2.Length - 1))
{
continue;
}
if (infoArray2[length].DefaultValue == DBNull.Value)
{
if (!infoArray2[length].ParameterType.IsArray || !infoArray2[length].IsDefined(typeof(ParamArrayAttribute), true))
{
continue;
}
elementType = infoArray2[length].ParameterType.GetElementType();
}
}
else if (infoArray2.Length < args.Length)
{
int num4 = infoArray2.Length - 1;
if ((!infoArray2[num4].ParameterType.IsArray || !infoArray2[num4].IsDefined(typeof(ParamArrayAttribute), true)) || (numArray[num][num4] != num4))
{
continue;
}
elementType = infoArray2[num4].ParameterType.GetElementType();
}
else
{
int num5 = infoArray2.Length - 1;
if ((infoArray2[num5].ParameterType.IsArray && infoArray2[num5].IsDefined(typeof(ParamArrayAttribute), true)) && ((numArray[num][num5] == num5) && !infoArray2[num5].ParameterType.IsAssignableFrom(types[num5])))
{
elementType = infoArray2[num5].ParameterType.GetElementType();
}
}
Type parameterType = null;
int num6 = (elementType != null) ? (infoArray2.Length - 1) : args.Length;
length = 0;
//.........这里部分代码省略.........
示例6: SelectMethod
public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
int num;
Type[] typeArray = new Type[types.Length];
for (num = 0; num < types.Length; num++)
{
typeArray[num] = types[num].UnderlyingSystemType;
if (!(typeArray[num] is RuntimeType))
{
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "types");
}
}
types = typeArray;
if ((match == null) || (match.Length == 0))
{
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
}
MethodBase[] baseArray = (MethodBase[]) match.Clone();
int num3 = 0;
for (num = 0; num < baseArray.Length; num++)
{
ParameterInfo[] parametersNoCopy = baseArray[num].GetParametersNoCopy();
if (parametersNoCopy.Length == types.Length)
{
int num2 = 0;
while (num2 < types.Length)
{
Type parameterType = parametersNoCopy[num2].ParameterType;
if ((parameterType != types[num2]) && (parameterType != typeof(object)))
{
if (parameterType.IsPrimitive)
{
if (!(types[num2].UnderlyingSystemType is RuntimeType) || !CanConvertPrimitive((RuntimeType) types[num2].UnderlyingSystemType, (RuntimeType) parameterType.UnderlyingSystemType))
{
break;
}
}
else if (!parameterType.IsAssignableFrom(types[num2]))
{
break;
}
}
num2++;
}
if (num2 == types.Length)
{
baseArray[num3++] = baseArray[num];
}
}
}
switch (num3)
{
case 0:
return null;
case 1:
return baseArray[0];
}
int index = 0;
bool flag = false;
int[] numArray = new int[types.Length];
for (num = 0; num < types.Length; num++)
{
numArray[num] = num;
}
for (num = 1; num < num3; num++)
{
switch (FindMostSpecificMethod(baseArray[index], numArray, null, baseArray[num], numArray, null, types, null))
{
case 0:
flag = true;
break;
case 2:
index = num;
flag = false;
index = num;
break;
}
}
if (flag)
{
throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
}
return baseArray[index];
}
示例7: SelectMethod
public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
Type[] array = new Type[types.Length];
for (int i = 0; i < types.Length; i++)
{
array[i] = types[i].UnderlyingSystemType;
if (!(array[i] is RuntimeType))
{
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "types");
}
}
types = array;
if (match == null || match.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
}
MethodBase[] array2 = (MethodBase[])match.Clone();
int num = 0;
for (int i = 0; i < array2.Length; i++)
{
ParameterInfo[] parametersNoCopy = array2[i].GetParametersNoCopy();
if (parametersNoCopy.Length == types.Length)
{
int j;
for (j = 0; j < types.Length; j++)
{
Type parameterType = parametersNoCopy[j].ParameterType;
if (!(parameterType == types[j]) && !(parameterType == typeof(object)))
{
if (parameterType.IsPrimitive)
{
if (!(types[j].UnderlyingSystemType is RuntimeType))
{
break;
}
if (!DefaultBinder.CanConvertPrimitive((RuntimeType)types[j].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType))
{
break;
}
}
else
{
if (!parameterType.IsAssignableFrom(types[j]))
{
break;
}
}
}
}
if (j == types.Length)
{
array2[num++] = array2[i];
}
}
}
if (num == 0)
{
return null;
}
if (num == 1)
{
return array2[0];
}
int num2 = 0;
bool flag = false;
int[] array3 = new int[types.Length];
for (int i = 0; i < types.Length; i++)
{
array3[i] = i;
}
for (int i = 1; i < num; i++)
{
int num3 = DefaultBinder.FindMostSpecificMethod(array2[num2], array3, null, array2[i], array3, null, types, null);
if (num3 == 0)
{
flag = true;
}
else
{
if (num3 == 2)
{
num2 = i;
flag = false;
num2 = i;
}
}
}
if (flag)
{
throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
}
return array2[num2];
}
示例8: BindToMethod
public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state)
{
if (match == null || match.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
}
MethodBase[] array = (MethodBase[])match.Clone();
state = null;
int[][] array2 = new int[array.Length][];
for (int i = 0; i < array.Length; i++)
{
ParameterInfo[] parametersNoCopy = array[i].GetParametersNoCopy();
array2[i] = new int[(parametersNoCopy.Length > args.Length) ? parametersNoCopy.Length : args.Length];
if (names == null)
{
for (int j = 0; j < args.Length; j++)
{
array2[i][j] = j;
}
}
else
{
if (!DefaultBinder.CreateParamOrder(array2[i], parametersNoCopy, names))
{
array[i] = null;
}
}
}
Type[] array3 = new Type[array.Length];
Type[] array4 = new Type[args.Length];
for (int i = 0; i < args.Length; i++)
{
if (args[i] != null)
{
array4[i] = args[i].GetType();
}
}
int num = 0;
bool flag = (bindingAttr & BindingFlags.OptionalParamBinding) != BindingFlags.Default;
Type type = null;
for (int i = 0; i < array.Length; i++)
{
type = null;
if (!(array[i] == null))
{
ParameterInfo[] parametersNoCopy2 = array[i].GetParametersNoCopy();
if (parametersNoCopy2.Length == 0)
{
if (args.Length == 0 || (array[i].CallingConvention & CallingConventions.VarArgs) != (CallingConventions)0)
{
array2[num] = array2[i];
array[num++] = array[i];
}
}
else
{
int j;
if (parametersNoCopy2.Length > args.Length)
{
j = args.Length;
while (j < parametersNoCopy2.Length - 1 && parametersNoCopy2[j].DefaultValue != DBNull.Value)
{
j++;
}
if (j != parametersNoCopy2.Length - 1)
{
goto IL_42C;
}
if (parametersNoCopy2[j].DefaultValue == DBNull.Value)
{
if (!parametersNoCopy2[j].ParameterType.IsArray || !parametersNoCopy2[j].IsDefined(typeof(ParamArrayAttribute), true))
{
goto IL_42C;
}
type = parametersNoCopy2[j].ParameterType.GetElementType();
}
}
else
{
if (parametersNoCopy2.Length < args.Length)
{
int num2 = parametersNoCopy2.Length - 1;
if (!parametersNoCopy2[num2].ParameterType.IsArray || !parametersNoCopy2[num2].IsDefined(typeof(ParamArrayAttribute), true) || array2[i][num2] != num2)
{
goto IL_42C;
}
type = parametersNoCopy2[num2].ParameterType.GetElementType();
}
else
{
int num3 = parametersNoCopy2.Length - 1;
if (parametersNoCopy2[num3].ParameterType.IsArray && parametersNoCopy2[num3].IsDefined(typeof(ParamArrayAttribute), true) && array2[i][num3] == num3 && !parametersNoCopy2[num3].ParameterType.IsAssignableFrom(array4[num3]))
{
type = parametersNoCopy2[num3].ParameterType.GetElementType();
}
}
}
Type type2 = null;
int num4 = (type != null) ? (parametersNoCopy2.Length - 1) : args.Length;
for (j = 0; j < num4; j++)
//.........这里部分代码省略.........