-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding attribute to ignore extension method for read writer (#841)
* feat: adding attibute to ignore extension method for read writer * tests * refactoring ReaderWriterProcessor adding SerailizeExtensionHelper to handle checking of types and methods to find extension methods making reflection and cecil methods have the same logic * adding better fail message to assert * fixing checking type is void * fixing code smell
- Loading branch information
1 parent
b9f9ef6
commit 9494500
Showing
5 changed files
with
237 additions
and
103 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,53 @@ | ||
using System; | ||
using Mirage.Serialization; | ||
using NUnit.Framework; | ||
|
||
namespace Mirage.Tests.Runtime.Serialization | ||
{ | ||
public class WeaverIgnoreTest | ||
{ | ||
[Test] | ||
public void DoesNotUseCustomWriter() | ||
{ | ||
// check method names | ||
Assert.That(Writer<MyCustomType>.Write.Method.Name, Is.Not.EqualTo(new Action<NetworkWriter, MyCustomType>(MyCustomTypeExtension.WriteOnlyPartOfCustom).Method.Name)); | ||
Assert.That(Reader<MyCustomType>.Read.Method.Name, Is.Not.EqualTo(new Func<NetworkReader, MyCustomType>(MyCustomTypeExtension.ReadOnlyPartOfCustom).Method.Name)); | ||
|
||
// check writing and reading | ||
var data = new MyCustomType | ||
{ | ||
first = 10, | ||
second = 20, | ||
}; | ||
var writer = new NetworkWriter(); | ||
writer.Write(data); | ||
var reader = new NetworkReader(writer.ToArraySegment()); | ||
MyCustomType copy = reader.Read<MyCustomType>(); | ||
|
||
// should have copied both fields, | ||
// if it uses custom extension methods it will only write first | ||
Assert.That(copy.first, Is.EqualTo(data.first)); | ||
Assert.That(copy.second, Is.EqualTo(data.second)); | ||
} | ||
|
||
} | ||
public struct MyCustomType | ||
{ | ||
public int first; | ||
public int second; | ||
} | ||
public static class MyCustomTypeExtension | ||
{ | ||
[WeaverIgnore] | ||
public static void WriteOnlyPartOfCustom(this NetworkWriter writer, MyCustomType value) | ||
{ | ||
writer.WriteInt32(value.first); | ||
} | ||
[WeaverIgnore] | ||
|
||
public static MyCustomType ReadOnlyPartOfCustom(this NetworkReader reader) | ||
{ | ||
return new MyCustomType { first = reader.ReadInt32() }; | ||
} | ||
} | ||
} |
Oops, something went wrong.