1 // ReflectionSerializationHolder.cs
\r
3 // Note: this class was superseded by MemberInfoSerializationHolder but
\r
4 // it's still included in the build to provide backwards compatibility.
\r
7 // Patrik Torstensson
\r
9 // (C) 2003 Patrik Torstensson
\r
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
14 // Permission is hereby granted, free of charge, to any person obtaining
\r
15 // a copy of this software and associated documentation files (the
\r
16 // "Software"), to deal in the Software without restriction, including
\r
17 // without limitation the rights to use, copy, modify, merge, publish,
\r
18 // distribute, sublicense, and/or sell copies of the Software, and to
\r
19 // permit persons to whom the Software is furnished to do so, subject to
\r
20 // the following conditions:
\r
22 // The above copyright notice and this permission notice shall be
\r
23 // included in all copies or substantial portions of the Software.
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 using System.Runtime.Serialization;
\r
37 namespace System.Reflection
\r
40 internal class ReflectionSerializationHolder : IObjectReference, ISerializable
\r
43 string _memberSignature;
\r
44 MemberTypes _memberType;
\r
45 Type _reflectedType;
\r
47 ReflectionSerializationHolder(SerializationInfo info, StreamingContext ctx)
\r
49 string assemblyName;
\r
52 assemblyName = info.GetString("AssemblyName");
\r
53 typeName = info.GetString("ClassName");
\r
55 _memberName = info.GetString("Name");
\r
56 _memberSignature = info.GetString("Signature");
\r
57 _memberType = (MemberTypes) info.GetInt32("MemberType");
\r
60 Assembly asm = Assembly.Load(assemblyName);
\r
62 _reflectedType = asm.GetType(typeName, true, true);
\r
65 public static void Serialize(SerializationInfo info, String name, Type klass, String signature, MemberTypes type)
\r
67 info.SetType( typeof(ReflectionSerializationHolder));
\r
69 info.AddValue("AssemblyName", klass.Module.Assembly.FullName, typeof(String));
\r
70 info.AddValue("ClassName", klass.FullName, typeof(String));
\r
72 info.AddValue("Name", name, typeof(String));
\r
73 info.AddValue("Signature", signature, typeof(String));
\r
74 info.AddValue("MemberType",(int)type);
\r
77 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
79 throw new NotSupportedException();
\r
82 public object GetRealObject(StreamingContext context)
\r
84 switch (_memberType)
\r
86 case MemberTypes.Constructor:
\r
87 ConstructorInfo [] ctors;
\r
89 ctors = _reflectedType.GetConstructors (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
\r
90 for (int i = 0; i < ctors.Length; i++)
\r
91 if ( ctors[i].ToString().Equals(_memberSignature))
\r
94 throw new SerializationException("Failed to find serialized constructor");
\r
96 case MemberTypes.Method:
\r
97 MethodInfo [] methods;
\r
99 methods = _reflectedType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
\r
100 for (int i = 0; i < methods.Length; i++)
\r
101 if ((methods[i]).ToString().Equals(_memberSignature))
\r
104 throw new SerializationException("Failed to find serialized method");
\r
106 throw new SerializationException("Failed to get object for member type " + _memberType.ToString());
\r