/// <devdoc> /// Retrieves the properties /// </devdoc> public override PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter) { if (instance == null) { return(DebugTypeDescriptor.GetProperties(PropertyType, filter)); } else { return(DebugTypeDescriptor.GetProperties(instance, filter)); } }
private void FillSingleMethodAttribute(MethodInfo realMethodInfo, IList attributes) { string methodName = realMethodInfo.Name; BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly; Type currentReflectType = realMethodInfo.ReflectedType; Debug.Assert(currentReflectType != null, "currentReflectType cannot be null"); // First, calculate the depth of the object hierarchy. We do this so we can do a single // object create for an array of attributes. // int depth = 0; while (currentReflectType != null && currentReflectType != typeof(object)) { depth++; currentReflectType = currentReflectType.BaseType; } if (depth > 0) { // Now build up an array in reverse order // currentReflectType = realMethodInfo.ReflectedType; object[][] attributeStack = new object[depth][]; while (currentReflectType != null && currentReflectType != typeof(object)) { // Fill in our member info so we can get at the custom attributes. // MemberInfo memberInfo = currentReflectType.GetMethod(methodName, bindingFlags); // Get custom attributes for the member info. // if (memberInfo != null) { attributeStack[--depth] = DebugTypeDescriptor.GetCustomAttributes(memberInfo); } // Ready for the next loop iteration. // currentReflectType = currentReflectType.BaseType; } // Now trawl the attribute stack so that we add attributes // from base class to most derived. // foreach (object[] attributeArray in attributeStack) { if (attributeArray != null) { foreach (object attr in attributeArray) { if (attr is Attribute) { attributes.Add(attr); } } } } } }
/// <devdoc> /// <para> /// Gets an editor of the specified type. /// </para> /// </devdoc> public override object GetEditor(Type editorBaseType) { object editor = null; // Check the editors we've already created for this type. // if (editorTypes != null) { for (int i = 0; i < editorCount; i++) { if (editorTypes[i] == editorBaseType) { return(editors[i]); } } } // If one wasn't found, then we must go through the attributes. // if (editor == null) { for (int i = 0; i < Attributes.Count; i++) { if (!(Attributes[i] is EditorAttribute)) { continue; } EditorAttribute attr = (EditorAttribute)Attributes[i]; Type editorType = GetTypeFromName(attr.EditorBaseTypeName); if (editorBaseType == editorType) { Type type = GetTypeFromName(attr.EditorTypeName); if (type != null) { editor = CreateInstance(type); break; } } } // Now, if we failed to find it in our own attributes, go to the // component descriptor. // if (editor == null) { editor = DebugTypeDescriptor.GetEditor(PropertyType, editorBaseType); } // Now, another slot in our editor cache for next time // if (editorTypes == null) { editorTypes = new Type[5]; editors = new object[5]; } if (editorCount >= editorTypes.Length) { Type[] newTypes = new Type[editorTypes.Length * 2]; object[] newEditors = new object[editors.Length * 2]; Array.Copy(editorTypes, newTypes, editorTypes.Length); Array.Copy(editors, newEditors, editors.Length); editorTypes = newTypes; editors = newEditors; } editorTypes[editorCount] = editorBaseType; editors[editorCount++] = editor; } return(editor); }