Skip to content

Instantly share code, notes, and snippets.

View mgravell's full-sized avatar
🏠
Working from home

Marc Gravell mgravell

🏠
Working from home
View GitHub Profile
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// Protocol version: v.127
// Copyright 2017 Google Inc. All Rights Reserved.
// This is the message that Google uses to request bids. A BidRequest
// includes the ad slot from a single impression.
//
message BidRequest {
// Unique request id generated by Google. This is 16 bytes long.
required bytes id = 2;
syntax = "proto2";
message Foo {
map<int32,string> keyedData = 1;
}
syntax = "proto3";
import "protobuf-net/protogen.proto";
message Foo {
option (.protobuf_net.msgopt).name = "Bar";
int32 id = 1 [(.protobuf_net.fieldopt).access = INTERNAL];
map<sint32,Foo> item = 2 [(.protobuf_net.fieldopt).asRef = true];
}
@mgravell
mgravell / program.cs
Created June 27, 2017 11:27
thread exiting cleanly
[STAThread]
static void Main()
{
new Thread(() =>
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine("running form");
Application.Run(new Form1());
Console.WriteLine("thread exited");
interface ISomeInterface
{
string Foo { get; set; }
}
class CloneHell : ISomeInterface
{
private readonly EvilTwist evil;
CloneHell(EvilTwist evil)
{

The short version would be: because nobody has supported, spec'd, designed, implemented, tested, documented, translated and supported that feature.

The longer version would relate to why to do it, given that it can be achieved indirectly with the readonly field - what benefit would it add.

For classes, it turns out to be relatively minor. Note that there is an [ImmutableObject(true)] attribute that can be used, but no features or frameworks really have a use for it, so ... nobody uses it.

Where this gets really interesting is in the current ref work that is happening in the corefx experimental branch. In particular, "readonly structs" are likely to be a thing soon. There's a reason for this, which is that:

  1. they enable good readonly ref T support (which is necessary for ReadOnlySpan, which is necessary for the Span stuff, which is necessary for the "unifying managed an unmanaged memory stuff", whi
using System;
using System.Collections.Generic;
static class P
{
static void Main()
{
List<Question> question = new List<Question>
{
new Question {
syntax = "proto3";
import "google/protobuf/timestamp.proto";
message AttributeValueType {
oneof itemValue {
int32 Int32 = 1;
string String = 2;
Timestamp DateTime = 3;
double Double = 4;
}
}
syntax = "proto2";
import "google/protobuf/timestamp.proto";
option java_outer_classname = "TestMsgEntity";
message TestMsg {
required string Message = 1;
required google.protobuf.timestamp UpdateTime = 2;
}