[Mono-dev] TypeForwardedFrom

Robert Jordan robertj at gmx.net
Fri Apr 5 14:14:53 UTC 2013


On 04.04.2013 20:57, Neale Ferguson wrote:
> Hi,
>   I¹m looking at fixing an incompatibility between .NET and Mono when it
> comes to Serialization. Bugzilla 11294 describes the situation but in brief
> it is a case that when .NET serializes something that has a
> TypeForwardedFrom attribute that information gets put into the serialized
> object, but mono does not. It appears that all mono does when it encounters
> that attribute it simply stores it away and nothing uses it. To emulate the
> .NET behavior that information needs to be accessible in metadata about the
> type and that information uses by the Serializers.
>   I¹m trying to work out how the information captured by
> TypeForwardedFromAttribute.cs can be made available at runtime to the
> serializer. My knowledge of how mcs operates and what the contents of
> metadata are and how to access them is my roadblock. So any reading/code
> that I can be directed to would be a great help.


You don't need to know how mcs operates. The TypeForwardedFrom
information can be obtained via reflection:


public static class TypeExtensions
{
	// Returns the assembly name of a type while considering
	// TypeForwardedFromAttribute.
	public static string GetAssemblyName (this Type self)
	{
		var attrs = self.GetCustomAttributes(typeof 
(TypeForwardedFromAttribute), false);
		if (attrs.Length == 0)
			return self.Assembly.FullName;
		else
			return ((TypeForwardedFromAttribute)attrs [0]).AssemblyFullName;
	}
}


I've attached a full sample which proves that MS.NET is simply
emitting TypeForwardedFromAttribute.AssemblyFullName for the
assembly name during serialization.

Robert

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tffa.cs
Type: text/x-csharp
Size: 1340 bytes
Desc: not available
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20130405/cf472661/attachment.bin>


More information about the Mono-devel-list mailing list