Skip to content

Commit 7cec63e

Browse files
committed
Merge pull request #119 from jeremymeng/netcore
Port DictionaryAdapter and tests to .Net Core
2 parents 0e007d0 + ac6d6ee commit 7cec63e

File tree

132 files changed

+291
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+291
-205
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ Symbol | NET35 | NET40 |
4242
----------------------------------- | ------------------ | ------------------ | ------------------ | ------------------
4343
`FEATURE_APPDOMAIN` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4444
`FEATURE_ASSEMBLYBUILDER_SAVE` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
45+
`FEATURE_BINDINGLIST` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
46+
`FEATURE_DICTIONARYADAPTER_XML` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4547
`FEATURE_EMIT_CUSTOMMODIFIERS` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4648
`FEATURE_EVENTLOG` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4749
`FEATURE_GAC` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4850
`FEATURE_GET_REFERENCED_ASSEMBLIES` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
51+
`FEATURE_IDATAERRORINFO` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
52+
`FEATURE_ISUPPORTINITIALIZE` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
4953
`FEATURE_LEGACY_REFLECTION_API` | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign:
50-
`FEATURE_NETCORE_CONVERTER_API` | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark:
54+
`FEATURE_LISTSORT` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
5155
`FEATURE_NETCORE_REFLECTION_API` | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark:
5256
`FEATURE_REMOTING` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
5357
`FEATURE_SECURITY_PERMISSIONS` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign:
@@ -68,17 +72,21 @@ Symbol | NET35 | NET40 |
6872

6973
* `FEATURE_APPDOMAIN` - enables support for features that make use of an AppDomain in the host.
7074
* `FEATURE_ASSEMBLYBUILDER_SAVE` - enabled support for saving the dynamically generated proxy assembly.
75+
* `FEATURE_BINDINGLIST` - enables support features that make use of System.ComponentModel.BindingList.
76+
* `FEATURE_DICTIONARYADAPTER_XML` - enable DictionaryAdapter Xml features.
7177
* `FEATURE_EMIT_CUSTOMMODIFIERS` - enables emitting optional and required custom modifiers defined on parameters including return parameters. It seems like a defect in corefx not to expose these methods because they are still implemented.
7278
* `FEATURE_EVENTLOG` - provides a diagnostics logger using the Windows Event Log.
7379
* `FEATURE_GAC` - enables support for obtaining assemblies using an assembly long form name.
7480
* `FEATURE_GET_REFERENCED_ASSEMBLIES` - enables code that takes advantage of System.Reflection.Assembly.GetReferencedAssemblies().
81+
* `FEATURE_IDATAERRORINFO` - enables code that depends on System.ComponentModel.IDataErrorInfo.
82+
* `FEATURE_ISUPPORTINITIALIZE` - enables support for features that make use of System.ComponentModel.ISupportInitialize.
7583
* `FEATURE_LEGACY_REFLECTION_API` - provides a shim for .NET 3.5/4.0 that emulates the `TypeInfo` API available in .NET 4.5+ and .NET Core.
76-
* `FEATURE_NETCORE_CONVERTER_API` - provides shims to implement missing Converter in .NET Core.
84+
* `FEATURE_LISTSORT` - enables support for features that make use of System.ComponentModel.ListSortDescription.
7785
* `FEATURE_NETCORE_REFLECTION_API` - provides shims to implement missing functionality in .NET Core that has no alternatives.
7886
* `FEATURE_REMOTING` - supports remoting on various types including inheriting from MarshalByRefObject.
7987
* `FEATURE_SECURITY_PERMISSIONS` - enables the use of CAS and Security[Critical|SafeCritical|Transparent].
8088
* `FEATURE_SERIALIZATION` - enables support for serialization of dynamic proxies and other types.
81-
* `FEATURE_SMTP` - providers the email sender abstraction and implementation.
89+
* `FEATURE_SMTP` - provides the email sender abstraction and implementation.
8290
* `FEATURE_STRONGNAME` - supports a strong named `Castle.Core.dll` assembly.
8391
* `FEATURE_SYSTEM_CONFIGURATION` - enables features that use System.Configuration and the ConfigurationManager.
8492
* `FEATURE_TARGETEXCEPTION` - enabled catching a `TargetException`. `System.Reflection.TargetException` is implemented by .NET Core but not exposed by corefx.

Settings.proj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ limitations under the License.
5757
<AdditionalDefineConstants></AdditionalDefineConstants>
5858
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_APPDOMAIN</AdditionalDefineConstants>
5959
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_ASSEMBLYBUILDER_SAVE</AdditionalDefineConstants>
60+
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_BINDINGLIST</AdditionalDefineConstants>
61+
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_DICTIONARYADAPTER_XML</AdditionalDefineConstants>
6062
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_EMIT_CUSTOMMODIFIERS</AdditionalDefineConstants>
6163
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_EVENTLOG</AdditionalDefineConstants>
6264
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_GAC</AdditionalDefineConstants>
6365
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_GET_REFERENCED_ASSEMBLIES</AdditionalDefineConstants>
66+
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_IDATAERRORINFO</AdditionalDefineConstants>
67+
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_ISUPPORTINITIALIZE</AdditionalDefineConstants>
68+
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_LISTSORT</AdditionalDefineConstants>
6469
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_REMOTING</AdditionalDefineConstants>
6570
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_SECURITY_PERMISSIONS</AdditionalDefineConstants>
6671
<AdditionalDefineConstants>$(AdditionalDefineConstants) FEATURE_SERIALIZATION</AdditionalDefineConstants>

src/Castle.Core.Tests/BaseTestCaseTestCase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public void TearDown_DoesNotSaveAnything_IfNoProxyGenerated()
4949
Assert.IsFalse(File.Exists(path));
5050
}
5151

52+
#if FEATURE_ASSEMBLYBUILDER_SAVE
5253
[Test]
53-
#if SILVERLIGHT
54-
[Ignore("Cannot do in Silverlight")]
55-
#endif
5654
#if __MonoCS__
5755
[Ignore("Expected: True But was: False")]
5856
#endif
@@ -69,6 +67,7 @@ public void TearDown_SavesAssembly_IfProxyGenerated()
6967
base.TearDown();
7068
Assert.IsTrue(File.Exists(path));
7169
}
70+
#endif
7271

7372
private void FindVerificationErrors()
7473
{
@@ -91,6 +90,7 @@ private void FindVerificationErrors()
9190
base.TearDown();
9291
}
9392

93+
#if FEATURE_ASSEMBLYBUILDER_SAVE
9494
[Test]
9595
#if SILVERLIGHT
9696
[Ignore("Cannot do in Silverlight")]
@@ -106,6 +106,7 @@ public void TearDown_FindsVerificationErrors()
106106
StringAssert.Contains("PeVerify reported error(s)", ex.Message);
107107
StringAssert.Contains("fall through end of the method without returning", ex.Message);
108108
}
109+
#endif
109110

110111
[Test]
111112
public void DisableVerification_DisablesVerificationForTestCase()

src/Castle.Core.Tests/BasicClassProxyTestCase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ public void ProxyForNonPublicClass()
8989
var type = Type.GetType("System.AppDomainInitializerInfo, mscorlib");
9090
var exception = Assert.Throws<GeneratorException>(() => generator.CreateClassProxy(type, new StandardInterceptor()));
9191
Assert.AreEqual(
92+
#if FEATURE_STRONGNAME
9293
"Can not create proxy for type System.AppDomainInitializerInfo because it is not accessible. Make it public, or internal and mark your assembly with [assembly: InternalsVisibleTo(\"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7\")] attribute, because assembly mscorlib is strong-named.",
94+
#else
95+
"Can not create proxy for type System.AppDomainInitializerInfo because it is not accessible. Make it public, or internal and mark your assembly with [assembly: InternalsVisibleTo(\"DynamicProxyGenAssembly2\")] attribute, because assembly mscorlib is strong-named.",
96+
#endif
9397
exception.Message);
9498
}
9599

src/Castle.Core.Tests/BasicInterfaceProxyTestCase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public void Cannot_proxy_inaccessible_interface()
252252
ex.Message);
253253
}
254254

255+
#if FEATURE_STRONGNAME
255256
[Test]
256257
public void Cannot_proxy_generic_interface_with_inaccessible_type_argument()
257258
{
@@ -261,6 +262,7 @@ public void Cannot_proxy_generic_interface_with_inaccessible_type_argument()
261262
"Can not create proxy for type System.Collections.Generic.IList`1[[Castle.DynamicProxy.Tests.BasicInterfaceProxyTestCase+PrivateInterface, Castle.Core.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc]] because type Castle.DynamicProxy.Tests.BasicInterfaceProxyTestCase+PrivateInterface is not accessible. Make it public, or internal",
262263
ex.Message);
263264
}
265+
#endif
264266

265267
[Test]
266268
public void Cannot_proxy_generic_interface_with_type_argument_that_has_inaccessible_type_argument()

src/Castle.Core.Tests/Components.DictionaryAdapter.Tests/CustomAssert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#if !SILVERLIGHT // Until support for other platforms is verified
15+
#if FEATURE_DICTIONARYADAPTER_XML
1616
namespace Castle.Components.DictionaryAdapter.Tests
1717
{
1818
using System;

src/Castle.Core.Tests/Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Castle.Components.DictionaryAdapter.Tests
1818
using System.Collections;
1919
using System.Collections.Generic;
2020
using System.Linq;
21+
using System.Reflection;
2122

2223
using CastleTests.Components.DictionaryAdapter.Tests;
2324

@@ -429,7 +430,7 @@ public void ReadAdapter_WithDefaultConversions_WorksFine()
429430
dictionary["Double"] = string.Format("{0}", 3.14D);
430431
dictionary["Decimal"] = string.Format("{0}", 100M);
431432
dictionary["String"] = "Hello World";
432-
dictionary["DateTime"] = now.ToShortDateString();
433+
dictionary["DateTime"] = now.ToString("d");
433434
dictionary["Guid"] = guid.ToString();
434435

435436
var conversions = factory.GetAdapter<IConversions>(dictionary);
@@ -468,7 +469,7 @@ public void UpdateAdapter_WithDefaultConversions_WorksFine()
468469
#if SILVERLIGHT // SL impl limitation
469470
Assert.AreEqual(today.ToString(), dictionary["DateTime"]);
470471
#else
471-
Assert.AreEqual(today.ToShortDateString(), dictionary["DateTime"]);
472+
Assert.AreEqual(today.ToString("d"), dictionary["DateTime"]);
472473
#endif
473474
Assert.AreEqual(guid.ToString(), dictionary["Guid"]);
474475
Assert.AreEqual("2124751012,22", dictionary["Phone"]);
@@ -484,7 +485,7 @@ public void ReadAdapter_WithDefaultNullableConversions_WorksFine()
484485
dictionary["NullFloat"] = string.Format("{0}", 98.6);
485486
dictionary["NullDouble"] = string.Format("{0}", 3.14D);
486487
dictionary["NullDecimal"] = string.Format("{0}", 100M);
487-
dictionary["NullDateTime"] = now.Value.ToShortDateString();
488+
dictionary["NullDateTime"] = now.Value.ToString("d");
488489
dictionary["NullGuid"] = guid.ToString();
489490

490491
var conversions = factory.GetAdapter<IConversions>(dictionary);
@@ -517,7 +518,7 @@ public void UpdateAdapter_WithDefaultNullableConversions_WorksFine()
517518
#if SILVERLIGHT // SL impl limitation
518519
Assert.AreEqual(today.Value.ToString(), dictionary["NullDateTime"]);
519520
#else
520-
Assert.AreEqual(today.Value.ToShortDateString(), dictionary["NullDateTime"]);
521+
Assert.AreEqual(today.Value.ToString("d"), dictionary["NullDateTime"]);
521522
#endif
522523
Assert.AreEqual(guid.ToString(), dictionary["NullGuid"]);
523524
}
@@ -767,7 +768,7 @@ public void WillNotPropagatePropertyChangedEventWhenNestedPropertyChanged()
767768
container.Item.Name = "Craig";
768769
}
769770

770-
#if !SILVERLIGHT //no BindingList in Silverlight
771+
#if FEATURE_BINDINGLIST
771772

772773
[Test]
773774
public void WillPropagatePropertyChangedEventWhenBindingListPropertyChanged()
@@ -1123,6 +1124,7 @@ public void CanInitializeTheDictionaryAdapterWithAttributes()
11231124
Assert.IsTrue(((IDictionaryAdapter)name).Validators.OfType<TestDictionaryValidator>().Any());
11241125
}
11251126

1127+
#if FEATURE_IDATAERRORINFO
11261128
[Test]
11271129
public void CanValidateAndObtainDataErrorInformation()
11281130
{
@@ -1188,6 +1190,7 @@ public void WillNotifyPropertyChangesOnValidateGroup()
11881190
name.LastName = "Monster";
11891191
Assert.IsTrue(notifyCalled);
11901192
}
1193+
#endif
11911194

11921195
[Test]
11931196
public void CanCreateDictionaryAdapterFromExistingAdapter()
@@ -1257,7 +1260,7 @@ public void CanGetInterfacePropertyOnDemand()
12571260
Assert.IsNotNull(container.Phone);
12581261
}
12591262

1260-
#if !SILVERLIGHT //no BindingList in Silverlight
1263+
#if FEATURE_BINDINGLIST
12611264

12621265
[Test]
12631266
public void CanAddBindingListItemsOnDemand()
@@ -1321,7 +1324,7 @@ public void CanGetNewGuidPropertyOnDemand()
13211324
public void CanDetermineTheAdaptedInterface()
13221325
{
13231326
var person = factory.GetAdapter<IPerson>(dictionary);
1324-
var type = person.GetType().GetCustomAttributes(
1327+
var type = person.GetType().GetTypeInfo().GetCustomAttributes(
13251328
typeof(DictionaryAdapterAttribute), false).Cast<DictionaryAdapterAttribute>()
13261329
.FirstOrDefault();
13271330
Assert.IsNotNull(type);

src/Castle.Core.Tests/Components.DictionaryAdapter.Tests/IAddress.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ namespace Castle.Components.DictionaryAdapter.Tests
1717
using System.ComponentModel;
1818

1919
//[PropagateNotifications(false)]
20-
public interface IAddress : IEditableObject, INotifyPropertyChanged, IDataErrorInfo
20+
public interface IAddress : IEditableObject, INotifyPropertyChanged
21+
#if FEATURE_IDATAERRORINFO
22+
, IDataErrorInfo
23+
#endif
2124
{
2225
string Line1 { get; set; }
2326
string Line2 { get; set; }

src/Castle.Core.Tests/Components.DictionaryAdapter.Tests/IItemContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public interface IItemContainer<TItem> : IDictionaryAdapter, IDictionaryCreate,
4343

4444
IList<TItem> GenericItems { get; set; }
4545

46-
#if !SILVERLIGHT
46+
#if FEATURE_BINDINGLIST
4747
BindingList<TItem> Bindingtems { get; set; }
4848
#endif
4949

src/Castle.Core.Tests/Components.DictionaryAdapter.Tests/IPerson.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ namespace Castle.Components.DictionaryAdapter.Tests
1919
using System.ComponentModel;
2020

2121
[MultiLevelEdit]
22-
public interface IPerson : IDictionaryAdapter, IEditableObject, IDictionaryNotify, IDataErrorInfo
22+
public interface IPerson : IDictionaryAdapter, IEditableObject, IDictionaryNotify
23+
#if FEATURE_IDATAERRORINFO
24+
, IDataErrorInfo
25+
#endif
2326
{
2427
[RemoveIf(null)]
2528
string Name { get; set; }

0 commit comments

Comments
 (0)