70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.Collections.Immutable;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal static class PropertySymbolExtensions
|
|
{
|
|
public static MethodSymbol? GetOwnOrInheritedGetMethod(this PropertySymbol? property)
|
|
{
|
|
while ((object)property != null)
|
|
{
|
|
MethodSymbol getMethod = property.GetMethod;
|
|
if ((object)getMethod != null)
|
|
{
|
|
return getMethod;
|
|
}
|
|
property = property.OverriddenProperty;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static MethodSymbol? GetOwnOrInheritedSetMethod(this PropertySymbol? property)
|
|
{
|
|
while ((object)property != null)
|
|
{
|
|
MethodSymbol setMethod = property.SetMethod;
|
|
if ((object)setMethod != null)
|
|
{
|
|
return setMethod;
|
|
}
|
|
property = property.OverriddenProperty;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static bool CanCallMethodsDirectly(this PropertySymbol property)
|
|
{
|
|
if (property.MustCallMethodsDirectly)
|
|
{
|
|
return true;
|
|
}
|
|
if (property.IsIndexedProperty)
|
|
{
|
|
if (property.IsIndexer)
|
|
{
|
|
return property.HasRefOrOutParameter();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool HasRefOrOutParameter(this PropertySymbol property)
|
|
{
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0020: Invalid comparison between Unknown and I4
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0029: Invalid comparison between Unknown and I4
|
|
ImmutableArray<ParameterSymbol>.Enumerator enumerator = property.Parameters.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
ParameterSymbol current = enumerator.Current;
|
|
if ((int)current.RefKind == 1 || (int)current.RefKind == 2)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|