-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from stakx/generic-interfaces-name-collisions
Prevent member name collision when proxy implements same generic interface more than twice
- Loading branch information
Showing
9 changed files
with
236 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2004-2010 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.Interfaces | ||
{ | ||
using System; | ||
|
||
public interface IGenericWithEvent<T> | ||
{ | ||
event EventHandler SomeEvent; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Castle.Core.Tests/Interfaces/IGenericWithNonGenericMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2004-2010 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.Interfaces | ||
{ | ||
public interface IGenericWithNonGenericMethod<T> | ||
{ | ||
void SomeMethod(); | ||
} | ||
|
||
public interface IGenericWithNonGenericMethod<T1, T2> | ||
{ | ||
void SomeMethod(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2004-2010 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.Interfaces | ||
{ | ||
public interface IGenericWithProperty<T> | ||
{ | ||
object SomeProperty { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Castle.Core/DynamicProxy/Generators/MetaTypeElementUtil.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2004-2011 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.Generators | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
internal static class MetaTypeElementUtil | ||
{ | ||
public static string CreateNameForExplicitImplementation(Type sourceType, string name) | ||
{ | ||
if (sourceType.GetTypeInfo().IsGenericType) | ||
{ | ||
var nameBuilder = new StringBuilder(); | ||
nameBuilder.AppendNameOf(sourceType); | ||
nameBuilder.Append('.'); | ||
nameBuilder.Append(name); | ||
return nameBuilder.ToString(); | ||
} | ||
else | ||
{ | ||
return string.Concat(sourceType.Name, ".", name); | ||
} | ||
} | ||
|
||
private static void AppendNameOf(this StringBuilder nameBuilder, Type type) | ||
{ | ||
nameBuilder.Append(type.Name); | ||
if (type.GetTypeInfo().IsGenericType) | ||
{ | ||
nameBuilder.Append('['); | ||
var genericTypeArguments = type.GetGenericArguments(); | ||
for (int i = 0, n = genericTypeArguments.Length; i < n; ++i) | ||
{ | ||
if (i > 0) | ||
{ | ||
nameBuilder.Append(','); | ||
} | ||
nameBuilder.AppendNameOf(genericTypeArguments[i]); | ||
} | ||
nameBuilder.Append(']'); | ||
} | ||
} | ||
} | ||
} |