本文整理汇总了C#中System.Reflection.MethodInfo.GetParentDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetParentDefinition方法的具体用法?C# MethodInfo.GetParentDefinition怎么用?C# MethodInfo.GetParentDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetParentDefinition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalParamIsDefined
// For ParameterInfo's we need to make sure that we chain through all the MethodInfo's in the inheritance chain.
// We pick up all the CustomAttributes for the starting ParameterInfo. We need to pick up only attributes that are marked inherited from the remainder of the ParameterInfo's in the inheritance chain.
// For MethodInfo's on an interface we do not do an inheritance walk. For ParameterInfo's on a
// Class we walk up the inheritance chain but do not look at the MethodInfo's on the interfaces that the
// class inherits from.
private static bool InternalParamIsDefined(MethodInfo method,ParameterInfo param,Type type, bool inherit)
{
if (param.IsDefined(type, false))
return true;
if (method.DeclaringType == null || !inherit) // This is an interface so we are done.
return false;
int paramPosition = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
ParameterInfo [] parameters = method.GetParameters();
param = parameters[paramPosition];
Object [] objAttr = param.GetCustomAttributes(type, false);
for (int i=0;i<objAttr.Length;i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if ((objAttr[i] is Attribute)
&& (attribUsage.Inherited))
return true;
}
method = method.GetParentDefinition();
}
return false;
}
示例2: InternalParamIsDefined
private static bool InternalParamIsDefined(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
if (param.IsDefined(type, false))
{
return true;
}
if ((method.DeclaringType != null) && inherit)
{
int position = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
param = method.GetParameters()[position];
object[] customAttributes = param.GetCustomAttributes(type, false);
for (int i = 0; i < customAttributes.Length; i++)
{
AttributeUsageAttribute attributeUsage = InternalGetAttributeUsage(customAttributes[i].GetType());
if ((customAttributes[i] is Attribute) && attributeUsage.Inherited)
{
return true;
}
}
method = method.GetParentDefinition();
}
}
return false;
}
示例3: InternalParamGetCustomAttributes
// For ParameterInfo's we need to make sure that we chain through all the MethodInfo's in the inheritance chain that
// have this ParameterInfo defined. .We pick up all the CustomAttributes for the starting ParameterInfo. We need to pick up only attributes
// that are marked inherited from the remainder of the MethodInfo's in the inheritance chain.
// For MethodInfo's on an interface we do not do an inheritance walk so the default ParameterInfo attributes are returned.
// For MethodInfo's on a class we walk up the inheritance chain but do not look at the MethodInfo's on the interfaces that the
// class inherits from and return the respective ParameterInfo attributes
private static Attribute[] InternalParamGetCustomAttributes(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
ArrayList disAllowMultiple = new ArrayList();
Object [] objAttr;
if (type == null)
type = s_AttributeType;
objAttr = param.GetCustomAttributes(type, false);
for (int i=0;i<objAttr.Length;i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if (attribUsage.AllowMultiple == false)
disAllowMultiple.Add(objType);
}
// Get all the attributes that have Attribute as the base class
Attribute [] ret = null;
if (objAttr.Length == 0)
ret = (Attribute[])Array.CreateInstance(type,0);
else
ret = (Attribute[])objAttr;
if (method.DeclaringType == null) // This is an interface so we are done.
return ret;
if (!inherit)
return ret;
int paramPosition = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
// Find the ParameterInfo on this method
ParameterInfo [] parameters = method.GetParameters();
param = parameters[paramPosition]; // Point to the correct ParameterInfo of the method
objAttr = param.GetCustomAttributes(type, false);
int count = 0;
for (int i=0;i<objAttr.Length;i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if ((attribUsage.Inherited)
&& (disAllowMultiple.Contains(objType) == false))
{
if (attribUsage.AllowMultiple == false)
disAllowMultiple.Add(objType);
count++;
}
else
objAttr[i] = null;
}
// Get all the attributes that have Attribute as the base class
Attribute [] attributes = (Attribute[])Array.CreateInstance(type,count);
count=0;
for (int i=0;i<objAttr.Length;i++)
{
if (objAttr[i] != null)
{
attributes[count] = (Attribute)objAttr[i];
count++;
}
}
Attribute [] temp = ret;
ret = (Attribute[])Array.CreateInstance(type,temp.Length + count);
Array.Copy(temp,ret,temp.Length);
int offset = temp.Length;
for (int i=0;i<attributes.Length;i++)
ret[offset + i] = attributes[i];
method = method.GetParentDefinition();
}
return ret;
}
示例4: InternalParamGetCustomAttributes
private static Attribute[] InternalParamGetCustomAttributes(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
ArrayList list = new ArrayList();
if (type == null)
{
type = typeof(Attribute);
}
object[] customAttributes = param.GetCustomAttributes(type, false);
for (int i = 0; i < customAttributes.Length; i++)
{
Type type2 = customAttributes[i].GetType();
if (!InternalGetAttributeUsage(type2).AllowMultiple)
{
list.Add(type2);
}
}
Attribute[] destinationArray = null;
if (customAttributes.Length == 0)
{
destinationArray = (Attribute[]) Array.CreateInstance(type, 0);
}
else
{
destinationArray = (Attribute[]) customAttributes;
}
if (method.DeclaringType != null)
{
if (!inherit)
{
return destinationArray;
}
int position = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
param = method.GetParameters()[position];
customAttributes = param.GetCustomAttributes(type, false);
int length = 0;
for (int j = 0; j < customAttributes.Length; j++)
{
Type type3 = customAttributes[j].GetType();
AttributeUsageAttribute attributeUsage = InternalGetAttributeUsage(type3);
if (attributeUsage.Inherited && !list.Contains(type3))
{
if (!attributeUsage.AllowMultiple)
{
list.Add(type3);
}
length++;
}
else
{
customAttributes[j] = null;
}
}
Attribute[] attributeArray2 = (Attribute[]) Array.CreateInstance(type, length);
length = 0;
for (int k = 0; k < customAttributes.Length; k++)
{
if (customAttributes[k] != null)
{
attributeArray2[length] = (Attribute) customAttributes[k];
length++;
}
}
Attribute[] sourceArray = destinationArray;
destinationArray = (Attribute[]) Array.CreateInstance(type, (int) (sourceArray.Length + length));
Array.Copy(sourceArray, destinationArray, sourceArray.Length);
int num6 = sourceArray.Length;
for (int m = 0; m < attributeArray2.Length; m++)
{
destinationArray[num6 + m] = attributeArray2[m];
}
method = method.GetParentDefinition();
}
}
return destinationArray;
}
示例5: InternalParamIsDefined
private static bool InternalParamIsDefined(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
if (param.IsDefined(type, false))
return true;
if (method.DeclaringType == null || !inherit)
return false;
int position = param.Position;
for (method = method.GetParentDefinition(); method != null; method = method.GetParentDefinition())
{
param = method.GetParameters()[position];
object[] customAttributes = param.GetCustomAttributes(type, false);
for (int index = 0; index < customAttributes.Length; ++index)
{
AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(customAttributes[index].GetType());
if (customAttributes[index] is Attribute && attributeUsage.Inherited)
return true;
}
}
return false;
}
示例6: InternalParamGetCustomAttributes
private static Attribute[] InternalParamGetCustomAttributes(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
ArrayList arrayList = new ArrayList();
if (type == null)
type = typeof (Attribute);
object[] customAttributes1 = param.GetCustomAttributes(type, false);
for (int index = 0; index < customAttributes1.Length; ++index)
{
Type type1 = customAttributes1[index].GetType();
if (!Attribute.InternalGetAttributeUsage(type1).AllowMultiple)
arrayList.Add((object) type1);
}
Attribute[] attributeArray1 = customAttributes1.Length != 0 ? (Attribute[]) customAttributes1 : (Attribute[]) Array.CreateInstance(type, 0);
if (method.DeclaringType == null || !inherit)
return attributeArray1;
int position = param.Position;
for (method = method.GetParentDefinition(); method != null; method = method.GetParentDefinition())
{
param = method.GetParameters()[position];
object[] customAttributes2 = param.GetCustomAttributes(type, false);
int length1 = 0;
for (int index = 0; index < customAttributes2.Length; ++index)
{
Type type1 = customAttributes2[index].GetType();
AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(type1);
if (attributeUsage.Inherited && !arrayList.Contains((object) type1))
{
if (!attributeUsage.AllowMultiple)
arrayList.Add((object) type1);
++length1;
}
else
customAttributes2[index] = (object) null;
}
Attribute[] attributeArray2 = (Attribute[]) Array.CreateInstance(type, length1);
int index1 = 0;
for (int index2 = 0; index2 < customAttributes2.Length; ++index2)
{
if (customAttributes2[index2] != null)
{
attributeArray2[index1] = (Attribute) customAttributes2[index2];
++index1;
}
}
Attribute[] attributeArray3 = attributeArray1;
attributeArray1 = (Attribute[]) Array.CreateInstance(type, attributeArray3.Length + index1);
Array.Copy((Array) attributeArray3, (Array) attributeArray1, attributeArray3.Length);
int length2 = attributeArray3.Length;
for (int index2 = 0; index2 < attributeArray2.Length; ++index2)
attributeArray1[length2 + index2] = attributeArray2[index2];
}
return attributeArray1;
}
示例7: InternalParamIsDefined
private static bool InternalParamIsDefined(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
// For ParameterInfo's we need to make sure that we chain through all the MethodInfo's in the inheritance chain.
// We pick up all the CustomAttributes for the starting ParameterInfo. We need to pick up only attributes
// that are marked inherited from the remainder of the ParameterInfo's in the inheritance chain.
// For MethodInfo's on an interface we do not do an inheritance walk. For ParameterInfo's on a
// Class we walk up the inheritance chain but do not look at the MethodInfo's on the interfaces that the class inherits from.
if (param.IsDefined(type, false))
return true;
if (method.DeclaringType == null || !inherit) // This is an interface so we are done.
return false;
int paramPosition = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
ParameterInfo [] parameters = method.GetParameters();
param = parameters[paramPosition];
Object [] objAttr = param.GetCustomAttributes(type, false);
for (int i =0; i < objAttr.Length; i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if ((objAttr[i] is Attribute) && (attribUsage.Inherited))
return true;
}
method = method.GetParentDefinition();
}
return false;
}
示例8: InternalParamGetCustomAttributes
private static Attribute[] InternalParamGetCustomAttributes(MethodInfo method, ParameterInfo param, Type type, bool inherit)
{
// For ParameterInfo's we need to make sure that we chain through all the MethodInfo's in the inheritance chain that
// have this ParameterInfo defined. .We pick up all the CustomAttributes for the starting ParameterInfo. We need to pick up only attributes
// that are marked inherited from the remainder of the MethodInfo's in the inheritance chain.
// For MethodInfo's on an interface we do not do an inheritance walk so the default ParameterInfo attributes are returned.
// For MethodInfo's on a class we walk up the inheritance chain but do not look at the MethodInfo's on the interfaces that the
// class inherits from and return the respective ParameterInfo attributes
ArrayList disAllowMultiple = new ArrayList();
Object [] objAttr;
if (type == null)
type = typeof(Attribute);
objAttr = param.GetCustomAttributes(type, false);
for (int i =0;i < objAttr.Length;i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if (attribUsage.AllowMultiple == false)
disAllowMultiple.Add(objType);
}
// Get all the attributes that have Attribute as the base class
Attribute [] ret = null;
if (objAttr.Length == 0)
ret = (Attribute[])Array.CreateInstance(type,0);
else
ret = (Attribute[])objAttr;
if (method.DeclaringType == null) // This is an interface so we are done.
return ret;
if (!inherit)
return ret;
int paramPosition = param.Position;
method = method.GetParentDefinition();
while (method != null)
{
// Find the ParameterInfo on this method
ParameterInfo [] parameters = method.GetParameters();
param = parameters[paramPosition]; // Point to the correct ParameterInfo of the method
objAttr = param.GetCustomAttributes(type, false);
int count = 0;
for (int i =0;i < objAttr.Length;i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if ((attribUsage.Inherited) && (disAllowMultiple.Contains(objType) == false))
{
if (attribUsage.AllowMultiple == false)
disAllowMultiple.Add(objType);
count++;
}
else
objAttr[i] = null;
}
// Get all the attributes that have Attribute as the base class
Attribute [] attributes = (Attribute[])Array.CreateInstance(type,count);
count = 0;
for (int i =0;i < objAttr.Length;i++)
{
if (objAttr[i] != null)
{
attributes[count] = (Attribute)objAttr[i];
count++;
}
}
Attribute [] temp = ret;
ret = (Attribute[])Array.CreateInstance(type,temp.Length + count);
Array.Copy(temp,ret,temp.Length);
int offset = temp.Length;
for (int i =0;i < attributes.Length;i++)
ret[offset + i] = attributes[i];
method = method.GetParentDefinition();
}
return ret;
}