提交 408fecdd 编写于 作者: J Jonathon Marolf

responding to PR feedback

上级 3937e611
......@@ -3095,8 +3095,29 @@ void M()
public async Task Support_Readonly_Properties()
{
await TestAsync(
@"class C { public int Prop { get ; } } class P { static void M ( ) { var prop = 42 ; var c = new [|C|] ( prop ) ; } } ",
@"class C { public C ( int prop ) { Prop = prop ; } public int Prop { get ; } } class P { static void M ( ) { var prop = 42 ; var c = new C ( prop ) ; } }",
@"class C {
public int Prop { get ; }
}
class P {
static void M ( ) {
var prop = 42 ;
var c = new [|C|] ( prop ) ;
}
} ",
@"class C {
public C ( int prop ) {
Prop = prop ;
}
public int Prop { get ; }
}
class P {
static void M ( ) {
var prop = 42 ;
var c = new C ( prop ) ;
}
}",
parseOptions: TestOptions.Regular,
withScriptOption: true);
}
......
......@@ -412,6 +412,7 @@ private IEnumerable<string> GetUnavailableMemberNames()
{
var property = (IPropertySymbol)symbol;
return
property.Parameters.Length == 0 &&
property.IsWritableInConstructor() &&
_service.IsConversionImplicit(_document.SemanticModel.Compilation, parameterType, property.Type);
}
......
......@@ -71,17 +71,14 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL
}
public static bool IsWritableInConstructor(this IPropertySymbol property)
{
return property.Parameters.Length == 0 &&
(property.SetMethod != null || ContainsBackingField(property));
}
=> (property.SetMethod != null || ContainsBackingField(property));
public static IFieldSymbol GetBackingFieldIfAny(this IPropertySymbol property) =>
property.ContainingType.GetMembers()
.OfType<IFieldSymbol>()
.FirstOrDefault(f => property.Equals(f.AssociatedSymbol));
public static IFieldSymbol GetBackingFieldIfAny(this IPropertySymbol property)
=> property.ContainingType.GetMembers()
.OfType<IFieldSymbol>()
.FirstOrDefault(f => property.Equals(f.AssociatedSymbol));
private static bool ContainsBackingField(IPropertySymbol property) =>
property.GetBackingFieldIfAny() != null;
private static bool ContainsBackingField(IPropertySymbol property)
=> property.GetBackingFieldIfAny() != null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册