// 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; }
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; }
// 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; }
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; }
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; }
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; }
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; }
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; }