Skip to content

Commit

Permalink
[DynamicProxy] Preserve DefaultValues of proxied method's parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kenegozi committed Sep 13, 2013
1 parent 36a3471 commit f86cbaf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Castle.Core.Tests/Castle.Core.Tests.csproj
Expand Up @@ -250,6 +250,8 @@
<Compile Include="BugsReported\Core40.cs" />
<Compile Include="BugsReported\DynProxy159.cs" />
<Compile Include="BugsReported\DynProxy145_SynchronizationContext.cs" />
<Compile Include="DynamicProxy.Tests\Classes\ClassWithMethodWithParameterWithDefaultValue.cs" />
<Compile Include="DynamicProxy.Tests\ClassProxyWithDefaultValuesTestCase.cs" />
<Compile Include="DynamicProxy.Tests\GenericInterfaceWithGenericMethod.cs" />
<Compile Include="MultipleSavedAssembliesTestCase.cs" />
<Compile Include="Components.DictionaryAdapter.Tests\AdaptingGenericDictionaryTestCase.cs" />
Expand Down
@@ -0,0 +1,39 @@
// Copyright 2004-2013 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
{
using System.Linq;

using Castle.DynamicProxy.Tests.Classes;

using NUnit.Framework;

[TestFixture]
public class ClassProxyWithDefaultValuesTestCase : BasePEVerifyTestCase
{
#if DOTNET45
[Test]
public void MethodParameterWithDefaultValue_DefaultValueIsSetOnProxiedMethodAsWell()
{
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithDefaultValue>().GetType();

var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value");

Assert.True(parameter.HasDefaultValue);
Assert.AreEqual(3, parameter.DefaultValue);
}
#endif
}
}
@@ -0,0 +1,24 @@
// Copyright 2004-2013 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 ClassWithMethodWithParameterWithDefaultValue
{
public virtual void Method(int? value = 3)
{

}
}
}
Expand Up @@ -156,6 +156,12 @@ private void DefineParameters(ParameterInfo[] parameters)
{
parameterBuilder.SetCustomAttribute(attribute);
}
#if DOTNET45
if (parameter.HasDefaultValue)
{
parameterBuilder.SetConstant(parameter.DefaultValue);
}
#endif
}
}

Expand Down

0 comments on commit f86cbaf

Please sign in to comment.