1+ namespace StyleCop . Analyzers . Lightup
2+ {
3+ using System ;
4+ using System . Collections . Immutable ;
5+ using Microsoft . CodeAnalysis ;
6+
7+ internal readonly struct IArgumentOperationWrapper : IOperationWrapper
8+ {
9+ internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IArgumentOperation" ;
10+ private static readonly Type WrappedType ;
11+ private static readonly Func < IOperation , IParameterSymbol > ParameterAccessor ;
12+ private static readonly Func < IOperation , IOperation > ValueAccessor ;
13+ private readonly IOperation operation ;
14+ static IArgumentOperationWrapper ( )
15+ {
16+ WrappedType = OperationWrapperHelper . GetWrappedType ( typeof ( IArgumentOperationWrapper ) ) ;
17+ ParameterAccessor = LightupHelpers . CreateOperationPropertyAccessor < IOperation , IParameterSymbol > ( WrappedType , nameof ( Parameter ) ) ;
18+ ValueAccessor = LightupHelpers . CreateOperationPropertyAccessor < IOperation , IOperation > ( WrappedType , nameof ( Value ) ) ;
19+ }
20+
21+ private IArgumentOperationWrapper ( IOperation operation )
22+ {
23+ this . operation = operation ;
24+ }
25+
26+ public IOperation WrappedOperation => this . operation ;
27+ public ITypeSymbol Type => this . WrappedOperation . Type ;
28+ public object ArgumentKind => throw new NotImplementedException ( "Property 'IArgumentOperation.ArgumentKind' has unsupported type 'ArgumentKind'" ) ;
29+ public IParameterSymbol Parameter => ParameterAccessor ( this . WrappedOperation ) ;
30+ public IOperation Value => ValueAccessor ( this . WrappedOperation ) ;
31+ public object InConversion => throw new NotImplementedException ( "Property 'IArgumentOperation.InConversion' has unsupported type 'CommonConversion'" ) ;
32+ public object OutConversion => throw new NotImplementedException ( "Property 'IArgumentOperation.OutConversion' has unsupported type 'CommonConversion'" ) ;
33+ public static IArgumentOperationWrapper FromOperation ( IOperation operation )
34+ {
35+ if ( operation == null )
36+ {
37+ return default ;
38+ }
39+
40+ if ( ! IsInstance ( operation ) )
41+ {
42+ throw new InvalidCastException ( $ "Cannot cast '{ operation . GetType ( ) . FullName } ' to '{ WrappedTypeName } '") ;
43+ }
44+
45+ return new IArgumentOperationWrapper ( operation ) ;
46+ }
47+
48+ public static bool IsInstance ( IOperation operation )
49+ {
50+ return operation != null && LightupHelpers . CanWrapOperation ( operation , WrappedType ) ;
51+ }
52+ }
53+ }
0 commit comments