[JEDI.NET-commits] main/run Jedi.Collections.pas,1.2,1.3
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-08-25 15:15:05
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24322/main/run Modified Files: Jedi.Collections.pas Log Message: * Added missing 'ignoreDefaultProperty' parameter in one of the InlineCollectionUtils.CreateItemProperty methods. * The InlineCollectionUtils.CreateItemProperty with the PropertyInfo parameter now just calls the other version of the method (minimizing code duplication is good ;-) ) Index: Jedi.Collections.pas =================================================================== RCS file: /cvsroot/jedidotnet/main/run/Jedi.Collections.pas,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Jedi.Collections.pas 24 Jun 2004 20:06:33 -0000 1.2 --- Jedi.Collections.pas 25 Aug 2004 15:14:56 -0000 1.3 *************** *** 52,56 **** overload; static; class function CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; component: System.Object; ! name, description: string; index, emptyValue: System.Object): PropertyDescriptor; overload; static; { Creates a property descriptor that will function as a 'new item' property. The property will get the specified --- 52,57 ---- overload; static; class function CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; component: System.Object; ! name, description: string; index, emptyValue: System.Object; ! ignoreDefaultProperty: Boolean = False): PropertyDescriptor; overload; static; { Creates a property descriptor that will function as a 'new item' property. The property will get the specified *************** *** 858,927 **** class function InlineCollectionUtils.CreateItemProperty(info: PropertyInfo; component: System.Object; name, description: string; index, emptyValue: System.Object; ignoreDefaultProperty: Boolean): PropertyDescriptor; var itemInstance: System.Object; itemType: System.Type; defaultProperty: PropertyDescriptor; - mattrs: array of System.Object; - attrs: ArrayList; - i: Integer; begin ! if not Assigned(info) then ! raise ArgumentNullException.Create('info'); if not Assigned(component) then raise ArgumentNullException.Create('component'); ! itemInstance := info.GetValue(component, [index]); ! defaultProperty := nil; if not ignoreDefaultProperty then begin if Assigned(itemInstance) then ! begin ! itemType := itemInstance.GetType; ! defaultProperty := TypeDescriptor.GetDefaultProperty(itemInstance); ! end else ! begin ! itemType := info.PropertyType; ! defaultProperty := TypeDescriptor.GetDefaultProperty(info.PropertyType); ! end end else ! begin ! if Assigned(itemInstance) then ! itemType := itemInstance.GetType ! else ! itemType := info.PropertyType; ! end; ! ! if Assigned(defaultProperty) then ! Result := ItemSubPropertyDescriptor.Create(info.DeclaringType, name, description, defaultProperty, itemType, ! emptyValue, index) ! else ! begin ! mattrs := info.GetCustomAttributes(True); ! attrs := ArrayList.Create; ! for i := 0 to High(mattrs) do ! begin ! if (description = '') or (mattrs[i].GetType <> TypeOf(DescriptionAttribute)) then ! attrs.Add(mattrs[i]); ! end; ! if description <> '' then ! attrs.Add(DescriptionAttribute.Create(description)); ! ! Result := ItemPropertyDescriptor.Create(info.DeclaringType, name, itemInstance.GetType, ! AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); ! end; ! end; - class function InlineCollectionUtils.CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; - component: System.Object; name, description: string; index, emptyValue: System.Object): PropertyDescriptor; - begin - if not Assigned(propertyType) then - raise ArgumentNullException.Create('propertyType'); - if not Assigned(component) then - raise ArgumentNullException.Create('component'); if description <> '' then attributes := AttributeUtils.CombineAttributes(attributes, AttributeArray.Create(DescriptionAttribute.Create(description))); ! Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, attributes, emptyValue, index); end; --- 859,913 ---- class function InlineCollectionUtils.CreateItemProperty(info: PropertyInfo; component: System.Object; name, description: string; index, emptyValue: System.Object; ignoreDefaultProperty: Boolean): PropertyDescriptor; + begin + if not Assigned(info) then + raise ArgumentNullException.Create('info'); + + Result := CreateItemProperty(info.PropertyType, AttributeArray(&Array(info.GetCustomAttributes(True))), component, + name, description, index, emptyValue, ignoreDefaultProperty) + end; + + class function InlineCollectionUtils.CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; + component: System.Object; name, description: string; index, emptyValue: System.Object; + ignoreDefaultProperty: Boolean): PropertyDescriptor; var itemInstance: System.Object; itemType: System.Type; defaultProperty: PropertyDescriptor; begin ! if not Assigned(propertyType) then ! raise ArgumentNullException.Create('propertyType'); if not Assigned(component) then raise ArgumentNullException.Create('component'); ! if component is IList then ! itemInstance := IList(component)[Integer(index)] ! else ! if component is IDictionary then ! itemInstance := IDictionary(component)[index] ! else ! itemInstance := nil; ! if Assigned(itemInstance) then ! itemType := itemInstance.GetType ! else ! itemType := propertyType; ! if not ignoreDefaultProperty then begin if Assigned(itemInstance) then ! defaultProperty := TypeDescriptor.GetDefaultProperty(itemInstance) else ! defaultProperty := TypeDescriptor.GetDefaultProperty(propertyType); end else ! defaultProperty := nil; if description <> '' then attributes := AttributeUtils.CombineAttributes(attributes, AttributeArray.Create(DescriptionAttribute.Create(description))); ! ! if Assigned(defaultProperty) then ! Result := ItemSubPropertyDescriptor.Create(component.GetType, name, description, defaultProperty, itemType, ! emptyValue, index) ! else ! Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, attributes, emptyValue, index); end; |