[Mono-dev] Type.cs patch wrt serializability
Atsushi Eno
atsushi at ximian.com
Tue Nov 8 05:35:50 EST 2005
Ahh, nice :-) can you please check the fix in svn?
Atsushi Eno
Zoltan Varga wrote:
> Hi,
>
> This is not correct. net 2.0 rtm does return SerializableAttribute
> for types/enums/delegates
> but only if the type has the 'serializable' attribute in metadata.
> Here is an improved patch:
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Index: Type.cs
> ===================================================================
> --- Type.cs (revision 52628)
> +++ Type.cs (working copy)
> @@ -1243,7 +1243,8 @@
> internal object[] GetPseudoCustomAttributes () {
> int count = 0;
>
> - if (IsSerializable)
> + /* IsSerializable returns true for delegates/enums as well */
> + if (Attributes & TypeAttributes.Serializable) != 0)
> count ++;
>
> if (count == 0)
> @@ -1251,7 +1252,7 @@
> object[] attrs = new object [count];
> count = 0;
>
> - if (IsSerializable)
> + if (Attributes & TypeAttributes.Serializable) != 0)
> attrs [count ++] = new SerializableAttribute ();
>
> return attrs;
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>
> Zoltan
>
> On 11/8/05, Atsushi Eno <atsushi at ximian.com> wrote:
>> Hello,
>>
>> Here is a patch for Type.cs to not add SerializableAttribute for
>> Serializable type (the code affects only on 2.0 profile). Currently
>> all enums and delegates are automatically added this attribute.
>>
>> I guess it used to do that, does not seem to apply to in 2.0 RTM.
>>
>> The attached test should print
>> True[CR]False[CR]System.MonoTODOAttribute (no SerializableAttribute).
>>
>> Is there still any reason we need SerializableAttribute there?
>>
>> Atsushi Eno
>>
>>
>>
>> Index: Type.cs
>> ===================================================================
>> --- Type.cs (revision 52652)
>> +++ Type.cs (working copy)
>> @@ -1241,20 +1241,7 @@
>> }
>>
>> internal object[] GetPseudoCustomAttributes () {
>> - int count = 0;
>> -
>> - if (IsSerializable)
>> - count ++;
>> -
>> - if (count == 0)
>> - return null;
>> - object[] attrs = new object [count];
>> - count = 0;
>> -
>> - if (IsSerializable)
>> - attrs [count ++] = new SerializableAttribute ();
>> -
>> - return attrs;
>> + return null;
>> }
>>
>> #endif
>>
>> using System;
>> using System.Xml;
>> using System.Xml.Schema;
>>
>> public class Test
>> {
>> public static void Main ()
>> {
>> Console.WriteLine (typeof (MyEnum).IsSerializable);
>> foreach (object o in typeof (MyEnum).GetCustomAttributes (false))
>> Console.WriteLine (o.GetType ());
>> Console.WriteLine (typeof (XmlSchemaInference).IsSerializable);
>> foreach (object o in typeof (XmlSchemaInference).GetCustomAttributes (true))
>> Console.WriteLine (o.GetType ());
>> }
>> }
>>
>> public enum MyEnum
>> {
>> Foo
>> }
>>
>>
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
>>
>>
>
More information about the Mono-devel-list
mailing list