diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/BasicClassProxyTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/BasicClassProxyTestCase.cs index a481147711..7eb90942e0 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/BasicClassProxyTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/BasicClassProxyTestCase.cs @@ -380,6 +380,21 @@ public void ClassProxyShouldCallProtectedDefaultConstructor() Assert.AreEqual("Something", ((ClassWithProtectedDefaultConstructor)proxy2).SomeString); } + [Test] + public void ClassProxyShouldHaveDefaultConstructorWhenBaseClassHasPrivateProtected() + { + object proxy = generator.CreateClassProxy(); + Assert.IsNotNull(Activator.CreateInstance(proxy.GetType())); + } + + [Test] + public void ClassProxyShouldCallPrivateProtectedDefaultConstructor() + { + object proxy = generator.CreateClassProxy(); + object proxy2 = Activator.CreateInstance(proxy.GetType()); + Assert.AreEqual("Something", ((ClassWithPrivateProtectedConstructor)proxy2).SomeString); + } + [Test] public void ClassImplementingInterfaceVitrually() { diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithPrivateProtectedConstructor.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithPrivateProtectedConstructor.cs new file mode 100644 index 0000000000..6afd2525bd --- /dev/null +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Classes/ClassWithPrivateProtectedConstructor.cs @@ -0,0 +1,32 @@ +// Copyright 2004-2020 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.Classes +{ + public class ClassWithPrivateProtectedConstructor + { + private protected ClassWithPrivateProtectedConstructor() + { + _someString = "Something"; + } + + private string _someString = string.Empty; + + public string SomeString + { + get { return _someString; } + set { _someString = value; } + } + } +} diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs index adc5e154ce..33f3119985 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs @@ -281,7 +281,7 @@ protected void GenerateConstructors(ClassEmitter emitter, Type baseType, params foreach (var constructor in constructors) { - if (!IsConstructorVisible(constructor)) + if (!ProxyUtil.IsAccessibleMethod(constructor)) { continue; } @@ -409,14 +409,6 @@ protected Type ObtainProxyType(CacheKey cacheKey, Func