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
// Explicit proto contract | |
[ProtoContract] | |
public class MappedEntity | |
{ | |
[ProtoMember(1)] | |
public int Id { get; set; } | |
[ProtoMember(2)] | |
public string Name { 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
var model = RuntimeTypeModel.Default; | |
// Obtain all serializable types having no explicit proto contract | |
var serializableTypes = Assembly.GetExecutingAssembly() | |
.GetTypes() | |
.Where(t => t.IsSerializable && !Attribute.IsDefined(t, typeof(ProtoContractAttribute))); | |
foreach (var type in serializableTypes) | |
{ | |
var metaType = model.Add(type, false); | |
metaType.AsReferenceDefault = true; |
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
Serialization of 90 objects, 1000 iterations: | |
Write(ms) Read(ms) Size(bytes) | |
BinaryFormatter 634 517 9807 | |
protobuf-net v2 219 253 5179 |
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
public class VariablesReductionVisitor : ExpressionVisitor | |
{ | |
private List<Expression> _children; | |
public override Expression Visit(Expression node) | |
{ | |
// Preserve parent's child expressions collection | |
var siblings = _children; | |
_children = new List<Expression>(); |
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
// Here different expression keys should be generated since parameter "value" is different | |
// for two expressions at the moment of their creation | |
int value = 1; | |
Expression<Func<string, string>> expr1 = s => s.Length > value ? s.Substring(0, value) : s; | |
int value = 2; | |
Expression<Func<string, string>> expr2 = s => s.Length > value ? s.Substring(0, value) : s; | |
// Here same expression keys should be generated since parameter value (1) is the same | |
// for two expressions at the moment of their creation |
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
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) | |
{ | |
if (action == null) | |
{ | |
throw new ArgumentNullException("action"); | |
} | |
foreach (T item in source) | |
{ | |
action(item); | |
} |
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
public void MyMethod(string str) | |
{ | |
CheckUtil.NotNullOrEmpty(str, "str"); | |
} |