1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
18 using System
.Reflection
;
19 using System
.Collections
;
20 using System
.Runtime
.Serialization
;
22 using Castle
.DynamicProxy
.Serialization
;
23 using Castle
.DynamicProxy
.Invocation
;
26 /// Summary description for GeneratorContext.
28 public sealed class GeneratorContext
: DictionaryBase
30 private IList _skipInterfaces
= new ArrayList();
31 private IList _skipMethods
= new ArrayList();
32 private IList _generateNewSlot
= new ArrayList();
33 private ArrayList _mixins
= new ArrayList();
34 private Type _proxyObjectReference
= typeof(ProxyObjectReference
);
35 private Type _interceptor
= typeof(IInterceptor
);
36 private Type _invocation
= typeof(IInvocation
);
37 private Type _interfaceInvocation
= typeof(InterfaceInvocation
);
38 private Type _sameClassInvocation
= typeof(SameClassInvocation
);
40 public GeneratorContext()
42 // By default we skip a few interfaces
43 AddInterfaceToSkip(typeof(ISerializable
));
46 AddMethodToSkip(typeof(ISerializable
).GetMethod("GetObjectData"));
50 /// The implementor of IObjectReference responsible for
51 /// the deserialization and reconstruction of the proxy object
53 public Type ProxyObjectReference
55 get { return _proxyObjectReference; }
56 set { _proxyObjectReference = value; }
59 public Type Interceptor
61 get { return _interceptor; }
62 set { _interceptor = value; }
65 public Type Invocation
67 get { return _invocation; }
68 set { _invocation = value; }
71 public Type InterfaceInvocation
73 get { return _interfaceInvocation; }
74 set { _interfaceInvocation = value; }
77 public Type SameClassInvocation
79 get { return _sameClassInvocation; }
80 set { _sameClassInvocation = value; }
85 get { return _mixins.Count != 0; }
88 public void AddMixinInstance(object instance
)
90 _mixins
.Add(instance
);
93 public object[] MixinsAsArray()
95 return _mixins
.ToArray();
98 public bool ShouldSkip(Type interfaceType
)
100 return _skipInterfaces
.Contains(interfaceType
);
103 public bool ShouldSkip(MethodInfo method
)
105 return _skipMethods
.Contains(method
);
109 /// Checks if the method has the same signature as a method that was marked as
110 /// one that should generate a new vtable slot.
112 public bool ShouldCreateNewSlot(MethodInfo method
)
114 string methodStr
= method
.ToString();
115 foreach (MethodInfo candidate
in _generateNewSlot
)
117 if (candidate
.ToString() == methodStr
)
123 public void AddInterfaceToSkip(Type interfaceType
)
125 _skipInterfaces
.Add(interfaceType
);
128 public void AddMethodToSkip(MethodInfo method
)
130 _skipMethods
.Add(method
);
133 public void AddMethodToGenerateNewSlot(MethodInfo method
)
135 _generateNewSlot
.Add(method
);
138 public object this[String key
]
140 get { return Dictionary[key]; }
141 set { Dictionary[key] = value; }