Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Surrogate
- [ProtoContract]
- public class SurrogateCultureInfo
- {
- [ProtoMember(1)]
- public string Culture { get; set; }
- public static implicit operator SurrogateCultureInfo( CultureInfo info )
- {
- return
- info != null
- ? new SurrogateCultureInfo { Culture = info.Name }
- : null;
- }
- public static implicit operator CultureInfo( SurrogateCultureInfo surrogate )
- {
- CultureInfo info = new CultureInfo(surrogate.Culture);
- return info;
- }
- }
- // Setting the surrogate
- var model = ProtoBuf.Meta.TypeModel.Create();
- AddTypeToModel<CultureInfo>( model ).SetSurrogate( typeof( Surrogates.SurrogateCultureInfo ) );
- private static MetaType AddTypeToModel<T>( RuntimeTypeModel typeModel )
- {
- var properties = typeof(T).GetProperties().Select(p => p.Name).OrderBy(name => name);
- return typeModel.Add(typeof(T), true).Add(properties.ToArray());
- }
Advertisement
Add Comment
Please, Sign In to add comment