-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using ProtoBuf.Meta; | ||
using Xunit; | ||
|
||
namespace ProtoBuf.Test.Meta | ||
{ | ||
public class OpenGenericMetaTypeTests | ||
{ | ||
public class OpenGenericTarget<T> | ||
{ | ||
public T Value { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
public class OpenGenericSurrogate<T> | ||
{ | ||
[ProtoMember(1)] | ||
public T Value { get; set; } | ||
|
||
|
||
public static implicit operator OpenGenericTarget<T>(OpenGenericSurrogate<T> surrogate) | ||
{ | ||
return surrogate == null ? null : new OpenGenericTarget<T> | ||
{ | ||
Value = surrogate.Value | ||
}; | ||
} | ||
|
||
public static implicit operator OpenGenericSurrogate<T>(OpenGenericTarget<T> source) | ||
{ | ||
return source == null ? null : new OpenGenericSurrogate<T> | ||
{ | ||
Value = source.Value | ||
}; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void OpenGenericMetaTypeSerialization() | ||
{ | ||
RuntimeTypeModel.Default.Add(typeof(OpenGenericTarget<>)).SetSurrogate(typeof(OpenGenericSurrogate<>)); | ||
|
||
var instance = new OpenGenericTarget<string> { Value = "XYZ!" }; | ||
var clone = RuntimeTypeModel.Default.DeepClone(instance); | ||
|
||
Assert.Equal(instance.Value, clone.Value); | ||
} | ||
} | ||
} |
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