Setting reflection metadata at run-time

BlitzMax Forums/BlitzMax Programming/Setting reflection metadata at run-time

I'm currently faced with a desire to extend a base type being blocked by incompatible Field metadata.

The base type uses:

List:TList {NoClone}

And the type I'd like to make an extension of the base uses

List:TList {Clone}

Is there any way of setting metadata at run-time to get around this?

[edit - thought I was ok - but no, still stuck :-) ]

can't you override the field in the extended type?
something like:
Type TBase
	Field List:TList {NoClone}
	Function Create:TBase()
	End Function
End Type

Type TChild extends TBase
	Field List:TList {Clone}
	Function Create:TChild()
	End Function
End Type


SuperStrict

Type Test
	Field  List:Int[2]  {Dog}
	
	Method GetMeta:String(_object:Object)
	
		Local object_id:TTypeId=TTypeId.ForObject(_object)
		Local field_list:TList = object_id.EnumFields()
					
		If field_list 
			For Local object_field:TField=EachIn field_list
				Print object_field.MetaData()
			Next
		EndIf
		
	End Method
	
	Method PrintList()
		Print List[0]
		Print List[1]
		
	End Method
	
	Method New()
		List[0] = 1
		List [1] = 2
	End Method
	
End Type

Type Test2 Extends Test

	Field List:Int[2]  {Cat}
	
	Method New()
		List[0] = 10
		List [1] = 20
	End Method
	
	Method PrintList2()
		Print List[0]
		Print List[1]
	End Method

End Type

Local jack:Test2 = New Test2
jack.PrintList()
jack.PrintList2()
Print jack.GetMeta(jack)

Outputs:
1
2
10
20
Dog=1
Cat=1

Uh oh...

How about this?
Type TTest
	Field Test:Int {NoClone}
EndType

Local f:TField = TTypeId.ForName("TTest").FindField("Test")
Print "before: " + f.MetaData()
f._meta = "Clone=1"

Local o:TTest = New TTest
Print "after: " + TTypeId.ForObject(o).FindField("Test").MetaData()


Thanks grable. It certainly works! It does make me uneasy though, directly setting a private field like that - but there doesn't seem to be any other way. I guess I could set it and safety check the result and throw an exception on error so at least I won't be caught unawares if/when the reflection module changes.

What does the "=1" mean? I've looked at the source,
Function ExtractMetaData$( meta$,key$ )
	'not currently safe: , or = in metadata could stuff it up
	'should use a map
	If Not key Return meta
	key=" "+key+"="
	meta=" "+meta+" "
	Local i=meta.Tolower().Find( key.Tolower() )
	If i=-1 Return
	i:+key.length
	meta=meta[i..meta.Find( " ",i )]
	If meta.StartsWith( "~q" ) meta=meta[1..meta.length-1]
	Return meta
End Function

But I've little clue as to what's going on in there.

What does the "=1" mean? I've looked at the source

Its added to any attributes without a value, so when you query for it you at least get something other than Null.

Right - thanks again grable.