Added support for readonly immutable fields

This commit is contained in:
Carl de Billy 2019-02-16 17:02:46 -05:00
Родитель 52e3f9509d
Коммит 5d96a9594d
2 изменённых файлов: 46 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,35 @@
// ******************************************************************
// Copyright <20> 2015-2018 nventive inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ******************************************************************
using System.Collections.Generic;
namespace Uno.CodeGen.Tests
{
[GeneratedImmutable]
internal partial class MyEntityWithFields
{
private readonly IReadOnlyDictionary<string, string> _readonlyField;
public MyEntityWithFields(IReadOnlyDictionary<string, string> readonlyField)
{
_readonlyField = readonlyField;
}
}
partial class Given_ImmutableEntity
{
}
}

Просмотреть файл

@ -951,10 +951,17 @@ $@"public sealed class {symbolName}BuilderJsonConverterTo{symbolName}{genericArg
if (!field.IsStatic) if (!field.IsStatic)
{ {
Error( if (field.IsReadOnly)
builder, {
$"Immutable type {symbolNames.SymbolNameWithGenerics} cannot " CheckTypeImmutable(field.Type, $"Field {field.Name}");
+ $"have the non-static field {field.Name}. You must remove it for immutable generation or make it static."); }
else
{
Error(
builder,
$"Immutable type {symbolNames.SymbolNameWithGenerics} cannot "
+ $"have the non-static field {field.Name}. You must either remove it, make it readonly or static to allow for immutable generation.");
}
} }
} }
} }