diff --git a/README.md b/README.md index eb49dc89df..ce78b73d7d 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,9 @@ Symbol | .NET 4.6.2 | .NET Standard 2.0 | . `FEATURE_APPDOMAIN` | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: `FEATURE_ASSEMBLYBUILDER_SAVE` | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: `FEATURE_BYREFLIKE` | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: -`FEATURE_SERIALIZATION` | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: `FEATURE_SYSTEM_CONFIGURATION` | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: * `FEATURE_APPDOMAIN` - enables support for features that make use of an AppDomain in the host. * `FEATURE_ASSEMBLYBUILDER_SAVE` - enabled support for saving the dynamically generated proxy assembly. * `FEATURE_BYREFLIKE` - enables support for by-ref-like (`ref struct`) types such as `Span` and `ReadOnlySpan`. -* `FEATURE_SERIALIZATION` - enables support for serialization of dynamic proxies and other types. * `FEATURE_SYSTEM_CONFIGURATION` - enables features that use System.Configuration and the ConfigurationManager. diff --git a/buildscripts/common.props b/buildscripts/common.props index 69df1b76a6..44ef8f50b2 100644 --- a/buildscripts/common.props +++ b/buildscripts/common.props @@ -56,7 +56,7 @@ DEBUG TRACE TRACE - TRACE;FEATURE_APPDOMAIN;FEATURE_ASSEMBLYBUILDER_SAVE;FEATURE_SERIALIZATION;FEATURE_SYSTEM_CONFIGURATION + TRACE;FEATURE_APPDOMAIN;FEATURE_ASSEMBLYBUILDER_SAVE;FEATURE_SYSTEM_CONFIGURATION diff --git a/ref/Castle.Core-net462.cs b/ref/Castle.Core-net462.cs index 72fadd5455..6c5f7150c9 100644 --- a/ref/Castle.Core-net462.cs +++ b/ref/Castle.Core-net462.cs @@ -1811,7 +1811,6 @@ public static void SetXsiType(this Castle.Components.DictionaryAdapter.Xml.IXmlN } namespace Castle.Core.Configuration { - [System.Serializable] public abstract class AbstractConfiguration : Castle.Core.Configuration.IConfiguration { protected AbstractConfiguration() { } @@ -1821,13 +1820,10 @@ protected AbstractConfiguration() { } public string Value { get; protected set; } public virtual object GetValue(System.Type type, object defaultValue) { } } - [System.Serializable] public class ConfigurationAttributeCollection : System.Collections.Specialized.NameValueCollection { public ConfigurationAttributeCollection() { } - protected ConfigurationAttributeCollection(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } - [System.Serializable] public class ConfigurationCollection : System.Collections.Generic.List { public ConfigurationCollection() { } @@ -1842,7 +1838,6 @@ public interface IConfiguration string Value { get; } object GetValue(System.Type type, object defaultValue); } - [System.Serializable] public class MutableConfiguration : Castle.Core.Configuration.AbstractConfiguration { public MutableConfiguration(string name) { } @@ -1884,7 +1879,6 @@ public static class ProxyServices { public static bool IsDynamicProxy(System.Type type) { } } - [System.Serializable] public class ReferenceEqualityComparer : System.Collections.Generic.IEqualityComparer, System.Collections.IEqualityComparer { public static Castle.Core.ReferenceEqualityComparer Instance { get; } @@ -1963,7 +1957,6 @@ public virtual Castle.Core.Logging.IExtendedLogger Create(System.Type type, Cast public abstract Castle.Core.Logging.IExtendedLogger Create(string name, Castle.Core.Logging.LoggerLevel level); protected static System.IO.FileInfo GetConfigFile(string fileName) { } } - [System.Serializable] public abstract class AbstractLoggerFactory : Castle.Core.Logging.ILoggerFactory { protected AbstractLoggerFactory() { } @@ -1973,7 +1966,6 @@ public virtual Castle.Core.Logging.ILogger Create(System.Type type, Castle.Core. public abstract Castle.Core.Logging.ILogger Create(string name, Castle.Core.Logging.LoggerLevel level); protected static System.IO.FileInfo GetConfigFile(string fileName) { } } - [System.Serializable] public class ConsoleFactory : Castle.Core.Logging.ILoggerFactory { public ConsoleFactory() { } @@ -1983,7 +1975,6 @@ public Castle.Core.Logging.ILogger Create(string name) { } public Castle.Core.Logging.ILogger Create(System.Type type, Castle.Core.Logging.LoggerLevel level) { } public Castle.Core.Logging.ILogger Create(string name, Castle.Core.Logging.LoggerLevel level) { } } - [System.Serializable] public class ConsoleLogger : Castle.Core.Logging.LevelFilteredLogger { public ConsoleLogger() { } @@ -2080,7 +2071,6 @@ public interface ILoggerFactory Castle.Core.Logging.ILogger Create(System.Type type, Castle.Core.Logging.LoggerLevel level); Castle.Core.Logging.ILogger Create(string name, Castle.Core.Logging.LoggerLevel level); } - [System.Serializable] public abstract class LevelFilteredLogger : Castle.Core.Logging.ILogger { protected LevelFilteredLogger() { } @@ -2141,12 +2131,10 @@ public void WarnFormat(System.Exception exception, string format, params object[ public void WarnFormat(System.IFormatProvider formatProvider, string format, params object[] args) { } public void WarnFormat(System.Exception exception, System.IFormatProvider formatProvider, string format, params object[] args) { } } - [System.Serializable] public class LoggerException : System.Exception { public LoggerException() { } public LoggerException(string message) { } - protected LoggerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public LoggerException(string message, System.Exception innerException) { } } public enum LoggerLevel @@ -2159,7 +2147,6 @@ public enum LoggerLevel Debug = 5, Trace = 6, } - [System.Serializable] public class NullLogFactory : Castle.Core.Logging.AbstractLoggerFactory { public NullLogFactory() { } @@ -2223,7 +2210,6 @@ public void WarnFormat(System.Exception exception, string format, params object[ public void WarnFormat(System.IFormatProvider formatProvider, string format, params object[] args) { } public void WarnFormat(System.Exception exception, System.IFormatProvider formatProvider, string format, params object[] args) { } } - [System.Serializable] public class StreamLogger : Castle.Core.Logging.LevelFilteredLogger, System.IDisposable { public StreamLogger(string name, System.IO.Stream stream) { } @@ -2236,7 +2222,6 @@ protected virtual void Dispose(bool disposing) { } protected override void Finalize() { } protected override void Log(Castle.Core.Logging.LoggerLevel loggerLevel, string loggerName, string message, System.Exception exception) { } } - [System.Serializable] public class StreamLoggerFactory : Castle.Core.Logging.AbstractLoggerFactory { public StreamLoggerFactory() { } @@ -2318,7 +2303,6 @@ public bool Accept(Castle.Core.Resource.CustomUri uri) { } public Castle.Core.Resource.IResource Create(Castle.Core.Resource.CustomUri uri) { } public Castle.Core.Resource.IResource Create(Castle.Core.Resource.CustomUri uri, string basePath) { } } - [System.Serializable] public sealed class CustomUri { public static readonly string SchemeDelimiter; @@ -2362,12 +2346,10 @@ public interface IResourceFactory Castle.Core.Resource.IResource Create(Castle.Core.Resource.CustomUri uri); Castle.Core.Resource.IResource Create(Castle.Core.Resource.CustomUri uri, string basePath); } - [System.Serializable] public class ResourceException : System.Exception { public ResourceException() { } public ResourceException(string message) { } - protected ResourceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public ResourceException(string message, System.Exception innerException) { } } public class StaticContentResource : Castle.Core.Resource.AbstractResource @@ -2447,7 +2429,6 @@ public void SetGenericMethodArguments(System.Type[] arguments) { } [System.Diagnostics.CodeAnalysis.DoesNotReturn] protected void ThrowOnNoTarget() { } } - [System.Serializable] public class AllMethodsHook : Castle.DynamicProxy.IProxyGenerationHook { protected static readonly System.Collections.Generic.ICollection SkippedTypes; @@ -2481,7 +2462,6 @@ public System.Type CreateInterfaceProxyTypeWithTarget(System.Type interfaceToPro public System.Type CreateInterfaceProxyTypeWithTargetInterface(System.Type interfaceToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public System.Type CreateInterfaceProxyTypeWithoutTarget(System.Type interfaceToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } } - [System.Serializable] public sealed class DynamicProxyException : System.Exception { } public interface IChangeProxyTarget { @@ -2622,7 +2602,6 @@ public ModuleScope(bool savePhysicalAssembly, bool disableSignedModule, string s public string StrongNamedModuleName { get; } public string? WeakNamedModuleDirectory { get; } public string WeakNamedModuleName { get; } - public void LoadAssemblyIntoCache(System.Reflection.Assembly assembly) { } public string? SaveAssembly() { } public string? SaveAssembly(bool strongNamed) { } public static byte[] GetKeyPair() { } @@ -2632,8 +2611,7 @@ public class PersistentProxyBuilder : Castle.DynamicProxy.DefaultProxyBuilder public PersistentProxyBuilder() { } public string? SaveAssembly() { } } - [System.Serializable] - public class ProxyGenerationOptions : System.Runtime.Serialization.ISerializable + public class ProxyGenerationOptions { public static readonly Castle.DynamicProxy.ProxyGenerationOptions Default; public ProxyGenerationOptions() { } @@ -2649,7 +2627,6 @@ public void AddDelegateTypeMixin(System.Type delegateType) { } public void AddMixinInstance(object instance) { } public override bool Equals(object? obj) { } public override int GetHashCode() { } - public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public void Initialize() { } public object[] MixinsAsArray() { } } @@ -2738,7 +2715,6 @@ public static bool IsAccessible(System.Reflection.MethodBase method, [System.Dia public static bool IsProxy(object? instance) { } public static bool IsProxyType(System.Type type) { } } - [System.Serializable] public class StandardInterceptor : Castle.DynamicProxy.IInterceptor { public StandardInterceptor() { } @@ -2783,13 +2759,11 @@ protected InheritanceInvocation(System.Type targetType, object proxy, Castle.Dyn public override System.Type TargetType { get; } protected abstract override void InvokeMethodOnTarget() { } } - [System.Serializable] public sealed class InheritanceInvocationWithoutTarget : Castle.DynamicProxy.Internal.InheritanceInvocation { public InheritanceInvocationWithoutTarget(System.Type targetType, object proxy, Castle.DynamicProxy.IInterceptor[] interceptors, System.Reflection.MethodInfo proxiedMethod, object[] arguments) { } protected override void InvokeMethodOnTarget() { } } - [System.Serializable] public sealed class InterfaceMethodWithoutTargetInvocation : Castle.DynamicProxy.AbstractInvocation { public InterfaceMethodWithoutTargetInvocation(object? target, object proxy, Castle.DynamicProxy.IInterceptor[] interceptors, System.Reflection.MethodInfo proxiedMethod, object?[] arguments) { } @@ -2804,29 +2778,4 @@ public static System.Type[] GetAllInterfaces(this System.Type type) { } public static System.Type? GetTypeOrNull(object? target) { } public static System.Reflection.MemberInfo[] Sort(System.Reflection.MemberInfo[] members) { } } -} -namespace Castle.DynamicProxy.Serialization -{ - [System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false)] - [System.CLSCompliant(false)] - public class CacheMappingsAttribute : System.Attribute - { - public CacheMappingsAttribute(byte[] serializedCacheMappings) { } - public byte[] SerializedCacheMappings { get; } - } - [System.Serializable] - public class ProxyObjectReference : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.IObjectReference, System.Runtime.Serialization.ISerializable - { - protected ProxyObjectReference(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public static Castle.DynamicProxy.ModuleScope ModuleScope { get; } - public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public object GetRealObject(System.Runtime.Serialization.StreamingContext context) { } - protected void InvokeCallback(object target) { } - public void OnDeserialization(object sender) { } - public object RecreateClassProxy() { } - public object RecreateInterfaceProxy(string generatorType) { } - protected virtual object RecreateProxy() { } - public static void ResetScope() { } - public static void SetScope(Castle.DynamicProxy.ModuleScope scope) { } - } } \ No newline at end of file diff --git a/ref/Castle.Services.Logging.EventLogIntegration-net462.cs b/ref/Castle.Services.Logging.EventLogIntegration-net462.cs index 2fe30146fe..e200373824 100644 --- a/ref/Castle.Services.Logging.EventLogIntegration-net462.cs +++ b/ref/Castle.Services.Logging.EventLogIntegration-net462.cs @@ -2,7 +2,6 @@ [assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName=".NET Framework 4.6.2")] namespace Castle.Services.Logging.EventLogIntegration { - [System.Serializable] public class DiagnosticsLogger : Castle.Core.Logging.LevelFilteredLogger, System.IDisposable { public DiagnosticsLogger(string logName) { } @@ -14,7 +13,6 @@ protected virtual void Dispose(bool disposing) { } protected override void Finalize() { } protected override void Log(Castle.Core.Logging.LoggerLevel loggerLevel, string loggerName, string message, System.Exception exception) { } } - [System.Serializable] public class DiagnosticsLoggerFactory : Castle.Core.Logging.AbstractLoggerFactory { public DiagnosticsLoggerFactory() { } diff --git a/ref/Castle.Services.Logging.SerilogIntegration-net462.cs b/ref/Castle.Services.Logging.SerilogIntegration-net462.cs index 3c486e2336..c194307cc2 100644 --- a/ref/Castle.Services.Logging.SerilogIntegration-net462.cs +++ b/ref/Castle.Services.Logging.SerilogIntegration-net462.cs @@ -9,7 +9,6 @@ public SerilogFactory(Serilog.ILogger logger) { } public override Castle.Core.Logging.ILogger Create(string name) { } public override Castle.Core.Logging.ILogger Create(string name, Castle.Core.Logging.LoggerLevel level) { } } - [System.Serializable] public class SerilogLogger : Castle.Core.Logging.ILogger { public SerilogLogger(Serilog.ILogger logger, Castle.Services.Logging.SerilogIntegration.SerilogFactory factory) { } diff --git a/ref/Castle.Services.Logging.log4netIntegration-net462.cs b/ref/Castle.Services.Logging.log4netIntegration-net462.cs index bbcf0afa53..bd331576d6 100644 --- a/ref/Castle.Services.Logging.log4netIntegration-net462.cs +++ b/ref/Castle.Services.Logging.log4netIntegration-net462.cs @@ -38,7 +38,6 @@ public Log4netFactory(string configFile) { } public override Castle.Core.Logging.ILogger Create(string name) { } public override Castle.Core.Logging.ILogger Create(string name, Castle.Core.Logging.LoggerLevel level) { } } - [System.Serializable] public class Log4netLogger : Castle.Core.Logging.ILogger { public Log4netLogger(log4net.Core.ILogger logger, Castle.Services.Logging.Log4netIntegration.Log4netFactory factory) { } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/BugsReported/DynProxy159.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/BugsReported/DynProxy159.cs deleted file mode 100644 index 0c9e385fdd..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/BugsReported/DynProxy159.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.BugsReported -{ - using System; - using System.IO; - using System.Reflection; - using System.Runtime.Serialization; - using System.Runtime.Serialization.Formatters.Binary; - - using Castle.DynamicProxy.Tests; - - using NUnit.Framework; - - [TestFixture] - public class DynProxy159 : BasePEVerifyTestCase - { - // this test will only fail the first time it is run in a given VM - - private void FakeSerialize(object o) - { - using (var ms = new MemoryStream()) - { - var formatter = new BinaryFormatter(); - formatter.Serialize(ms, o); - } - } - - [Test] - public void ShouldNotChangeOrderOfSerializeableMembers() - { - var fromSystem = FormatterServices.GetSerializableMembers(typeof(MySerialClass)); - var beforeProxySerialization = new MemberInfo[fromSystem.Length]; - Array.Copy(fromSystem, beforeProxySerialization, fromSystem.Length); - fromSystem = null; - - FakeSerialize(generator.CreateClassProxy(typeof(MySerialClass))); - - fromSystem = FormatterServices.GetSerializableMembers(typeof(MySerialClass)); - - CollectionAssert.AreEquivalent(beforeProxySerialization, fromSystem); - } - - [Test] - public void ShouldSerializedMixofProxiedAndUnproxiedInstances() - { - var o = new[] - { - new MySerialClass(), - (MySerialClass)generator.CreateClassProxy(typeof(MySerialClass)), - new MySerialClass(), - }; - - o[2].yyy = 3.1415; - o[2].zzz = 100; - - FakeSerialize(o); - - Assert.AreEqual(3.1415, o[2].yyy); - Assert.AreEqual(100, o[2].zzz); - } - } - - [Serializable] - public class MySerialClass - { - public string xxx { get; set; } - public double? yyy { get; set; } - public int? zzz { get; set; } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs index 9a0f56af72..2d50087c16 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassOverridingEqualsAndGetHashCode { private Guid _id; diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithExplicitInterface.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithExplicitInterface.cs index 2f9c76b9e7..8bc81291c5 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithExplicitInterface.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithExplicitInterface.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Classes { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassWithExplicitInterface : ISimpleInterface { int ISimpleInterface.Do() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithInterface.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithInterface.cs index 78d0c0d1c4..83810047ea 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithInterface.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithInterface.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Classes { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassWithInterface : ISimpleInterface { public int Do() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/HasNonInheritableAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/HasNonInheritableAttribute.cs index 971e79a180..4f05c123cd 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/HasNonInheritableAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/HasNonInheritableAttribute.cs @@ -60,9 +60,6 @@ public virtual void Do2() } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = false)] public class ComplexNonInheritableAttribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/InheritableAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/InheritableAttribute.cs index 5ce6488cb3..f1471fee95 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/InheritableAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/InheritableAttribute.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = true)] public class InheritableAttribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/MySerializableClass.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/MySerializableClass.cs index 7dce2c4b9c..bc332461cb 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/MySerializableClass.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/MySerializableClass.cs @@ -15,12 +15,7 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - using System.Runtime.Serialization; -#endif -#if FEATURE_SERIALIZATION - [Serializable] -#endif + public class MySerializableClass { protected DateTime current; @@ -40,24 +35,4 @@ public virtual double CalculateSumDistanceNow() return Math.PI; } } - -#if FEATURE_SERIALIZATION - [Serializable] - public class MySerializableClass2 : MySerializableClass, ISerializable - { - public MySerializableClass2() - { - } - - public MySerializableClass2(SerializationInfo info, StreamingContext context) - { - current = (DateTime) info.GetValue("dt", typeof (DateTime)); - } - - public virtual void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("dt", current); - } - } -#endif } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NestedNonInheritableAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NestedNonInheritableAttribute.cs index a0ebf7e238..717e90e5bb 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NestedNonInheritableAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NestedNonInheritableAttribute.cs @@ -18,12 +18,9 @@ namespace Castle.DynamicProxy.Tests.Classes public partial class Nested { -#if FEATURE_SERIALIZATION - [Serializable] -#endif - [AttributeUsage(AttributeTargets.All, Inherited = false)] - public class NonInheritableAttribute : Attribute - { - } + [AttributeUsage(AttributeTargets.All, Inherited = false)] + public class NonInheritableAttribute : Attribute + { + } } } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttribute.cs index 8ea6b829cd..53c6ac0e01 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttribute.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = false)] public class NonInheritableAttribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttributeWithPositionalArrayParameterAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttributeWithPositionalArrayParameterAttribute.cs index 2c937b1670..106840f263 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttributeWithPositionalArrayParameterAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableAttributeWithPositionalArrayParameterAttribute.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = false)] public class NonInheritableAttributeWithPositionalArrayParameterAttribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArray2Attribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArray2Attribute.cs index bc00ed1389..56f4e44ad0 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArray2Attribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArray2Attribute.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = false)] public class NonInheritableWithArray2Attribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArrayAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArrayAttribute.cs index c32ec3a008..d3cceafeaa 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArrayAttribute.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/NonInheritableWithArrayAttribute.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Classes { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [AttributeUsage(AttributeTargets.All, Inherited = false)] public class NonInheritableWithArrayAttribute : Attribute { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/CrossAppDomainCaller.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/CrossAppDomainCaller.cs index a824b262e4..dc334e5184 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/CrossAppDomainCaller.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/CrossAppDomainCaller.cs @@ -18,9 +18,6 @@ namespace Castle.DynamicProxy.Tests { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class CrossAppDomainCaller { public static void RunInOtherAppDomain(Action callback, params object[] args) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/DictionarySerializationTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/DictionarySerializationTestCase.cs deleted file mode 100644 index 517f151eda..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/DictionarySerializationTestCase.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Runtime.Serialization.Formatters.Binary; - - using Castle.DynamicProxy.Tests.Classes; - - using NUnit.Framework; - - [TestFixture] - public class DictionarySerializationTestCase - { - [Test] - public void NullReferenceProxyDeserializationTest() - { - ProxyGenerator generator = new ProxyGenerator(); - Dictionary theInstances = - new Dictionary(); - ClassOverridingEqualsAndGetHashCode c = - (ClassOverridingEqualsAndGetHashCode)generator.CreateClassProxy(typeof(ClassOverridingEqualsAndGetHashCode)); - c.Id = Guid.NewGuid(); - c.Name = DateTime.Now.ToString("yyyyMMddHHmmss"); - theInstances.Add(c, c.Name); - Dictionary theInstancesBis = - SerializeAndDeserialize>(theInstances); - - Assert.IsNotNull(theInstancesBis); - Assert.AreEqual(theInstances.Count, theInstancesBis.Count); - } - - [Test] - public void DictionaryDeserializationWithoutProxyTest() - { - Dictionary theInstances = - new Dictionary(); - - for (int i = 0; i < 50; i++) - { - ClassOverridingEqualsAndGetHashCode c = new ClassOverridingEqualsAndGetHashCode(); - c.Id = Guid.NewGuid(); - c.Name = DateTime.Now.ToString("yyyyMMddHHmmss"); - theInstances.Add(c, c.Name); - } - -#pragma warning disable 219 - Dictionary theInstancesBis = - SerializeAndDeserialize>(theInstances); -#pragma warning restore 219 - } - - [Test] - public void DictionaryDeserializationWithProxyTest() - { - ProxyGenerator generator = new ProxyGenerator(); - Dictionary theInstances = - new Dictionary(); - - for (int i = 0; i < 50; i++) - { - ClassOverridingEqualsAndGetHashCode c = - (ClassOverridingEqualsAndGetHashCode)generator.CreateClassProxy(typeof(ClassOverridingEqualsAndGetHashCode)); - c.Id = Guid.NewGuid(); - c.Name = DateTime.Now.ToString("yyyyMMddHHmmss"); - theInstances.Add(c, c.Name); - } - -#pragma warning disable 219 - Dictionary theInstancesBis = - SerializeAndDeserialize>(theInstances); -#pragma warning restore 219 - } - - [Test] - public void BasicSerializationProxyTest() - { - ProxyGenerator generator = new ProxyGenerator(); - ClassOverridingEqualsAndGetHashCode c = - (ClassOverridingEqualsAndGetHashCode)generator.CreateClassProxy(typeof(ClassOverridingEqualsAndGetHashCode)); - c.Id = Guid.NewGuid(); - c.Name = DateTime.Now.ToString("yyyyMMddHHmmss"); - - ClassOverridingEqualsAndGetHashCode c2 = SerializeAndDeserialize(c); - Assert.IsNotNull(c2); - Assert.AreEqual(c.Id, c2.Id); - Assert.AreEqual(c.Name, c2.Name); - } - - public static T SerializeAndDeserialize(T proxy) - { - MemoryStream stream = new MemoryStream(); - BinaryFormatter formatter = new BinaryFormatter(); - formatter.Serialize(stream, proxy); - stream.Position = 0; - return (T) formatter.Deserialize(stream); - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Explicit/SimpleInterfaceExplicit.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Explicit/SimpleInterfaceExplicit.cs index e9fe0bf79a..f1867875bd 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Explicit/SimpleInterfaceExplicit.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Explicit/SimpleInterfaceExplicit.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Explicit { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class SimpleInterfaceExplicit : ISimpleInterface { int ISimpleInterface.Do() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/GenerationHookTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/GenerationHookTestCase.cs index e45103f30d..d030d075dd 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/GenerationHookTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/GenerationHookTestCase.cs @@ -149,9 +149,6 @@ public void Hook_can_see_ToString_method() } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class LogHook : IProxyGenerationHook { private readonly Type targetTypeToAssert; diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/AlwaysThrowsServiceImpl.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/AlwaysThrowsServiceImpl.cs index b7d4f8e0c6..4366e25cdc 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/AlwaysThrowsServiceImpl.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/AlwaysThrowsServiceImpl.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.InterClasses { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class AlwaysThrowsServiceImpl : IService { public int Sum(int b1, int b2) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ClassWithMarkerInterface.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ClassWithMarkerInterface.cs index 1b539aa8c2..ee86be2193 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ClassWithMarkerInterface.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ClassWithMarkerInterface.cs @@ -14,15 +14,10 @@ namespace Castle.DynamicProxy.Tests.Classes { - using System; - public interface IMarkerInterface { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassWithMarkerInterface { } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/IMyInterface2.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/IMyInterface2.cs index 6c8a147108..732083de16 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/IMyInterface2.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/IMyInterface2.cs @@ -27,9 +27,6 @@ public interface IMyInterface2 int Calc(int x, int y, int z, Single k); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif [MyAttribute("MyInterfaceImpl")] public class MyInterfaceImpl : IMyInterface2 { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ServiceImpl.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ServiceImpl.cs index c92751ed59..64faade247 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ServiceImpl.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/ServiceImpl.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.InterClasses { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ServiceImpl : IService, IExtendedService { public int Sum(int b1, int b2) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/Two.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/Two.cs index ba4b8f1ffc..de5ca63834 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/Two.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/Two.cs @@ -14,13 +14,8 @@ namespace Castle.DynamicProxy.Tests.InterClasses { - using System; - using Castle.DynamicProxy.Tests.Interfaces; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Two : ITwo { public int TwoMethod() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/WithRefOut.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/WithRefOut.cs index c7fd1a73e0..ddcf501472 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/WithRefOut.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterClasses/WithRefOut.cs @@ -14,13 +14,8 @@ namespace Castle.DynamicProxy.Tests.InterClasses { - using System; - using Castle.DynamicProxy.Tests.Interfaces; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class WithRefOut : IWithRefOut { public void Do(out int i) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTargetTypeTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTargetTypeTestCase.cs index c90653547b..fc24114ca0 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTargetTypeTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTargetTypeTestCase.cs @@ -155,9 +155,6 @@ public override void Method() } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public sealed class InterceptorSelector : IInterceptorSelector { public Type ReceivedType { get; private set; } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTestCase.cs index 71ef4a56b5..fc0dd54851 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/InterceptorSelectorTestCase.cs @@ -17,11 +17,7 @@ namespace Castle.DynamicProxy.Tests using System; using System.Collections.Generic; using System.Reflection; -#if FEATURE_SERIALIZATION - using System.Xml.Serialization; -#endif - using Castle.DynamicProxy.Generators; using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tests.Classes; using Castle.DynamicProxy.Tests.InterClasses; @@ -342,9 +338,6 @@ public interface IMultiGenericInterface T2 Method(T1 p); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class GenericClass : IGenericInterface { #region IGenericInterface Members @@ -375,9 +368,6 @@ public int Age } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif internal class TypeInterceptorSelector : IInterceptorSelector where TInterceptor : IInterceptor { #region IInterceptorSelector Members @@ -398,9 +388,6 @@ public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IIntercep #endregion } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class AllInterceptorSelector : IInterceptorSelector { #region IInterceptorSelector Members @@ -413,9 +400,6 @@ public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IIntercep #endregion } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class SelectorWithState : IInterceptorSelector { private readonly int state; @@ -458,9 +442,6 @@ protected bool Equals(SelectorWithState other) } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class SimpleClass : ISimpleInterface { #region ISimpleInterface Members @@ -484,22 +465,12 @@ public class FakeProxy public static ProxyGenerationOptions proxyGenerationOptions; public static MethodInfo token_Do; -#if FEATURE_SERIALIZATION - [XmlIgnore] -#endif public IInterceptor[] __interceptors; public IInterceptorSelector __selector; -#if FEATURE_SERIALIZATION - [XmlIgnore] -#endif public SimpleClass __target; -#if FEATURE_SERIALIZATION - [NonSerialized] - [XmlIgnore] -#endif public IInterceptor[] interceptors_Do; public virtual int Do() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/AddTwoInterceptor.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/AddTwoInterceptor.cs index 6af31f8bc8..331304dff0 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/AddTwoInterceptor.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/AddTwoInterceptor.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Interceptors { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class AddTwoInterceptor : IInterceptor { #region IInterceptor Members diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/CallCountingInterceptor.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/CallCountingInterceptor.cs index 1ffe032097..2ce2eb75ee 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/CallCountingInterceptor.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interceptors/CallCountingInterceptor.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Interceptors { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class CallCountingInterceptor : IInterceptor { private int count; diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IEmpty.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IEmpty.cs index b2e684aa24..d98ee484f3 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IEmpty.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IEmpty.cs @@ -14,15 +14,10 @@ namespace Castle.DynamicProxy.Tests.Interfaces { - using System; - public interface IEmpty { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Empty : IEmpty { } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IGenericWithRefOut.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IGenericWithRefOut.cs index 6e612f0acb..736ec616a4 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IGenericWithRefOut.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IGenericWithRefOut.cs @@ -14,17 +14,12 @@ namespace Castle.DynamicProxy.Tests.Interfaces { - using System; - public interface IGenericWithRefOut { void Do(out T i); void Did(ref T i); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class GenericWithRefOut : IGenericWithRefOut { public void Do(out T i) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/MixinTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/MixinTestCase.cs index 9f2c97d25e..917c6ee599 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/MixinTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/MixinTestCase.cs @@ -52,9 +52,6 @@ public interface IMyInterface int Calc(int x, int y, int z, Single k); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class MyInterfaceImpl : IMyInterface { private string _name; diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingIDerivedSImpleMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingIDerivedSImpleMixin.cs index aee5b30795..1c7a8a2238 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingIDerivedSImpleMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingIDerivedSImpleMixin.cs @@ -14,11 +14,6 @@ namespace Castle.DynamicProxy.Tests.Mixins { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassImplementingIDerivedSimpleMixin : IDerivedSimpleMixin { public int DoSomething() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingISimpleMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingISimpleMixin.cs index 8e02763110..e6dc9fbaea 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingISimpleMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ClassImplementingISimpleMixin.cs @@ -16,9 +16,6 @@ namespace Castle.DynamicProxy.Tests.Mixins { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassImplementingISimpleMixin : ISimpleMixin { public int DoSomething() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ComplexMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ComplexMixin.cs index 582f4d59dd..0e29d456b7 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ComplexMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ComplexMixin.cs @@ -31,9 +31,6 @@ public interface IThird : ISecond void DoThird(); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ComplexMixin : IThird { public ComplexMixin() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ConstructorArgumentsOrderWithMixinsTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ConstructorArgumentsOrderWithMixinsTestCase.cs index 2eee9416ce..9a3ab71bce 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ConstructorArgumentsOrderWithMixinsTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/ConstructorArgumentsOrderWithMixinsTestCase.cs @@ -39,9 +39,6 @@ public interface IFoo1 { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Foo : IFoo1 { } @@ -50,9 +47,6 @@ public interface IFoo2 { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Bar : IFoo2 { } @@ -61,9 +55,6 @@ public interface IFoo3 { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Baz : IFoo3 { } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/OtherMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/OtherMixin.cs index ea73f8b475..8b6400d9f7 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/OtherMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/OtherMixin.cs @@ -17,9 +17,6 @@ public interface IOtherMixin int Sum(int x, int y); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class OtherMixin : IOtherMixin { public OtherMixin() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SimpleMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SimpleMixin.cs index eddfed700a..280d11f6f3 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SimpleMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SimpleMixin.cs @@ -21,9 +21,6 @@ public interface ISimpleMixin int DoSomething(); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class SimpleMixin : ISimpleMixin { public SimpleMixin() diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SortingIssueOnMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SortingIssueOnMixin.cs index fa77a2bcaa..900ac2b317 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SortingIssueOnMixin.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Mixins/SortingIssueOnMixin.cs @@ -25,17 +25,11 @@ public interface IDomainsAs void DoSomethingElse(); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class DomainWithMixin : IDomainWithMixin { public void DoSomething() { } } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class DomainsAs : IDomainsAs { public void DoSomethingElse() { } diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/ModuleScopeTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/ModuleScopeTestCase.cs index 00c0784f9a..ebd8d4649a 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/ModuleScopeTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/ModuleScopeTestCase.cs @@ -17,9 +17,7 @@ namespace Castle.DynamicProxy.Tests using System; using System.IO; using System.Reflection; - using Castle.DynamicProxy.Generators; - using Castle.DynamicProxy.Serialization; - using Castle.DynamicProxy.Tests.InterClasses; + using NUnit.Framework; [TestFixture] @@ -272,54 +270,6 @@ public void ExplicitSaveThrowsWhenSpecifiedAssemblyNotGeneratedStrongName() } #endif -#if FEATURE_SERIALIZATION - [Test] - public void SavedAssemblyHasCacheMappings() - { - var scope = new ModuleScope(true); - scope.ObtainDynamicModuleWithWeakName(); - - var savedPath = scope.SaveAssembly(); - - CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) - { - var assembly = Assembly.LoadFrom((string) args[0]); - Assert.IsTrue(assembly.IsDefined(typeof (CacheMappingsAttribute), false)); - }, - savedPath); - - File.Delete(savedPath); - } - - [Test] - public void CacheMappingsHoldTypes() - { - var scope = new ModuleScope(true); - var builder = new DefaultProxyBuilder(scope); - var cp = builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, ProxyGenerationOptions.Default); - - var savedPath = scope.SaveAssembly(); - - CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) - { - var assembly = Assembly.LoadFrom((string) args[0]); - var attribute = - (CacheMappingsAttribute) - assembly.GetCustomAttributes(typeof (CacheMappingsAttribute), false)[0]; - var entries = attribute.GetDeserializedMappings(); - Assert.AreEqual(1, entries.Count); - - var key = new CacheKey(typeof (object), new Type[0], - ProxyGenerationOptions.Default); - Assert.IsTrue(entries.ContainsKey(key)); - Assert.AreEqual(args[1], entries[key]); - }, - savedPath, cp.FullName); - - File.Delete(savedPath); - } -#endif - [Test] public void GeneratedAssembliesDefaultName() { @@ -382,129 +332,5 @@ public void DefaultProxyBuilderWithSpecificScope() var builder = new DefaultProxyBuilder(scope); Assert.AreSame(scope, builder.ModuleScope); } - -#if FEATURE_SERIALIZATION - [Test] - public void LoadAssemblyIntoCache_InvalidAssembly() - { - var newScope = new ModuleScope(false); - - Assert.Throws(() => - newScope.LoadAssemblyIntoCache(Assembly.GetExecutingAssembly()) - ); - } - - [Test] - public void LoadAssemblyIntoCache_CreateClassProxy() - { - CheckLoadAssemblyIntoCache( - builder => builder.CreateClassProxyType(typeof (object), null, ProxyGenerationOptions.Default)); - } - - [Test] - public void LoadAssemblyIntoCache_CreateInterfaceProxyTypeWithoutTarget() - { - CheckLoadAssemblyIntoCache( - delegate(IProxyBuilder builder) - { - return builder.CreateInterfaceProxyTypeWithoutTarget(typeof (IServiceProvider), new Type[0], - ProxyGenerationOptions.Default); - }); - } - - [Test] - public void LoadAssemblyIntoCache_CreateInterfaceProxyTypeWithTarget() - { - CheckLoadAssemblyIntoCache( - delegate(IProxyBuilder builder) - { - return builder.CreateInterfaceProxyTypeWithTarget(typeof (IMyInterface2), new Type[0], typeof (MyInterfaceImpl), - ProxyGenerationOptions.Default); - }); - } - - [Test] - public void LoadAssemblyIntoCache_CreateInterfaceProxyTypeWithTargetInterface() - { - CheckLoadAssemblyIntoCache( - delegate(IProxyBuilder builder) - { - return builder.CreateInterfaceProxyTypeWithTargetInterface(typeof (IMyInterface2), null, - ProxyGenerationOptions.Default); - }); - } - - [Test] - public void LoadAssemblyIntoCache_DifferentGenerationOptions() - { - var savedScope = new ModuleScope(true); - var builder = new DefaultProxyBuilder(savedScope); - - var options1 = new ProxyGenerationOptions(); - options1.AddMixinInstance(new DateTime()); - var options2 = ProxyGenerationOptions.Default; - - var cp1 = builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options1); - var cp2 = builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options2); - Assert.AreNotSame(cp1, cp2); - Assert.AreSame(cp1, builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options1)); - Assert.AreSame(cp2, builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options2)); - - var path = savedScope.SaveAssembly(); - - CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) - { - var newScope = new ModuleScope(false); - var newBuilder = new DefaultProxyBuilder(newScope); - - var assembly = Assembly.LoadFrom((string) args[0]); - newScope.LoadAssemblyIntoCache(assembly); - - var newOptions1 = new ProxyGenerationOptions(); - newOptions1.AddMixinInstance(new DateTime()); - var newOptions2 = ProxyGenerationOptions.Default; - - var loadedCP1 = newBuilder.CreateClassProxyType(typeof (object), - Type.EmptyTypes, - newOptions1); - var loadedCP2 = newBuilder.CreateClassProxyType(typeof (object), - Type.EmptyTypes, - newOptions2); - Assert.AreNotSame(loadedCP1, loadedCP2); - Assert.AreEqual(assembly, loadedCP1.Assembly); - Assert.AreEqual(assembly, loadedCP2.Assembly); - }, path); - - File.Delete(path); - } - - private delegate Type ProxyCreator(IProxyBuilder proxyBuilder); - - private void CheckLoadAssemblyIntoCache(ProxyCreator creator) - { - var savedScope = new ModuleScope(true); - var builder = new DefaultProxyBuilder(savedScope); - - var cp = creator(builder); - Assert.AreSame(cp, creator(builder)); - - var path = savedScope.SaveAssembly(); - - CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) - { - var newScope = new ModuleScope(false); - var newBuilder = new DefaultProxyBuilder(newScope); - - var assembly = Assembly.LoadFrom((string) args[0]); - newScope.LoadAssemblyIntoCache(assembly); - - var loadedCP = assembly.GetType((string) args[1]); - Assert.AreSame(loadedCP, ((ProxyCreator) args[2])(newBuilder)); - Assert.AreEqual(assembly, ((ProxyCreator) args[2])(newBuilder).Assembly); - }, path, cp.FullName, creator); - - File.Delete(path); - } -#endif } } \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/MultipleSavedAssembliesTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/MultipleSavedAssembliesTestCase.cs deleted file mode 100644 index 7627dc9020..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/MultipleSavedAssembliesTestCase.cs +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests -{ - using System.Reflection; - - using Castle.DynamicProxy.Tests.Classes; - using Castle.DynamicProxy.Tests.Interceptors; - - using NUnit.Framework; - - public interface IGenericInterface - { - void GenericMethod(T toto); - } - - public class Class1 : IGenericInterface - { - public void GenericMethod(IInterface1 toto) - { - } - } - - public class Class2 : IGenericInterface - { - public void GenericMethod(IInterface2 toto) - { - } - } - - public class Class3 : IInterface3, IInterface2 - { - } - - public class Class4 : IInterface3, IInterface1 - { - } - - public interface IInterface1 - { - } - - public interface IInterface2 - { - } - - public interface IInterface3 - { - } - - [TestFixture] - public class MultipleSavedAssembliesTestCase - { - [Test] - [Bug("DYNPROXY-179")] - public void LoadAssemblyIntoCache_InvalidCacheAfterTwoLoadAssemblyIntoCacheThatContainsSameClass() - { - // - // Step 1 - Save an assembly with 1 class proxy - // - var proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "5", "ProxyCache5.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "5", "ProxyCache5.dll"); - var proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - var generator = new ProxyGenerator(proxyBuilder); - generator.CreateClassProxy(typeof(EmptyClass), new[] { typeof(IInterface1) }, new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 2 - Save another assembly with 1 class proxy - // note : to reproduce the problem, must load previously saved assembly (in cache) before saving this assembly. - // - proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "6", "ProxyCache6.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "6", "ProxyCache6.dll"); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - var proxyAssembly = Assembly.LoadFrom("ProxyCache5.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - generator.CreateClassProxy(typeof(EmptyClass), new[] { typeof(IInterface2) }, new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 3 - Load the last proxy assembly and try to create the first class proxy (created in step 1) - // note : Creating proxy from step 2 works. - // issue : returns the wrong proxy (the one from step 2) - // - proxyGeneratorModuleScope = new ModuleScope(true); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - proxyAssembly = Assembly.LoadFrom("ProxyCache6.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - var invalidProxy = generator.CreateClassProxy(typeof(EmptyClass), new[] { typeof(IInterface1) }, new DoNothingInterceptor()); - if (invalidProxy as IInterface1 == null) - { - Assert.Fail(); - } - } - - [Test] - [Bug("DYNPROXY-179")] - public void LoadAssemblyIntoCache_InvalidCacheAfterTwoLoadAssemblyIntoCacheThatContainsSameGeneric() - { - // - // Step 1 - Save an assembly with 1 generic proxy - // - var proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "1", "ProxyCache1.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "1", "ProxyCache1.dll"); - var proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - var generator = new ProxyGenerator(proxyBuilder); - generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface), new Class1(), new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 2 - Save another assembly with 1 generic proxy - // note : to reproduce the problem, must load previously saved assembly (in cache) before saving this assembly. - // - proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "2", "ProxyCache2.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "2", "ProxyCache2.dll"); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - var proxyAssembly = Assembly.LoadFrom("ProxyCache1.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface), new Class2(), new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 3 - Load the last proxy assembly and try to create the first generic proxy (created in step 1) - // note : Creating proxy from step 2 works. - // exception : Missing method exception, it returns the wrong proxy and the constructor used doesn't match the arguments passed. - // - proxyGeneratorModuleScope = new ModuleScope(true); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - proxyAssembly = Assembly.LoadFrom("ProxyCache2.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface), new Class1(), new DoNothingInterceptor()); - } - - [Test] - [Bug("DYNPROXY-179")] - public void LoadAssemblyIntoCache_InvalidCacheAfterTwoLoadAssemblyIntoCacheThatContainsSameInterface() - { - // - // Step 1 - Save an assembly with 1 interface proxy - // - var proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "3", "ProxyCache3.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "3", "ProxyCache3.dll"); - var proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - var generator = new ProxyGenerator(proxyBuilder); - generator.CreateInterfaceProxyWithTargetInterface(typeof(IInterface3), new[] { typeof(IInterface2) }, new Class3(), new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 2 - Save another assembly with 1 interface proxy - // note : to reproduce the problem, must load previously saved assembly (in cache) before saving this assembly. - // - proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "4", "ProxyCache4.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "4", "ProxyCache4.dll"); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - var proxyAssembly = Assembly.LoadFrom("ProxyCache3.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - generator.CreateInterfaceProxyWithTargetInterface(typeof(IInterface3), new[] { typeof(IInterface1) }, new Class4(), new DoNothingInterceptor()); - proxyGeneratorModuleScope.SaveAssembly(); - - // - // Step 3 - Load the last proxy assembly and try to create the first interface proxy (created in step 1) - // note : Creating proxy from step 2 works. - // issue : returns the wrong proxy (the one from step 2) - // - proxyGeneratorModuleScope = new ModuleScope(true); - proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); - generator = new ProxyGenerator(proxyBuilder); - - proxyAssembly = Assembly.LoadFrom("ProxyCache4.dll"); - proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); - - var invalidProxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IInterface3), new[] { typeof(IInterface2) }, new Class3(), new DoNothingInterceptor()); - if (invalidProxy as IInterface2 == null) - { - Assert.Fail(); - } - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/OutRefParamsTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/OutRefParamsTestCase.cs index 39b6b1be34..d86650d4b1 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/OutRefParamsTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/OutRefParamsTestCase.cs @@ -29,9 +29,6 @@ public interface IClassHasMethodThrowException int MethodWithRefParam(ref int refParam, out string outParam); } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ClassHasMethodThrowException : IClassHasMethodThrowException { public virtual int MethodWithRefParam(ref int refParam, out string outParam) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyNothingHook.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyNothingHook.cs index c6df7bcacd..46efbecfaa 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyNothingHook.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyNothingHook.cs @@ -17,9 +17,6 @@ namespace Castle.DynamicProxy.Tests using System; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ProxyNothingHook : IProxyGenerationHook { public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxySomeMethodsHook.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxySomeMethodsHook.cs index 63c5fe77a0..5e758720b7 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxySomeMethodsHook.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxySomeMethodsHook.cs @@ -17,9 +17,6 @@ namespace Castle.DynamicProxy.Tests using System; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ProxySomeMethodsHook : IProxyGenerationHook { private readonly Func shouldInterceptMethod; diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyTypeCachingWithDifferentHooksTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyTypeCachingWithDifferentHooksTestCase.cs index e12f30a977..e07e577628 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyTypeCachingWithDifferentHooksTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/ProxyTypeCachingWithDifferentHooksTestCase.cs @@ -25,14 +25,8 @@ namespace Castle.DynamicProxy.Tests [TestFixture] public class ProxyTypeCachingWithDifferentHooksTestCase : BasePEVerifyTestCase { -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class CustomHook : AllMethodsHook { } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class EquatableHook : IProxyGenerationHook, IEquatable { public override bool Equals(object obj) => Equals(obj as EquatableHook); @@ -45,9 +39,6 @@ public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo) { } public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo) => false; } -#if FEATURE_SERIALIZATION - [Serializable] -#endif public record class RecordClassHook : IProxyGenerationHook { public RecordClassHook(string id) diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/SerializableClassTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/SerializableClassTestCase.cs deleted file mode 100644 index c869686271..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/SerializableClassTestCase.cs +++ /dev/null @@ -1,626 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests -{ - using System; - using System.Collections; - using System.IO; - using System.Reflection; - using System.Runtime.Serialization; - using System.Runtime.Serialization.Formatters.Binary; - - using Castle.DynamicProxy.Serialization; - using Castle.DynamicProxy.Tests.Classes; - using Castle.DynamicProxy.Tests.BugsReported; - using Castle.DynamicProxy.Tests.InterClasses; - using Castle.DynamicProxy.Tests.Serialization; - - using NUnit.Framework; - - [TestFixture] - public class SerializableClassTestCase : BasePEVerifyTestCase - { - [Test] - public void BaseTypeForInterfaceProxy_is_honored_after_deserialization() - { - var options = new ProxyGenerationOptions - { - BaseTypeForInterfaceProxy = typeof(SimpleClass) - }; - var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IService), Type.EmptyTypes, options); - var newProxy = SerializeAndDeserialize(proxy); - Assert.AreEqual(typeof(SimpleClass), newProxy.GetType().BaseType); - } - - [Test(Description = "DYNPROXY-133")] - public void Can_proxy_class_with_explicit_GetObjectData() - { - generator.CreateClassProxy(); - } - - [Test] - public void ClassProxyWithTargetSerialization() - { - var proxy = generator.CreateClassProxyWithTarget(new MySerializableClass(), new StandardInterceptor()); - - var current = proxy.Current; - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.AreEqual(current, otherProxy.Current); - } - - [Test] - public void CreateSerializable() - { - var proxy = (MySerializableClass) - generator.CreateClassProxy(typeof(MySerializableClass), new StandardInterceptor()); - - Assert.IsTrue(proxy.GetType().IsSerializable); - } - - [Test] - public void CustomMarkerInterface() - { - var proxy = generator.CreateClassProxy(typeof(ClassWithMarkerInterface), - new[] { typeof(IMarkerInterface) }, - new StandardInterceptor()); - - Assert.IsNotNull(proxy); - Assert.IsTrue(proxy is IMarkerInterface); - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.IsTrue(otherProxy is IMarkerInterface); - } - - [Test] - public void DeserializationWithSpecificModuleScope() - { - ProxyObjectReference.SetScope(generator.ProxyBuilder.ModuleScope); - var first = generator.CreateClassProxy(new StandardInterceptor()); - var second = SerializeAndDeserialize(first); - Assert.AreSame(first.GetType(), second.GetType()); - } - - [Test] - public void HashtableSerialization() - { - var proxy = generator.CreateClassProxy( - typeof(Hashtable), new StandardInterceptor()); - - Assert.IsTrue(typeof(Hashtable).IsAssignableFrom(proxy.GetType())); - - (proxy as Hashtable).Add("key", "helloooo!"); - - var otherProxy = (Hashtable)SerializeAndDeserialize(proxy); - - Assert.IsTrue(otherProxy.ContainsKey("key")); - Assert.AreEqual("helloooo!", otherProxy["key"]); - } - - [Test] - public void ImplementsISerializable() - { - var proxy = (MySerializableClass) - generator.CreateClassProxy(typeof(MySerializableClass), new StandardInterceptor()); - - Assert.IsTrue(proxy is ISerializable); - } - - public override void Init() - { - base.Init(); - ProxyObjectReference.ResetScope(); - } - - [Test] - public void MixinFieldsSetOnDeserialization_ClassProxy() - { - var options = new ProxyGenerationOptions(); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = (MySerializableClass)generator.CreateClassProxy( - typeof(MySerializableClass), - new Type[0], - options, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)proxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)proxy).GetExecutingObject() is SerializableMixin); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.IsTrue(otherProxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)otherProxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)otherProxy).GetExecutingObject() is SerializableMixin); - } - - [Test] - public void MixinFieldsSetOnDeserialization_InterfaceProxy_WithTarget() - { - var options = new ProxyGenerationOptions(); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = (IService)generator.CreateInterfaceProxyWithTarget( - typeof(IService), - new ServiceImpl(), - options, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)proxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)proxy).GetExecutingObject() is SerializableMixin); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.IsTrue(otherProxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)otherProxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)otherProxy).GetExecutingObject() is SerializableMixin); - } - - [Test] - public void MixinFieldsSetOnDeserialization_InterfaceProxy_WithTargetInterface() - { - var options = new ProxyGenerationOptions(); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = (IService)generator.CreateInterfaceProxyWithTargetInterface( - typeof(IService), - new ServiceImpl(), - options, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)proxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)proxy).GetExecutingObject() is SerializableMixin); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.IsTrue(otherProxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)otherProxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)otherProxy).GetExecutingObject() is SerializableMixin); - } - - [Test] - public void MixinFieldsSetOnDeserialization_InterfaceProxy_WithoutTarget() - { - var options = new ProxyGenerationOptions(); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = (IService)generator.CreateInterfaceProxyWithoutTarget( - typeof(IService), - new Type[0], - options, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)proxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)proxy).GetExecutingObject() is SerializableMixin); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.IsTrue(otherProxy is IMixedInterface); - Assert.IsNotNull(((IMixedInterface)otherProxy).GetExecutingObject()); - Assert.IsTrue(((IMixedInterface)otherProxy).GetExecutingObject() is SerializableMixin); - } - - [Test] - public void MixinsAppliedOnDeserialization() - { - var options = new ProxyGenerationOptions(); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = (MySerializableClass)generator.CreateClassProxy( - typeof(MySerializableClass), - new Type[0], - options, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMixedInterface); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.IsTrue(otherProxy is IMixedInterface); - } - - [Test] - public void ProxyGenerationOptionsRespectedOnDeserialization() - { - var hook = new MethodFilterHook("(get_Current)|(GetExecutingObject)"); - var options = new ProxyGenerationOptions(hook); - options.AddMixinInstance(new SerializableMixin()); - options.Selector = new SerializableInterceptorSelector(); - - var proxy = (MySerializableClass)generator.CreateClassProxy( - typeof(MySerializableClass), - new Type[0], - options, - new StandardInterceptor()); - - Assert.AreEqual(proxy.GetType(), proxy.GetType().GetMethod("get_Current").DeclaringType); - Assert.AreNotEqual(proxy.GetType(), proxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - Assert.AreEqual(proxy.GetType().BaseType, proxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - var options2 = (ProxyGenerationOptions)proxy.GetType(). - GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return o is SerializableMixin; })); - Assert.IsNotNull(options2.Selector); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.AreEqual(otherProxy.GetType(), otherProxy.GetType().GetMethod("get_Current").DeclaringType); - Assert.AreNotEqual(otherProxy.GetType(), otherProxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - Assert.AreEqual(otherProxy.GetType().BaseType, - otherProxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - options2 = (ProxyGenerationOptions)otherProxy.GetType(). - GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return o is SerializableMixin; })); - Assert.IsNotNull(options2.Selector); - } - - [Test] - public void ProxyGenerationOptionsRespectedOnDeserializationComplex() - { - var hook = new MethodFilterHook("(get_Current)|(GetExecutingObject)"); - var options = new ProxyGenerationOptions(hook); - options.AddMixinInstance(new SerializableMixin()); - options.Selector = new SerializableInterceptorSelector(); - - var holder = new ComplexHolder(); - holder.Type = typeof(MySerializableClass); - holder.Element = generator.CreateClassProxy(typeof(MySerializableClass), new Type[0], options, - new StandardInterceptor()); - - // check holder elements - Assert.AreEqual(typeof(MySerializableClass), holder.Type); - Assert.IsNotNull(holder.Element); - Assert.IsTrue(holder.Element is MySerializableClass); - Assert.AreNotEqual(typeof(MySerializableClass), holder.Element.GetType()); - - // check whether options were applied correctly - Assert.AreEqual(holder.Element.GetType(), holder.Element.GetType().GetMethod("get_Current").DeclaringType); - Assert.AreNotEqual(holder.Element.GetType(), - holder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - Assert.AreEqual(holder.Element.GetType().BaseType, - holder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - var options2 = (ProxyGenerationOptions)holder.Element.GetType(). - GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return o is SerializableMixin; })); - Assert.IsNotNull(options2.Selector); - - var otherHolder = SerializeAndDeserialize(holder); - - // check holder elements - Assert.AreEqual(typeof(MySerializableClass), otherHolder.Type); - Assert.IsNotNull(otherHolder.Element); - Assert.IsTrue(otherHolder.Element is MySerializableClass); - Assert.AreNotEqual(typeof(MySerializableClass), otherHolder.Element.GetType()); - - // check whether options were applied correctly - Assert.AreEqual(otherHolder.Element.GetType(), otherHolder.Element.GetType().GetMethod("get_Current").DeclaringType); - Assert.AreNotEqual(otherHolder.Element.GetType(), - otherHolder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - Assert.AreEqual(otherHolder.Element.GetType().BaseType, - otherHolder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); - options2 = (ProxyGenerationOptions)otherHolder.Element.GetType(). - GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return o is SerializableMixin; })); - Assert.IsNotNull(options2.Selector); - } - - [Test] - public void ProxyKnowsItsGenerationOptions() - { - var hook = new MethodFilterHook(".*"); - var options = new ProxyGenerationOptions(hook); - options.AddMixinInstance(new SerializableMixin()); - - var proxy = generator.CreateClassProxy( - typeof(MySerializableClass), - new Type[0], - options, - new StandardInterceptor()); - - var field = proxy.GetType().GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); - Assert.IsNotNull(field); - Assert.AreSame(options, field.GetValue(proxy)); - - base.Init(); - - proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IService), new StandardInterceptor()); - field = proxy.GetType().GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); - Assert.AreSame(ProxyGenerationOptions.Default, field.GetValue(proxy)); - - base.Init(); - - proxy = generator.CreateInterfaceProxyWithTarget(typeof(IService), new ServiceImpl(), options, - new StandardInterceptor()); - field = proxy.GetType().GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); - Assert.AreSame(options, field.GetValue(proxy)); - - base.Init(); - - proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IService), new ServiceImpl(), - new StandardInterceptor()); - field = proxy.GetType().GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); - Assert.AreSame(ProxyGenerationOptions.Default, field.GetValue(proxy)); - } - - [Test] - public void ReusingModuleScopeFromProxyObjectReference() - { - var generatorWithSpecificModuleScope = - new ProxyGenerator(new DefaultProxyBuilder(ProxyObjectReference.ModuleScope)); - Assert.AreSame(generatorWithSpecificModuleScope.ProxyBuilder.ModuleScope, ProxyObjectReference.ModuleScope); - var first = - generatorWithSpecificModuleScope.CreateClassProxy(new StandardInterceptor()); - var second = SerializeAndDeserialize(first); - Assert.AreSame(first.GetType(), second.GetType()); - } - - [Test] - public void SerializatingObjectsWithoutDefaultConstructor() - { - var proxy = (C)generator.CreateClassProxy(typeof(C), new object[] { 1 }, new StandardInterceptor()); - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.AreEqual(proxy.I, otherProxy.I); - Assert.AreSame(otherProxy, otherProxy.This); - } - - [Test] - public void SerializationDelegate() - { - var proxy = (MySerializableClass2) - generator.CreateClassProxy(typeof(MySerializableClass2), new StandardInterceptor()); - - var current = proxy.Current; - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.AreEqual(current, otherProxy.Current); - } - - [Test] - public void SerializeClassWithDirectAndIndirectSelfReference() - { - var proxy = - (ClassWithDirectAndIndirectSelfReference) - generator.CreateClassProxy(typeof(ClassWithDirectAndIndirectSelfReference), - new Type[0], new StandardInterceptor()); - Assert.AreSame(proxy, proxy.This); - - var otherProxy = - SerializeAndDeserialize(proxy); - Assert.AreSame(otherProxy, otherProxy.List[0]); - Assert.AreSame(otherProxy, otherProxy.This); - } - - [Test] - public void SerializeClassWithIndirectSelfReference() - { - var proxy = - (ClassWithIndirectSelfReference)generator.CreateClassProxy(typeof(ClassWithIndirectSelfReference), - new Type[0], new StandardInterceptor()); - Assert.AreSame(proxy, proxy.List[0]); - - var otherProxy = SerializeAndDeserialize(proxy); - Assert.AreSame(otherProxy, otherProxy.List[0]); - } - - [Test] - public void SerializeObjectsWithDelegateToOtherObject() - { - var eventHandlerInstance = new EventHandlerClass(); - var proxy = - (DelegateHolder)generator.CreateClassProxy(typeof(DelegateHolder), new IInterceptor[] { new StandardInterceptor() }); - - proxy.DelegateMember = new EventHandler(eventHandlerInstance.TestHandler); - proxy.ComplexTypeMember = new ArrayList(new[] { 1, 2, 3 }); - proxy.ComplexTypeMember.Add(eventHandlerInstance); - - Assert.IsNotNull(proxy.DelegateMember); - Assert.IsNotNull(proxy.DelegateMember.Target); - - Assert.IsNotNull(proxy.ComplexTypeMember); - Assert.AreEqual(4, proxy.ComplexTypeMember.Count); - Assert.AreEqual(1, proxy.ComplexTypeMember[0]); - Assert.AreEqual(2, proxy.ComplexTypeMember[1]); - Assert.AreEqual(3, proxy.ComplexTypeMember[2]); - Assert.AreSame(proxy.ComplexTypeMember[3], proxy.DelegateMember.Target); - - var otherProxy = (SerializeAndDeserialize(proxy)); - - Assert.IsNotNull(otherProxy.DelegateMember); - Assert.IsNotNull(otherProxy.DelegateMember.Target); - - Assert.IsNotNull(otherProxy.ComplexTypeMember); - Assert.AreEqual(4, otherProxy.ComplexTypeMember.Count); - Assert.AreEqual(1, otherProxy.ComplexTypeMember[0]); - Assert.AreEqual(2, otherProxy.ComplexTypeMember[1]); - Assert.AreEqual(3, otherProxy.ComplexTypeMember[2]); - Assert.AreSame(otherProxy.ComplexTypeMember[3], otherProxy.DelegateMember.Target); - } - - [Test] - public void SerializeObjectsWithDelegateToThisObject() - { - var proxy = - (DelegateHolder)generator.CreateClassProxy(typeof(DelegateHolder), new IInterceptor[] { new StandardInterceptor() }); - - proxy.DelegateMember = new EventHandler(proxy.TestHandler); - proxy.ComplexTypeMember = new ArrayList(new[] { 1, 2, 3 }); - - Assert.IsNotNull(proxy.DelegateMember); - Assert.AreSame(proxy, proxy.DelegateMember.Target); - - Assert.IsNotNull(proxy.ComplexTypeMember); - Assert.AreEqual(3, proxy.ComplexTypeMember.Count); - Assert.AreEqual(1, proxy.ComplexTypeMember[0]); - Assert.AreEqual(2, proxy.ComplexTypeMember[1]); - Assert.AreEqual(3, proxy.ComplexTypeMember[2]); - - var otherProxy = (SerializeAndDeserialize(proxy)); - - Assert.IsNotNull(otherProxy.DelegateMember); - Assert.AreSame(otherProxy, otherProxy.DelegateMember.Target); - - Assert.IsNotNull(otherProxy.ComplexTypeMember); - Assert.AreEqual(3, otherProxy.ComplexTypeMember.Count); - Assert.AreEqual(1, otherProxy.ComplexTypeMember[0]); - Assert.AreEqual(2, otherProxy.ComplexTypeMember[1]); - Assert.AreEqual(3, otherProxy.ComplexTypeMember[2]); - } - - [Test] - public void SerializeObjectsWithIndirectDelegateToMember() - { - var proxy = (IndirectDelegateHolder)generator.CreateClassProxy(typeof(IndirectDelegateHolder), - new IInterceptor[] { new StandardInterceptor() }); - - proxy.DelegateHolder.DelegateMember = new EventHandler(proxy.DelegateHolder.TestHandler); - proxy.DelegateHolder.ComplexTypeMember = new ArrayList(new[] { 1, 2, 3 }); - - Assert.IsNotNull(proxy.DelegateHolder.DelegateMember); - Assert.AreSame(proxy.DelegateHolder, proxy.DelegateHolder.DelegateMember.Target); - - Assert.IsNotNull(proxy.DelegateHolder.ComplexTypeMember); - Assert.AreEqual(3, proxy.DelegateHolder.ComplexTypeMember.Count); - Assert.AreEqual(1, proxy.DelegateHolder.ComplexTypeMember[0]); - Assert.AreEqual(2, proxy.DelegateHolder.ComplexTypeMember[1]); - Assert.AreEqual(3, proxy.DelegateHolder.ComplexTypeMember[2]); - - var otherProxy = (SerializeAndDeserialize(proxy)); - - Assert.IsNotNull(otherProxy.DelegateHolder.DelegateMember); - Assert.AreSame(otherProxy.DelegateHolder, otherProxy.DelegateHolder.DelegateMember.Target); - - Assert.IsNotNull(otherProxy.DelegateHolder.ComplexTypeMember); - Assert.AreEqual(3, otherProxy.DelegateHolder.ComplexTypeMember.Count); - Assert.AreEqual(1, otherProxy.DelegateHolder.ComplexTypeMember[0]); - Assert.AreEqual(2, otherProxy.DelegateHolder.ComplexTypeMember[1]); - Assert.AreEqual(3, otherProxy.DelegateHolder.ComplexTypeMember[2]); - } - - [Test] - public void SerializeObjectsWithIndirectDelegateToThisObject() - { - var proxy = (IndirectDelegateHolder)generator.CreateClassProxy(typeof(IndirectDelegateHolder), - new IInterceptor[] { new StandardInterceptor() }); - - proxy.DelegateHolder.DelegateMember = new EventHandler(proxy.TestHandler); - proxy.DelegateHolder.ComplexTypeMember = new ArrayList(new[] { 1, 2, 3 }); - - Assert.IsNotNull(proxy.DelegateHolder.DelegateMember); - Assert.AreSame(proxy, proxy.DelegateHolder.DelegateMember.Target); - - Assert.IsNotNull(proxy.DelegateHolder.ComplexTypeMember); - Assert.AreEqual(3, proxy.DelegateHolder.ComplexTypeMember.Count); - Assert.AreEqual(1, proxy.DelegateHolder.ComplexTypeMember[0]); - Assert.AreEqual(2, proxy.DelegateHolder.ComplexTypeMember[1]); - Assert.AreEqual(3, proxy.DelegateHolder.ComplexTypeMember[2]); - - var otherProxy = (SerializeAndDeserialize(proxy)); - - Assert.IsNotNull(otherProxy.DelegateHolder.DelegateMember); - Assert.AreSame(otherProxy, otherProxy.DelegateHolder.DelegateMember.Target); - - Assert.IsNotNull(otherProxy.DelegateHolder.ComplexTypeMember); - Assert.AreEqual(3, otherProxy.DelegateHolder.ComplexTypeMember.Count); - Assert.AreEqual(1, otherProxy.DelegateHolder.ComplexTypeMember[0]); - Assert.AreEqual(2, otherProxy.DelegateHolder.ComplexTypeMember[1]); - Assert.AreEqual(3, otherProxy.DelegateHolder.ComplexTypeMember[2]); - } - - [Test] - public void SimpleInterfaceProxy() - { - var proxy = - generator.CreateInterfaceProxyWithTarget(typeof(IMyInterface2), new MyInterfaceImpl(), new StandardInterceptor()); - - Assert.IsTrue(proxy.GetType().IsSerializable); - - var inter = (IMyInterface2)proxy; - - inter.Name = "opa"; - Assert.AreEqual("opa", inter.Name); - inter.Started = true; - Assert.AreEqual(true, inter.Started); - - var otherProxy = (IMyInterface2)SerializeAndDeserialize(proxy); - - Assert.AreEqual(inter.Name, otherProxy.Name); - Assert.AreEqual(inter.Started, otherProxy.Started); - } - - [Test] - public void SimpleInterfaceProxy_WithoutTarget() - { - var proxy = - generator.CreateInterfaceProxyWithoutTarget(typeof(IMyInterface2), new[] { typeof(IMyInterface) }, - new StandardInterceptor()); - - Assert.IsTrue(proxy is IMyInterface2); - Assert.IsTrue(proxy is IMyInterface); - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.IsTrue(otherProxy is IMyInterface2); - Assert.IsTrue(otherProxy is IMyInterface); - } - - [Test] - public void SimpleProxySerialization() - { - var proxy = (MySerializableClass) - generator.CreateClassProxy(typeof(MySerializableClass), new StandardInterceptor()); - - var current = proxy.Current; - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.AreEqual(current, otherProxy.Current); - } - - [Test] - public void BadSerializable() - { - const int expectedValue = 13; - - var proxy = generator.CreateClassProxy(); - proxy.Value = expectedValue; - - var otherProxy = SerializeAndDeserialize(proxy); - - Assert.AreEqual(expectedValue, otherProxy.Value); - } - - public override void TearDown() - { - base.TearDown(); - ProxyObjectReference.ResetScope(); - } - - public static T SerializeAndDeserialize(T proxy) - { - using (var stream = new MemoryStream()) - { - var formatter = new BinaryFormatter(); - formatter.Serialize(stream, proxy); - stream.Position = 0; - return (T)formatter.Deserialize(stream); - } - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/BadSerializable.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/BadSerializable.cs deleted file mode 100644 index 55c1b3b332..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/BadSerializable.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Runtime.Serialization; - - [Serializable] - public abstract class BadSerializable - { - public int Value { get; set; } - - public abstract void GetObjectData(SerializationInfo info, StreamingContext context); - } -} - -#endif diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/C.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/C.cs deleted file mode 100644 index 81dabc3207..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/C.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - - [Serializable] - public class C - { - public int I; - public C This; - - public C(int i) - { - I = i; - This = this; - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithDirectAndIndirectSelfReference.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithDirectAndIndirectSelfReference.cs deleted file mode 100644 index 9ac5987698..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithDirectAndIndirectSelfReference.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Collections; - - [Serializable] - public class ClassWithDirectAndIndirectSelfReference - { - public ArrayList List = new ArrayList(); - public ClassWithDirectAndIndirectSelfReference This; - - public ClassWithDirectAndIndirectSelfReference() - { - This = this; - List.Add(this); - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithIndirectSelfReference.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithIndirectSelfReference.cs deleted file mode 100644 index 5609c08c2e..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ClassWithIndirectSelfReference.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Collections; - - [Serializable] - public class ClassWithIndirectSelfReference - { - public ArrayList List = new ArrayList(); - - public ClassWithIndirectSelfReference() - { - List.Add(this); - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ComplexHolder.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ComplexHolder.cs deleted file mode 100644 index 83e76f345e..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/ComplexHolder.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - - [Serializable] - public class ComplexHolder - { - public object Element; - public Type Type; - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/DelegateHolder.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/DelegateHolder.cs deleted file mode 100644 index 1217c6af2f..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/DelegateHolder.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Collections; - - [Serializable] - public class DelegateHolder - { - public ArrayList ComplexTypeMember; - public EventHandler DelegateMember; - - public void TestHandler(object sender, EventArgs e) - { - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/EventHandlerClass.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/EventHandlerClass.cs deleted file mode 100644 index 688940f6b2..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/EventHandlerClass.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - - [Serializable] - public class EventHandlerClass - { - public void TestHandler(object sender, EventArgs e) - { - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IMixedInterface.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IMixedInterface.cs deleted file mode 100644 index 09c428461d..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IMixedInterface.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.DynamicProxy.Tests.Serialization -{ - public interface IMixedInterface - { - object GetExecutingObject(); - } -} \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IndirectDelegateHolder.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IndirectDelegateHolder.cs deleted file mode 100644 index 7f243d08a4..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/IndirectDelegateHolder.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - - [Serializable] - public class IndirectDelegateHolder - { - public DelegateHolder DelegateHolder = new DelegateHolder(); - - public void TestHandler(object sender, EventArgs e) - { - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/MethodFilterHook.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/MethodFilterHook.cs deleted file mode 100644 index 400de3ee34..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/MethodFilterHook.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Reflection; - using System.Text.RegularExpressions; - - [Serializable] - public class MethodFilterHook : IProxyGenerationHook - { - private string nameFilter; - - public MethodFilterHook(string nameFilter) - { - this.nameFilter = nameFilter; - } - - public void MethodsInspected() - { - } - - public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo) - { - } - - public bool ShouldInterceptMethod(Type type, MethodInfo memberInfo) - { - return Regex.IsMatch(memberInfo.Name, nameFilter); - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableExplicitImpl.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableExplicitImpl.cs deleted file mode 100644 index c802e78a14..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableExplicitImpl.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Runtime.Serialization; - - [Serializable] - public class SerializableExplicitImpl : ISerializable - { - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableInterceptorSelector.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableInterceptorSelector.cs deleted file mode 100644 index 7981406596..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableInterceptorSelector.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - using System.Reflection; - - [Serializable] - public class SerializableInterceptorSelector : IInterceptorSelector - { - public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) - { - return interceptors; - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableMixin.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableMixin.cs deleted file mode 100644 index 326982a185..0000000000 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/Serialization/SerializableMixin.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tests.Serialization -{ - using System; - - [Serializable] - public class SerializableMixin : IMixedInterface - { - public object GetExecutingObject() - { - return this; - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core/Core/Configuration/AbstractConfiguration.cs b/src/Castle.Core/Core/Configuration/AbstractConfiguration.cs index d1120a4228..bfeb897552 100644 --- a/src/Castle.Core/Core/Configuration/AbstractConfiguration.cs +++ b/src/Castle.Core/Core/Configuration/AbstractConfiguration.cs @@ -26,9 +26,6 @@ namespace Castle.Core.Configuration /// AbstractConfiguration makes easier to implementers /// to create a new version of /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public abstract class AbstractConfiguration : IConfiguration { private readonly ConfigurationAttributeCollection attributes = new ConfigurationAttributeCollection(); diff --git a/src/Castle.Core/Core/Configuration/ConfigurationAttributeCollection.cs b/src/Castle.Core/Core/Configuration/ConfigurationAttributeCollection.cs index fbd8e131ea..7f609dbf35 100644 --- a/src/Castle.Core/Core/Configuration/ConfigurationAttributeCollection.cs +++ b/src/Castle.Core/Core/Configuration/ConfigurationAttributeCollection.cs @@ -14,25 +14,11 @@ namespace Castle.Core.Configuration { -#if FEATURE_SERIALIZATION - using System; - using System.Runtime.Serialization; -#endif - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ConfigurationAttributeCollection : System.Collections.Specialized.NameValueCollection { public ConfigurationAttributeCollection() { } - -#if FEATURE_SERIALIZATION - protected ConfigurationAttributeCollection(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -#endif } } \ No newline at end of file diff --git a/src/Castle.Core/Core/Configuration/ConfigurationCollection.cs b/src/Castle.Core/Core/Configuration/ConfigurationCollection.cs index 8c9b34f07c..65825d579b 100644 --- a/src/Castle.Core/Core/Configuration/ConfigurationCollection.cs +++ b/src/Castle.Core/Core/Configuration/ConfigurationCollection.cs @@ -20,9 +20,6 @@ namespace Castle.Core.Configuration /// /// A collection of objects. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ConfigurationCollection : List { /// diff --git a/src/Castle.Core/Core/Configuration/MutableConfiguration.cs b/src/Castle.Core/Core/Configuration/MutableConfiguration.cs index f21ea902a9..70407b15fd 100644 --- a/src/Castle.Core/Core/Configuration/MutableConfiguration.cs +++ b/src/Castle.Core/Core/Configuration/MutableConfiguration.cs @@ -14,11 +14,6 @@ namespace Castle.Core.Configuration { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class MutableConfiguration : AbstractConfiguration { /// diff --git a/src/Castle.Core/Core/Logging/AbstractLoggerFactory.cs b/src/Castle.Core/Core/Logging/AbstractLoggerFactory.cs index f5da938ad6..c6d69cbf72 100644 --- a/src/Castle.Core/Core/Logging/AbstractLoggerFactory.cs +++ b/src/Castle.Core/Core/Logging/AbstractLoggerFactory.cs @@ -17,9 +17,6 @@ namespace Castle.Core.Logging using System; using System.IO; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public abstract class AbstractLoggerFactory : ILoggerFactory { public virtual ILogger Create(Type type) diff --git a/src/Castle.Core/Core/Logging/ConsoleFactory.cs b/src/Castle.Core/Core/Logging/ConsoleFactory.cs index c456888879..fb04eda043 100644 --- a/src/Castle.Core/Core/Logging/ConsoleFactory.cs +++ b/src/Castle.Core/Core/Logging/ConsoleFactory.cs @@ -16,9 +16,6 @@ namespace Castle.Core.Logging { using System; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ConsoleFactory : ILoggerFactory { private LoggerLevel? level; diff --git a/src/Castle.Core/Core/Logging/ConsoleLogger.cs b/src/Castle.Core/Core/Logging/ConsoleLogger.cs index 277b48f59c..1fd75ae32b 100644 --- a/src/Castle.Core/Core/Logging/ConsoleLogger.cs +++ b/src/Castle.Core/Core/Logging/ConsoleLogger.cs @@ -22,9 +22,6 @@ namespace Castle.Core.Logging /// This is mainly for the cases when you have a utility that /// does not have a logger to supply. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ConsoleLogger : LevelFilteredLogger { /// diff --git a/src/Castle.Core/Core/Logging/LevelFilteredLogger.cs b/src/Castle.Core/Core/Logging/LevelFilteredLogger.cs index c0437fe668..eeb119e590 100644 --- a/src/Castle.Core/Core/Logging/LevelFilteredLogger.cs +++ b/src/Castle.Core/Core/Logging/LevelFilteredLogger.cs @@ -22,9 +22,6 @@ namespace Castle.Core.Logging /// provides a LogLevel attribute and reroutes all functions into /// one Log method. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public abstract class LevelFilteredLogger : ILogger { private LoggerLevel level = LoggerLevel.Off; diff --git a/src/Castle.Core/Core/Logging/LoggerException.cs b/src/Castle.Core/Core/Logging/LoggerException.cs index 8b5f7421df..f051abb9a0 100644 --- a/src/Castle.Core/Core/Logging/LoggerException.cs +++ b/src/Castle.Core/Core/Logging/LoggerException.cs @@ -15,11 +15,7 @@ namespace Castle.Core.Logging { using System; - using System.Runtime.Serialization; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class LoggerException : Exception { public LoggerException() @@ -33,11 +29,5 @@ public LoggerException(string message) : base(message) public LoggerException(string message, Exception innerException) : base(message, innerException) { } - -#if FEATURE_SERIALIZATION - protected LoggerException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -#endif } } \ No newline at end of file diff --git a/src/Castle.Core/Core/Logging/NullLogFactory.cs b/src/Castle.Core/Core/Logging/NullLogFactory.cs index 37479e2ed5..679f9a54ce 100644 --- a/src/Castle.Core/Core/Logging/NullLogFactory.cs +++ b/src/Castle.Core/Core/Logging/NullLogFactory.cs @@ -14,14 +14,9 @@ namespace Castle.Core.Logging { - using System; - /// /// NullLogFactory used when logging is turned off. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class NullLogFactory : AbstractLoggerFactory { /// diff --git a/src/Castle.Core/Core/Logging/StreamLogger.cs b/src/Castle.Core/Core/Logging/StreamLogger.cs index 91e1b8c07e..21dd25ed03 100644 --- a/src/Castle.Core/Core/Logging/StreamLogger.cs +++ b/src/Castle.Core/Core/Logging/StreamLogger.cs @@ -26,9 +26,6 @@ namespace Castle.Core.Logging /// /// This logger is not thread safe. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class StreamLogger : LevelFilteredLogger, IDisposable { private StreamWriter writer; diff --git a/src/Castle.Core/Core/Logging/StreamLoggerFactory.cs b/src/Castle.Core/Core/Logging/StreamLoggerFactory.cs index 78077f1105..a39a237004 100644 --- a/src/Castle.Core/Core/Logging/StreamLoggerFactory.cs +++ b/src/Castle.Core/Core/Logging/StreamLoggerFactory.cs @@ -23,9 +23,6 @@ namespace Castle.Core.Logging /// to files. The name of the file is derived from the log name /// plus the 'log' extension. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class StreamLoggerFactory : AbstractLoggerFactory { public override ILogger Create(string name) diff --git a/src/Castle.Core/Core/ReferenceEqualityComparer.cs b/src/Castle.Core/Core/ReferenceEqualityComparer.cs index 3b91551dd3..2b2a96628c 100644 --- a/src/Castle.Core/Core/ReferenceEqualityComparer.cs +++ b/src/Castle.Core/Core/ReferenceEqualityComparer.cs @@ -19,9 +19,6 @@ namespace Castle.Core using System.Collections.Generic; using System.Runtime.CompilerServices; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer { private static readonly ReferenceEqualityComparer instance = new ReferenceEqualityComparer(); diff --git a/src/Castle.Core/Core/Resource/CustomUri.cs b/src/Castle.Core/Core/Resource/CustomUri.cs index de9b017d4a..b2578d7f76 100644 --- a/src/Castle.Core/Core/Resource/CustomUri.cs +++ b/src/Castle.Core/Core/Resource/CustomUri.cs @@ -17,9 +17,6 @@ namespace Castle.Core.Resource using System; using System.Text; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public sealed class CustomUri { public static readonly string SchemeDelimiter = "://"; diff --git a/src/Castle.Core/Core/Resource/ResourceException.cs b/src/Castle.Core/Core/Resource/ResourceException.cs index 4a7318c140..a2a6e317f9 100644 --- a/src/Castle.Core/Core/Resource/ResourceException.cs +++ b/src/Castle.Core/Core/Resource/ResourceException.cs @@ -15,11 +15,7 @@ namespace Castle.Core.Resource { using System; - using System.Runtime.Serialization; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ResourceException : Exception { public ResourceException() @@ -33,11 +29,5 @@ public ResourceException(string message) : base(message) public ResourceException(string message, Exception innerException) : base(message, innerException) { } - -#if FEATURE_SERIALIZATION - protected ResourceException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -#endif } } \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/AllMethodsHook.cs b/src/Castle.Core/DynamicProxy/AllMethodsHook.cs index bb11338cab..3b5ab0d8db 100644 --- a/src/Castle.Core/DynamicProxy/AllMethodsHook.cs +++ b/src/Castle.Core/DynamicProxy/AllMethodsHook.cs @@ -20,9 +20,6 @@ namespace Castle.DynamicProxy using System.Collections.Generic; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class AllMethodsHook : IProxyGenerationHook { protected static readonly ICollection SkippedTypes = new[] diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxySerializableContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxySerializableContributor.cs deleted file mode 100644 index bdf8909cb5..0000000000 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxySerializableContributor.cs +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2004-2026 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Contributors -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Linq; - using System.Reflection; - using System.Runtime.Serialization; - - using Castle.DynamicProxy.Generators; - using Castle.DynamicProxy.Generators.Emitters; - using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Internal; - using Castle.DynamicProxy.Tokens; - - internal class ClassProxySerializableContributor : SerializableContributor - { - private bool delegateToBaseGetObjectData; - private ConstructorInfo serializationConstructor; - private readonly IList serializedFields = new List(); - - public ClassProxySerializableContributor(Type targetType, Type[] interfaces, string typeId) - : base(targetType, interfaces, typeId) - { - Debug.Assert(targetType.IsSerializable, "This contributor is intended for serializable types only."); - } - - public override void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) - { - delegateToBaseGetObjectData = VerifyIfBaseImplementsGetObjectData(targetType, model, out var getObjectData); - - // This contributor is going to add a `GetObjectData` method to the proxy type. - // If a method with the same name and signature exists in the proxied class type, - // and another contributor has decided to proxy it, we need to tell it not to. - // Otherwise, we'll end up with two implementations! - - if (getObjectData == null) - { - // `VerifyIfBaseImplementsGetObjectData` only searches for `GetObjectData` - // in the implementation map for `ISerializable`. In the best case, it was - // already found there. If not, we need to look again, since *any* method - // with the same signature is a problem. - - var getObjectDataMethod = targetType.GetMethod( - "GetObjectData", - BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, - null, - new[] { typeof(SerializationInfo), typeof(StreamingContext) }, - null); - - if (getObjectDataMethod != null) - { - getObjectData = model.FindMethod(getObjectDataMethod); - } - } - - if (getObjectData != null && getObjectData.Proxyable) - { - getObjectData.Ignore = true; - } - } - - public override void Generate(ClassEmitter @class) - { - ImplementGetObjectData(@class); - Constructor(@class); - } - - protected override void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData, - FieldReference field) - { - serializedFields.Add(field); - base.AddAddValueInvocation(serializationInfo, getObjectData, field); - } - - protected override void CustomizeGetObjectData(CodeBuilder codeBuilder, ArgumentReference serializationInfo, - ArgumentReference streamingContext, ClassEmitter emitter) - { - codeBuilder.AddStatement( - new MethodInvocationExpression( - serializationInfo, - SerializationInfoMethods.AddValue_Bool, - new LiteralStringExpression("__delegateToBase"), - new LiteralBoolExpression(delegateToBaseGetObjectData))); - - if (delegateToBaseGetObjectData == false) - { - EmitCustomGetObjectData(codeBuilder, serializationInfo); - return; - } - - EmitCallToBaseGetObjectData(codeBuilder, serializationInfo, streamingContext); - } - - private void EmitCustomGetObjectData(CodeBuilder codeBuilder, ArgumentReference serializationInfo) - { - var members = codeBuilder.DeclareLocal(typeof(MemberInfo[])); - var data = codeBuilder.DeclareLocal(typeof(object[])); - - var getSerializableMembers = new MethodInvocationExpression( - null, - FormatterServicesMethods.GetSerializableMembers, - new TypeTokenExpression(targetType)); - codeBuilder.AddStatement(new AssignStatement(members, getSerializableMembers)); - - // Sort to keep order on both serialize and deserialize side the same, c.f DYNPROXY-ISSUE-127 - var callSort = new MethodInvocationExpression( - null, - TypeUtilMethods.Sort, - members); - codeBuilder.AddStatement(new AssignStatement(members, callSort)); - - var getObjectData = new MethodInvocationExpression( - null, - FormatterServicesMethods.GetObjectData, - ThisExpression.Instance, - members); - codeBuilder.AddStatement(new AssignStatement(data, getObjectData)); - - var addValue = new MethodInvocationExpression( - serializationInfo, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__data"), - data); - codeBuilder.AddStatement(addValue); - } - - private void EmitCallToBaseGetObjectData(CodeBuilder codeBuilder, ArgumentReference serializationInfo, - ArgumentReference streamingContext) - { - var baseGetObjectData = targetType.GetMethod("GetObjectData", - new[] { typeof(SerializationInfo), typeof(StreamingContext) }); - - codeBuilder.AddStatement( - new MethodInvocationExpression( - baseGetObjectData, - serializationInfo, - streamingContext)); - } - - private void Constructor(ClassEmitter emitter) - { - if (!delegateToBaseGetObjectData) - { - return; - } - GenerateSerializationConstructor(emitter); - } - - private void GenerateSerializationConstructor(ClassEmitter emitter) - { - var serializationInfo = new ArgumentReference(typeof(SerializationInfo)); - var streamingContext = new ArgumentReference(typeof(StreamingContext)); - - var ctor = emitter.CreateConstructor(serializationInfo, streamingContext); - - ctor.CodeBuilder.AddStatement( - new ConstructorInvocationStatement(serializationConstructor, - serializationInfo, - streamingContext)); - - foreach (var field in serializedFields) - { - var getValue = new MethodInvocationExpression(serializationInfo, - SerializationInfoMethods.GetValue, - new LiteralStringExpression(field.Reference.Name), - new TypeTokenExpression(field.Reference.FieldType)); - ctor.CodeBuilder.AddStatement(new AssignStatement( - field, - new ConvertExpression(field.Reference.FieldType, - typeof(object), - getValue))); - } - - ctor.CodeBuilder.AddStatement(ReturnStatement.Instance); - } - - private bool VerifyIfBaseImplementsGetObjectData(Type baseType, MetaType model, out MetaMethod getObjectData) - { - getObjectData = null; - - if (!typeof(ISerializable).IsAssignableFrom(baseType)) - { - return false; - } - - if (baseType.IsDelegateType()) - { - //working around bug in CLR which returns true for "does this type implement ISerializable" for delegates - return false; - } - - // If base type implements ISerializable, we have to make sure - // the GetObjectData is marked as virtual - var getObjectDataMethod = baseType.GetInterfaceMap(typeof(ISerializable)).TargetMethods[0]; - if (getObjectDataMethod.IsPrivate) //explicit interface implementation - { - return false; - } - - if (!getObjectDataMethod.IsVirtual || getObjectDataMethod.IsFinal) - { - var message = string.Format("The type {0} implements ISerializable, but GetObjectData is not marked as virtual. " + - "Dynamic Proxy needs types implementing ISerializable to mark GetObjectData as virtual " + - "to ensure correct serialization process.", - baseType.FullName); - throw new ArgumentException(message); - } - - getObjectData = model.FindMethod(getObjectDataMethod); - - serializationConstructor = baseType.GetConstructor( - BindingFlags.Instance | BindingFlags.Public | - BindingFlags.NonPublic, - null, - new[] { typeof(SerializationInfo), typeof(StreamingContext) }, - null); - - if (serializationConstructor == null) - { - var message = string.Format("The type {0} implements ISerializable, " + - "but failed to provide a deserialization constructor", - baseType.FullName); - throw new ArgumentException(message); - } - - return true; - } - } -} - -#endif diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxySerializableContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxySerializableContributor.cs deleted file mode 100644 index a9b85d86ea..0000000000 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxySerializableContributor.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Contributors -{ - using System; - - using Castle.DynamicProxy.Generators.Emitters; - using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Tokens; - - internal class InterfaceProxySerializableContributor : SerializableContributor - { - public InterfaceProxySerializableContributor(Type targetType, string proxyGeneratorId, Type[] interfaces) - : base(targetType, interfaces, proxyGeneratorId) - { - } - - protected override void CustomizeGetObjectData(CodeBuilder codeBuilder, ArgumentReference serializationInfo, - ArgumentReference streamingContext, ClassEmitter emitter) - { - var targetField = emitter.GetField("__target"); - - codeBuilder.AddStatement( - new MethodInvocationExpression( - serializationInfo, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__targetFieldType"), - new LiteralStringExpression(targetField.Reference.FieldType.AssemblyQualifiedName))); - - codeBuilder.AddStatement( - new MethodInvocationExpression( - serializationInfo, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__theInterface"), - new LiteralStringExpression(targetType.AssemblyQualifiedName))); - } - } -} - -#endif diff --git a/src/Castle.Core/DynamicProxy/Contributors/SerializableContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/SerializableContributor.cs deleted file mode 100644 index 34b5817946..0000000000 --- a/src/Castle.Core/DynamicProxy/Contributors/SerializableContributor.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2004-2026 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Contributors -{ - using System; - using System.Runtime.Serialization; - - using Castle.DynamicProxy.Generators; - using Castle.DynamicProxy.Generators.Emitters; - using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Serialization; - using Castle.DynamicProxy.Tokens; - - internal abstract class SerializableContributor : ITypeContributor - { - protected readonly Type targetType; - private readonly string proxyTypeId; - private readonly Type[] interfaces; - - protected SerializableContributor(Type targetType, Type[] interfaces, string proxyTypeId) - { - this.targetType = targetType; - this.proxyTypeId = proxyTypeId; - this.interfaces = interfaces ?? Type.EmptyTypes; - } - - public virtual void Generate(ClassEmitter @class) - { - ImplementGetObjectData(@class); - } - - protected void ImplementGetObjectData(ClassEmitter emitter) - { - var getObjectData = emitter.CreateMethod("GetObjectData", typeof(void), - new[] { typeof(SerializationInfo), typeof(StreamingContext) }); - var info = getObjectData.Arguments[0]; - - var typeLocal = getObjectData.CodeBuilder.DeclareLocal(typeof(Type)); - - getObjectData.CodeBuilder.AddStatement( - new AssignStatement( - typeLocal, - new MethodInvocationExpression( - null, - TypeMethods.StaticGetType, - new LiteralStringExpression(typeof(ProxyObjectReference).AssemblyQualifiedName), - new LiteralBoolExpression(true), - new LiteralBoolExpression(false)))); - - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - info, - SerializationInfoMethods.SetType, - typeLocal)); - - foreach (var field in emitter.GetAllFields()) - { - if (field.Reference.IsStatic) - { - continue; - } - if (field.Reference.IsNotSerialized) - { - continue; - } - AddAddValueInvocation(info, getObjectData, field); - } - - var interfacesLocal = getObjectData.CodeBuilder.DeclareLocal(typeof(string[])); - - getObjectData.CodeBuilder.AddStatement( - new AssignStatement( - interfacesLocal, - new NewArrayExpression(interfaces.Length, typeof(string)))); - - for (var i = 0; i < interfaces.Length; i++) - { - getObjectData.CodeBuilder.AddStatement( - new AssignStatement( - new ArrayElementReference(interfacesLocal, i), - new LiteralStringExpression(interfaces[i].AssemblyQualifiedName))); - } - - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - info, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__interfaces"), - interfacesLocal)); - - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - info, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__baseType"), - new LiteralStringExpression(emitter.BaseType.AssemblyQualifiedName))); - - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - info, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__proxyGenerationOptions"), - emitter.GetField("proxyGenerationOptions"))); - - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - info, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression("__proxyTypeId"), - new LiteralStringExpression(proxyTypeId))); - - CustomizeGetObjectData(getObjectData.CodeBuilder, info, getObjectData.Arguments[1], emitter); - - getObjectData.CodeBuilder.AddStatement(ReturnStatement.Instance); - } - - protected virtual void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData, - FieldReference field) - { - getObjectData.CodeBuilder.AddStatement( - new MethodInvocationExpression( - serializationInfo, - SerializationInfoMethods.AddValue_Object, - new LiteralStringExpression(field.Reference.Name), - field)); - return; - } - - protected abstract void CustomizeGetObjectData(CodeBuilder builder, ArgumentReference serializationInfo, - ArgumentReference streamingContext, ClassEmitter emitter); - - public virtual void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) - { - } - } -} - -#endif diff --git a/src/Castle.Core/DynamicProxy/DynamicProxyException.cs b/src/Castle.Core/DynamicProxy/DynamicProxyException.cs index 0bca0c97b4..14c497286c 100644 --- a/src/Castle.Core/DynamicProxy/DynamicProxyException.cs +++ b/src/Castle.Core/DynamicProxy/DynamicProxyException.cs @@ -23,9 +23,6 @@ namespace Castle.DynamicProxy // Prefer throwing Base Class Library exception types wherever appropriate. // This exception type is to be used mostly when something inside DynamicProxy goes wrong. // Think of it as a "failed assertion" / "bug" exception. -#if FEATURE_SERIALIZATION - [Serializable] -#endif public sealed class DynamicProxyException : Exception { internal DynamicProxyException(string message) : base(message) @@ -35,11 +32,5 @@ internal DynamicProxyException(string message) : base(message) internal DynamicProxyException(string message, Exception innerException) : base(message, innerException) { } - -#if FEATURE_SERIALIZATION - internal DynamicProxyException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -#endif } } diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs index 0dbb858f83..d1d06a6002 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs @@ -35,10 +35,6 @@ protected BaseClassProxyGenerator(ModuleScope scope, Type targetType, Type[]? in protected abstract FieldReference? TargetField { get; } -#if FEATURE_SERIALIZATION - protected abstract SerializableContributor GetSerializableContributor(); -#endif - protected abstract CompositeTypeContributor GetProxyTargetContributor(INamingScope namingScope); protected abstract ProxyTargetAccessorContributor GetProxyTargetAccessorContributor(); @@ -187,15 +183,6 @@ private IEnumerable GetTypeImplementerMapping(out IEnumerable(); - } -#endif - protected override CacheKey GetCacheKey() { return new CacheKey(proxyTargetType, targetType, interfaces, ProxyGenerationOptions); @@ -218,13 +207,6 @@ protected virtual IEnumerable GetTypeImplementerMapping(Type proxyTargetTy } // 4. plus special interfaces - -#if FEATURE_SERIALIZATION - var serializableContributor = new InterfaceProxySerializableContributor(targetType, GeneratorType, interfaces); - contributorsList.Add(serializableContributor); - AddMappingForISerializable(typeImplementerMapping, serializableContributor); -#endif - var proxyTargetAccessorContributor = GetProxyTargetAccessorContributor(); contributorsList.Add(proxyTargetAccessorContributor); try @@ -258,9 +240,6 @@ private void CreateFields(ClassEmitter emitter, Type proxyTargetType) { base.CreateFields(emitter); targetField = emitter.CreateField("__target", proxyTargetType); -#if FEATURE_SERIALIZATION - emitter.DefineCustomAttributeFor(targetField); -#endif } private void EnsureValidBaseType(Type type) diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs index 1dc5806b82..1cefe69bfa 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs @@ -19,10 +19,6 @@ namespace Castle.DynamicProxy.Generators using System.Diagnostics; using System.Linq; using System.Reflection; -#if FEATURE_SERIALIZATION - using System.Runtime.Serialization; - using System.Xml.Serialization; -#endif using Castle.Core.Logging; using Castle.DynamicProxy.Contributors; @@ -109,14 +105,6 @@ protected void AddMapping(Type @interface, ITypeContributor implementer, IDictio } } -#if FEATURE_SERIALIZATION - protected void AddMappingForISerializable(IDictionary typeImplementerMapping, - ITypeContributor instance) - { - AddMapping(typeof(ISerializable), instance, typeImplementerMapping); - } -#endif - /// /// It is safe to add mapping (no mapping for the interface exists) /// @@ -168,11 +156,7 @@ protected virtual void CreateFields(ClassEmitter emitter) protected void CreateInterceptorsField(ClassEmitter emitter) { - var interceptorsField = emitter.CreateField("__interceptors", typeof(IInterceptor[])); - -#if FEATURE_SERIALIZATION - emitter.DefineCustomAttributeFor(interceptorsField); -#endif + emitter.CreateField("__interceptors", typeof(IInterceptor[])); } protected FieldReference CreateOptionsField(ClassEmitter emitter) @@ -193,9 +177,6 @@ protected void CreateSelectorField(ClassEmitter emitter) protected virtual void CreateTypeAttributes(ClassEmitter emitter) { emitter.AddCustomAttributes(ProxyGenerationOptions.AdditionalAttributes); -#if FEATURE_SERIALIZATION - emitter.DefineCustomAttribute(new object[] { targetType }); -#endif } protected void EnsureOptionsOverrideEqualsAndGetHashCode() diff --git a/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs b/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs index d0a98b8f62..b39e983e80 100644 --- a/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs +++ b/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs @@ -17,9 +17,6 @@ namespace Castle.DynamicProxy.Generators using System; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif internal class CacheKey { private readonly MemberInfo target; diff --git a/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs index ac61b6a61b..9113dccc48 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs @@ -17,12 +17,9 @@ namespace Castle.DynamicProxy.Generators { using System; - using System.Collections.Generic; - using System.Reflection; using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Serialization; internal sealed class ClassProxyGenerator : BaseClassProxyGenerator { @@ -38,13 +35,6 @@ protected override CacheKey GetCacheKey() return new CacheKey(targetType, interfaces, ProxyGenerationOptions); } -#if FEATURE_SERIALIZATION - protected override SerializableContributor GetSerializableContributor() - { - return new ClassProxySerializableContributor(targetType, interfaces, ProxyTypeConstants.Class); - } -#endif - protected override CompositeTypeContributor GetProxyTargetContributor(INamingScope namingScope) { return new ClassProxyTargetContributor(targetType, namingScope) { Logger = Logger }; diff --git a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs index 006d127833..f0a97f0689 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs @@ -17,17 +17,10 @@ namespace Castle.DynamicProxy.Generators { using System; - using System.Collections.Generic; - using System.Reflection; - -#if FEATURE_SERIALIZATION - using System.Xml.Serialization; -#endif using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Serialization; internal sealed class ClassProxyWithTargetGenerator : BaseClassProxyGenerator { @@ -52,13 +45,6 @@ protected override void CreateFields(ClassEmitter emitter) CreateTargetField(emitter); } -#if FEATURE_SERIALIZATION - protected override SerializableContributor GetSerializableContributor() - { - return new ClassProxySerializableContributor(targetType, interfaces, ProxyTypeConstants.ClassWithTarget); - } -#endif - protected override CompositeTypeContributor GetProxyTargetContributor(INamingScope namingScope) { return new ClassProxyWithTargetTargetContributor(targetType, namingScope) { Logger = Logger }; @@ -79,9 +65,6 @@ protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContribu private void CreateTargetField(ClassEmitter emitter) { targetField = emitter.CreateField("__target", targetType); -#if FEATURE_SERIALIZATION - emitter.DefineCustomAttributeFor(targetField); -#endif } } } diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs index f19c987fc4..af7a73babf 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs @@ -19,7 +19,6 @@ namespace Castle.DynamicProxy.Generators using System.Linq; using Castle.DynamicProxy.Contributors; - using Castle.DynamicProxy.Serialization; internal sealed class InterfaceProxyWithTargetGenerator : BaseInterfaceProxyGenerator { diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs index 47106c7bf6..ebbaa60ed1 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs @@ -21,8 +21,6 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Internal; - using Castle.DynamicProxy.Serialization; internal sealed class InterfaceProxyWithTargetInterfaceGenerator : BaseInterfaceProxyGenerator { diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs index edfa748111..a7a6c08003 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs @@ -19,7 +19,6 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Serialization; internal sealed class InterfaceProxyWithoutTargetGenerator : BaseInterfaceProxyGenerator { diff --git a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs index f1bee1b38d..e8853023b3 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs @@ -81,10 +81,6 @@ public ClassEmitter Generate(ClassEmitter @class, INamingScope namingScope) ImplementInvokeMethodOnTarget(invocation, methodInfo.GetParameters(), targetField, callback); -#if FEATURE_SERIALIZATION - invocation.DefineCustomAttribute(); -#endif - return invocation; } diff --git a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs index 9ec97f9f60..98e1b398a8 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs @@ -19,10 +19,6 @@ namespace Castle.DynamicProxy.Generators using System.Linq; using System.Reflection; using System.Reflection.Emit; - using System.Runtime.CompilerServices; -#if FEATURE_SERIALIZATION - using System.Xml.Serialization; -#endif using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters; @@ -64,9 +60,7 @@ protected FieldReference BuildMethodInterceptorsField(ClassEmitter @class, Metho namingScope.GetUniqueName(string.Format("interceptors_{0}", method.Name)), typeof(IInterceptor[]), false); -#if FEATURE_SERIALIZATION - @class.DefineCustomAttributeFor(methodInterceptors); -#endif + return methodInterceptors; } diff --git a/src/Castle.Core/DynamicProxy/Internal/InheritanceInvocationWithoutTarget.cs b/src/Castle.Core/DynamicProxy/Internal/InheritanceInvocationWithoutTarget.cs index dea052dca5..8e78707058 100644 --- a/src/Castle.Core/DynamicProxy/Internal/InheritanceInvocationWithoutTarget.cs +++ b/src/Castle.Core/DynamicProxy/Internal/InheritanceInvocationWithoutTarget.cs @@ -21,9 +21,6 @@ namespace Castle.DynamicProxy.Internal using System.Diagnostics; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [EditorBrowsable(EditorBrowsableState.Never)] public sealed class InheritanceInvocationWithoutTarget : InheritanceInvocation { diff --git a/src/Castle.Core/DynamicProxy/Internal/InterfaceMethodWithoutTargetInvocation.cs b/src/Castle.Core/DynamicProxy/Internal/InterfaceMethodWithoutTargetInvocation.cs index b03704533e..6e6a23a58a 100644 --- a/src/Castle.Core/DynamicProxy/Internal/InterfaceMethodWithoutTargetInvocation.cs +++ b/src/Castle.Core/DynamicProxy/Internal/InterfaceMethodWithoutTargetInvocation.cs @@ -21,9 +21,6 @@ namespace Castle.DynamicProxy.Internal using System.Diagnostics; using System.Reflection; -#if FEATURE_SERIALIZATION - [Serializable] -#endif [EditorBrowsable(EditorBrowsableState.Never)] public sealed class InterfaceMethodWithoutTargetInvocation : AbstractInvocation { diff --git a/src/Castle.Core/DynamicProxy/ModuleScope.cs b/src/Castle.Core/DynamicProxy/ModuleScope.cs index 908b91a445..cc984007ac 100644 --- a/src/Castle.Core/DynamicProxy/ModuleScope.cs +++ b/src/Castle.Core/DynamicProxy/ModuleScope.cs @@ -17,20 +17,14 @@ namespace Castle.DynamicProxy { using System; - using System.Collections.Generic; - using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Resources; - using System.Threading; using Castle.Core.Internal; using Castle.DynamicProxy.Generators; -#if FEATURE_SERIALIZATION - using Castle.DynamicProxy.Serialization; -#endif public class ModuleScope { @@ -490,73 +484,11 @@ internal void ResetModules() File.Delete(assemblyFilePath); } -#if FEATURE_SERIALIZATION - AddCacheMappings(assemblyBuilder); -#endif - assemblyBuilder.Save(assemblyFileName); return assemblyFilePath; } #endif -#if FEATURE_SERIALIZATION - private void AddCacheMappings(AssemblyBuilder builder) - { - var mappings = new Dictionary(); - - typeCache.ForEach((key, value) => - { - // NOTE: using == returns invalid results. - // we need to use Equals here for it to work properly - if (builder.Equals(value.Assembly)) - { - mappings.Add(key, value.FullName); - } - }); - - CacheMappingsAttribute.ApplyTo(builder, mappings); - } - - /// - /// Loads the generated types from the given assembly into this 's cache. - /// - /// The assembly to load types from. This assembly must have been saved via or - /// , or it must have the manually applied. - /// - /// This method can be used to load previously generated and persisted proxy types from disk into this scope's type cache, e.g. in order - /// to avoid the performance hit associated with proxy generation. - /// - public void LoadAssemblyIntoCache(Assembly assembly) - { - if (assembly == null) - { - throw new ArgumentNullException(nameof(assembly)); - } - - var cacheMappings = - (CacheMappingsAttribute[])assembly.GetCustomAttributes(typeof(CacheMappingsAttribute), false); - - if (cacheMappings.Length == 0) - { - var message = string.Format( - "The given assembly '{0}' does not contain any cache information for generated types.", - assembly.FullName); - throw new ArgumentException(message, nameof(assembly)); - } - - foreach (var mapping in cacheMappings[0].GetDeserializedMappings()) - { - var loadedType = assembly.GetType(mapping.Value); - - if (loadedType != null) - { - typeCache.AddOrUpdateWithoutTakingLock(mapping.Key, loadedType); - } - } - } -#endif - internal virtual TypeBuilder DefineType(bool inSignedModulePreferably, string name, TypeAttributes flags) { var module = ObtainDynamicModule(disableSignedModule == false && inSignedModulePreferably); diff --git a/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs b/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs index 2574203c93..985b17fc1f 100644 --- a/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs +++ b/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs @@ -20,11 +20,6 @@ namespace Castle.DynamicProxy using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; - using System.Reflection; - using System.Reflection.Emit; -#if FEATURE_SERIALIZATION - using System.Runtime.Serialization; -#endif using Castle.DynamicProxy.Internal; @@ -36,22 +31,13 @@ namespace Castle.DynamicProxy /// used to create a proxy (or proxy type). /// /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class ProxyGenerationOptions -#if FEATURE_SERIALIZATION - : ISerializable -#endif { public static readonly ProxyGenerationOptions Default = new ProxyGenerationOptions(); private List? mixins; private readonly IList additionalAttributes = new List(); -#if FEATURE_SERIALIZATION - [NonSerialized] -#endif private MixinData? mixinData; // this is calculated dynamically on proxy type creation /// @@ -72,16 +58,6 @@ public ProxyGenerationOptions() { } -#if FEATURE_SERIALIZATION - private ProxyGenerationOptions(SerializationInfo info, StreamingContext context) - { - Hook = (IProxyGenerationHook)info.GetValue("hook", typeof(IProxyGenerationHook)); - Selector = (IInterceptorSelector)info.GetValue("selector", typeof(IInterceptorSelector)); - mixins = (List)info.GetValue("mixins", typeof(List)); - BaseTypeForInterfaceProxy = Type.GetType(info.GetString("baseTypeForInterfaceProxy.AssemblyQualifiedName")); - } -#endif - [MemberNotNull(nameof(mixinData))] public void Initialize() { @@ -99,16 +75,6 @@ public void Initialize() } } -#if FEATURE_SERIALIZATION - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("hook", Hook); - info.AddValue("selector", Selector); - info.AddValue("mixins", mixins); - info.AddValue("baseTypeForInterfaceProxy.AssemblyQualifiedName", BaseTypeForInterfaceProxy.AssemblyQualifiedName); - } -#endif - /// /// Gets or sets the that should be used during proxy type /// generation. Defaults to an instance of . diff --git a/src/Castle.Core/DynamicProxy/Serialization/ProxyTypeConstants.cs b/src/Castle.Core/DynamicProxy/ProxyTypeConstants.cs similarity index 96% rename from src/Castle.Core/DynamicProxy/Serialization/ProxyTypeConstants.cs rename to src/Castle.Core/DynamicProxy/ProxyTypeConstants.cs index c4e055abab..9bf3eeb61c 100644 --- a/src/Castle.Core/DynamicProxy/Serialization/ProxyTypeConstants.cs +++ b/src/Castle.Core/DynamicProxy/ProxyTypeConstants.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Castle.DynamicProxy.Serialization +namespace Castle.DynamicProxy { internal static class ProxyTypeConstants { diff --git a/src/Castle.Core/DynamicProxy/Serialization/CacheMappingsAttribute.cs b/src/Castle.Core/DynamicProxy/Serialization/CacheMappingsAttribute.cs deleted file mode 100644 index c9c5a31520..0000000000 --- a/src/Castle.Core/DynamicProxy/Serialization/CacheMappingsAttribute.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Serialization -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Reflection; - using System.Reflection.Emit; - using System.Runtime.Serialization.Formatters.Binary; - - using Castle.DynamicProxy.Generators; - - /// - /// Applied to the assemblies saved by in order to persist the cache data included in the persisted assembly. - /// - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] - [CLSCompliant(false)] - public class CacheMappingsAttribute : Attribute - { - private static readonly ConstructorInfo constructor = - typeof(CacheMappingsAttribute).GetConstructor(new[] { typeof(byte[]) }); - - private readonly byte[] serializedCacheMappings; - - public CacheMappingsAttribute(byte[] serializedCacheMappings) - { - this.serializedCacheMappings = serializedCacheMappings; - } - - public byte[] SerializedCacheMappings - { - get { return serializedCacheMappings; } - } - - internal Dictionary GetDeserializedMappings() - { - using (var stream = new MemoryStream(SerializedCacheMappings)) - { - var formatter = new BinaryFormatter(); - return (Dictionary)formatter.Deserialize(stream); - } - } - - internal static void ApplyTo(AssemblyBuilder assemblyBuilder, Dictionary mappings) - { - using (var stream = new MemoryStream()) - { - var formatter = new BinaryFormatter(); - formatter.Serialize(stream, mappings); - var bytes = stream.ToArray(); - var attributeBuilder = new CustomAttributeBuilder(constructor, new object[] { bytes }); - assemblyBuilder.SetCustomAttribute(attributeBuilder); - } - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs b/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs deleted file mode 100644 index 461715ee97..0000000000 --- a/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Serialization -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Reflection; - using System.Runtime.Serialization; - - using Castle.DynamicProxy.Generators; - using Castle.DynamicProxy.Internal; - - /// - /// Handles the deserialization of proxies. - /// - [Serializable] - public class ProxyObjectReference : IObjectReference, ISerializable, IDeserializationCallback - { - private static ModuleScope scope = new ModuleScope(); - - private readonly SerializationInfo info; - private readonly StreamingContext context; - - private readonly Type baseType; - private readonly Type[] interfaces; - private readonly object proxy; - private readonly ProxyGenerationOptions proxyGenerationOptions; - - private bool isInterfaceProxy; - private bool delegateToBase; - - /// - /// Resets the used for deserialization to a new scope. - /// - /// - /// This is useful for test cases. - /// - public static void ResetScope() - { - SetScope(new ModuleScope()); - } - - /// - /// Resets the used for deserialization to a given . - /// - /// The scope to be used for deserialization. - /// - /// By default, the deserialization process uses a different scope than the rest of the application, which can lead to multiple proxies - /// being generated for the same type. By explicitly setting the deserialization scope to the application's scope, this can be avoided. - /// - public static void SetScope(ModuleScope scope) - { - if (scope == null) - { - throw new ArgumentNullException(nameof(scope)); - } - ProxyObjectReference.scope = scope; - } - - /// - /// Gets the used for deserialization. - /// - /// As has no way of automatically determining the scope used by the application (and the application might use more than one scope at the same time), uses a dedicated scope instance for deserializing proxy types. This instance can be reset and set to a specific value via and . - public static ModuleScope ModuleScope - { - get { return scope; } - } - - protected ProxyObjectReference(SerializationInfo info, StreamingContext context) - { - this.info = info; - this.context = context; - - baseType = DeserializeTypeFromString("__baseType"); - - var _interfaceNames = (string[])info.GetValue("__interfaces", typeof(string[])); - interfaces = new Type[_interfaceNames.Length]; - - for (var i = 0; i < _interfaceNames.Length; i++) - { - interfaces[i] = Type.GetType(_interfaceNames[i]); - } - - proxyGenerationOptions = - (ProxyGenerationOptions)info.GetValue("__proxyGenerationOptions", typeof(ProxyGenerationOptions)); - proxy = RecreateProxy(); - - // We'll try to deserialize as much of the proxy state as possible here. This is just best effort; due to deserialization dependency reasons, - // we need to repeat this in OnDeserialization to guarantee correct state deserialization. - DeserializeProxyState(); - } - - private Type DeserializeTypeFromString(string key) - { - return Type.GetType(info.GetString(key), true, false); - } - - protected virtual object RecreateProxy() - { - var generatorType = GetValue("__proxyTypeId"); - if (generatorType.Equals(ProxyTypeConstants.Class)) - { - isInterfaceProxy = false; - return RecreateClassProxy(); - } - if (generatorType.Equals(ProxyTypeConstants.ClassWithTarget)) - { - isInterfaceProxy = false; - return RecreateClassProxyWithTarget(); - } - isInterfaceProxy = true; - return RecreateInterfaceProxy(generatorType); - } - - private object RecreateClassProxyWithTarget() - { - var generator = new ClassProxyWithTargetGenerator(scope, baseType, interfaces, proxyGenerationOptions); - var proxyType = generator.GetProxyType(); - return InstantiateClassProxy(proxyType); - } - - public object RecreateInterfaceProxy(string generatorType) - { - var @interface = DeserializeTypeFromString("__theInterface"); - var targetType = DeserializeTypeFromString("__targetFieldType"); - - BaseInterfaceProxyGenerator generator; - if (generatorType == ProxyTypeConstants.InterfaceWithTarget) - { - generator = new InterfaceProxyWithTargetGenerator(scope, @interface, interfaces, targetType, proxyGenerationOptions); - } - else if (generatorType == ProxyTypeConstants.InterfaceWithoutTarget) - { - generator = new InterfaceProxyWithoutTargetGenerator(scope, @interface, interfaces, targetType, proxyGenerationOptions); - } - else if (generatorType == ProxyTypeConstants.InterfaceWithTargetInterface) - { - generator = new InterfaceProxyWithTargetInterfaceGenerator(scope, @interface, interfaces, targetType, proxyGenerationOptions); - } - else - { - throw new InvalidOperationException( - string.Format( - "Got value {0} for the interface generator type, which is not known for the purpose of serialization.", - generatorType)); - } - - var proxyType = generator.GetProxyType(); - return FormatterServices.GetSafeUninitializedObject(proxyType); - } - - public object RecreateClassProxy() - { - var generator = new ClassProxyGenerator(scope, baseType, interfaces, proxyGenerationOptions); - var proxyType = generator.GetProxyType(); - return InstantiateClassProxy(proxyType); - } - - private object InstantiateClassProxy(Type proxy_type) - { - delegateToBase = GetValue("__delegateToBase"); - if (delegateToBase) - { - return Activator.CreateInstance(proxy_type, new object[] { info, context }); - } - else - { - return FormatterServices.GetSafeUninitializedObject(proxy_type); - } - } - - protected void InvokeCallback(object target) - { - if (target is IDeserializationCallback) - { - (target as IDeserializationCallback).OnDeserialization(this); - } - } - - public object GetRealObject(StreamingContext context) - { - return proxy; - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - // There is no need to implement this method as - // this class would never be serialized. - } - - public void OnDeserialization(object sender) - { - var interceptors = GetValue("__interceptors"); - SetInterceptors(interceptors); - - DeserializeProxyMembers(); - - // Get the proxy state again, to get all those members we couldn't get in the constructor due to deserialization ordering. - DeserializeProxyState(); - InvokeCallback(proxy); - } - - private void DeserializeProxyMembers() - { - var proxyType = proxy.GetType(); - var members = FormatterServices.GetSerializableMembers(proxyType); - - var deserializedMembers = new List(); - var deserializedValues = new List(); - for (var i = 0; i < members.Length; i++) - { - var member = members[i] as FieldInfo; - // we get some inherited members... - if (member.DeclaringType != proxyType) - { - continue; - } - - Debug.Assert(member != null); - var value = info.GetValue(member.Name, member.FieldType); - deserializedMembers.Add(member); - deserializedValues.Add(value); - } - FormatterServices.PopulateObjectMembers(proxy, deserializedMembers.ToArray(), deserializedValues.ToArray()); - } - - private void DeserializeProxyState() - { - if (isInterfaceProxy) - { - var target = GetValue("__target"); - SetTarget(target); - } - else if (!delegateToBase) - { - var baseMemberData = GetValue("__data"); - var members = FormatterServices.GetSerializableMembers(baseType); - - // Sort to keep order on both serialize and deserialize side the same, c.f DYNPROXY-ISSUE-127 - members = TypeUtil.Sort(members); - - FormatterServices.PopulateObjectMembers(proxy, members, baseMemberData); - } - } - - private void SetTarget(object target) - { - var targetField = proxy.GetType().GetField("__target", BindingFlags.Instance | BindingFlags.NonPublic); - if (targetField == null) - { - throw new SerializationException( - "The SerializationInfo specifies an invalid interface proxy type, which has no __target field."); - } - - targetField.SetValue(proxy, target); - } - - private void SetInterceptors(IInterceptor[] interceptors) - { - var interceptorField = proxy.GetType().GetField("__interceptors", BindingFlags.Instance | BindingFlags.NonPublic); - if (interceptorField == null) - { - throw new SerializationException( - "The SerializationInfo specifies an invalid proxy type, which has no __interceptors field."); - } - - interceptorField.SetValue(proxy, interceptors); - } - - private T GetValue(string name) - { - return (T)info.GetValue(name, typeof(T)); - } - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/StandardInterceptor.cs b/src/Castle.Core/DynamicProxy/StandardInterceptor.cs index e7dc17c3b4..5e5280471e 100644 --- a/src/Castle.Core/DynamicProxy/StandardInterceptor.cs +++ b/src/Castle.Core/DynamicProxy/StandardInterceptor.cs @@ -16,11 +16,6 @@ namespace Castle.DynamicProxy { - using System; - -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class StandardInterceptor : IInterceptor { public void Intercept(IInvocation invocation) diff --git a/src/Castle.Core/DynamicProxy/Tokens/FormatterServicesMethods.cs b/src/Castle.Core/DynamicProxy/Tokens/FormatterServicesMethods.cs deleted file mode 100644 index 0754821e70..0000000000 --- a/src/Castle.Core/DynamicProxy/Tokens/FormatterServicesMethods.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tokens -{ - using System; - using System.Reflection; - using System.Runtime.Serialization; - - internal static class FormatterServicesMethods - { - public static readonly MethodInfo GetObjectData = - typeof(FormatterServices).GetMethod("GetObjectData", new[] { typeof(object), typeof(MemberInfo[]) }); - - public static readonly MethodInfo GetSerializableMembers = - typeof(FormatterServices).GetMethod("GetSerializableMembers", new[] { typeof(Type) }); - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Tokens/SerializationInfoMethods.cs b/src/Castle.Core/DynamicProxy/Tokens/SerializationInfoMethods.cs deleted file mode 100644 index 7a22bda26d..0000000000 --- a/src/Castle.Core/DynamicProxy/Tokens/SerializationInfoMethods.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if FEATURE_SERIALIZATION - -namespace Castle.DynamicProxy.Tokens -{ - using System; - using System.Reflection; - using System.Runtime.Serialization; - - /// - /// Holds objects representing methods of class. - /// - internal static class SerializationInfoMethods - { - /// - /// - /// - public static readonly MethodInfo AddValue_Bool = - typeof(SerializationInfo).GetMethod("AddValue", new[] { typeof(string), typeof(bool) }); - - /// - /// - /// - public static readonly MethodInfo AddValue_Int32 = - typeof(SerializationInfo).GetMethod("AddValue", new[] { typeof(string), typeof(int) }); - - /// - /// - /// - public static readonly MethodInfo AddValue_Object = - typeof(SerializationInfo).GetMethod("AddValue", new[] { typeof(string), typeof(object) }); - - /// - /// - /// - public static readonly MethodInfo GetValue = - typeof(SerializationInfo).GetMethod("GetValue", new[] { typeof(string), typeof(Type) }); - - /// - /// - /// - public static readonly MethodInfo SetType = - typeof(SerializationInfo).GetMethod("SetType"); - } -} - -#endif \ No newline at end of file diff --git a/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLogger.cs b/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLogger.cs index 7ec9ebfe40..f73c4cfe5b 100644 --- a/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLogger.cs +++ b/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLogger.cs @@ -22,17 +22,11 @@ namespace Castle.Services.Logging.EventLogIntegration /// /// The Logger using standard Diagnostics namespace. /// -#if FEATURE_SERIALIZATION - [Serializable] -#endif #if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif public class DiagnosticsLogger : LevelFilteredLogger, IDisposable { -#if FEATURE_SERIALIZATION - [NonSerialized] -#endif private EventLog eventLog; /// diff --git a/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLoggerFactory.cs b/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLoggerFactory.cs index 178b61dce8..a646922037 100644 --- a/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLoggerFactory.cs +++ b/src/Castle.Services.Logging.EventLogIntegration/DiagnosticsLoggerFactory.cs @@ -17,9 +17,6 @@ namespace Castle.Services.Logging.EventLogIntegration using System; using Castle.Core.Logging; -#if FEATURE_SERIALIZATION - [Serializable] -#endif #if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif diff --git a/src/Castle.Services.Logging.SerilogIntegration/SerilogLogger.cs b/src/Castle.Services.Logging.SerilogIntegration/SerilogLogger.cs index 7d201a9fc9..35793da070 100644 --- a/src/Castle.Services.Logging.SerilogIntegration/SerilogLogger.cs +++ b/src/Castle.Services.Logging.SerilogIntegration/SerilogLogger.cs @@ -19,9 +19,6 @@ namespace Castle.Services.Logging.SerilogIntegration using Serilog; using Serilog.Events; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class SerilogLogger : Castle.Core.Logging.ILogger { public SerilogLogger(ILogger logger, SerilogFactory factory) diff --git a/src/Castle.Services.Logging.log4netIntegration/Log4netLogger.cs b/src/Castle.Services.Logging.log4netIntegration/Log4netLogger.cs index e4a8d8fa71..aaad76c561 100644 --- a/src/Castle.Services.Logging.log4netIntegration/Log4netLogger.cs +++ b/src/Castle.Services.Logging.log4netIntegration/Log4netLogger.cs @@ -21,9 +21,6 @@ namespace Castle.Services.Logging.Log4netIntegration using log4net.Core; using log4net.Util; -#if FEATURE_SERIALIZATION - [Serializable] -#endif public class Log4netLogger : Castle.Core.Logging.ILogger { private static readonly Type declaringType = typeof(Log4netLogger);