forked from DotNetAnalyzers/StyleCopAnalyzers
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIAnonymousObjectCreationOperationWrapper.g.cs
More file actions
53 lines (45 loc) · 2.34 KB
/
IAnonymousObjectCreationOperationWrapper.g.cs
File metadata and controls
53 lines (45 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace StyleCop.Analyzers.Lightup
{
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
internal readonly struct IAnonymousObjectCreationOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAnonymousObjectCreationOperation";
private static readonly Type WrappedType;
private static readonly Func<IOperation, ImmutableArray<IOperation>> InitializersAccessor;
private readonly IOperation operation;
static IAnonymousObjectCreationOperationWrapper()
{
WrappedType = OperationWrapperHelper.GetWrappedType(typeof(IAnonymousObjectCreationOperationWrapper));
InitializersAccessor = LightupHelpers.CreateOperationPropertyAccessor<IOperation, ImmutableArray<IOperation>>(WrappedType, nameof(Initializers));
}
private IAnonymousObjectCreationOperationWrapper(IOperation operation)
{
this.operation = operation;
}
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> Initializers => InitializersAccessor(this.WrappedOperation);
public static explicit operator IAnonymousObjectCreationOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAnonymousObjectCreationOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAnonymousObjectCreationOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
{
return default;
}
if (!IsInstance(operation))
{
throw new InvalidCastException($"Cannot cast '{operation.GetType().FullName}' to '{WrappedTypeName}'");
}
return new IAnonymousObjectCreationOperationWrapper(operation);
}
public static bool IsInstance(IOperation operation)
{
return operation != null && LightupHelpers.CanWrapOperation(operation, WrappedType);
}
}
}