Added support for readonly immutable fields
This commit is contained in:
Родитель
52e3f9509d
Коммит
5d96a9594d
|
@ -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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче