remarks generate example c# roslyn

c# - generate - Operaciones rebajadas en roslyn



params comments c# (2)

Diferente ángulo en esta respuesta: ¿qué pasa con este aspecto del compilador?

InternalVisibleTo Attribute

enlace: https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx

¿Podría ser un tema interesante de conversación relacionado con un "ángulo diferente" para utilizar para abordar la depuración?

MÁS INFORMACIÓN (del artículo):

Información de versión

Plataforma universal de Windows disponible desde 8 .NET Framework
Disponible desde 2.0 Portable Class Library
Compatible con: plataformas portátiles .NET Silverlight
Disponible desde 2.0 Windows Phone Silverlight
Disponible desde 7.0 Windows Phone
Disponible desde 8.1

Cuando se introdujeron las operaciones en Roslyn, uno de los objetivos era proporcionar operaciones reducidas (creo que fue en un video de reunión de revisión de diseño) que, por lo que entiendo, debería proporcionar operaciones explícitas para acciones de compilación implícitas en las de alto nivel. Veo el directorio de reducción en Roslyn, pero las clases son internas allí. ¿Es posible obtener operaciones reducidas ahora o aún no hay API pública disponible?

En el ejemplo a continuación, las operaciones ya eliminan algunas partes implícitas: agregan la declaración de retorno para el cuerpo de expresión y exponen el símbolo para el operador sobrecargado. Pero los incrementos previos y posteriores difieren solo por tipo.

using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Semantics; using System.Linq; namespace so39468373 { internal static class Program { private static void Main() { var tree = CSharpSyntaxTree.ParseText(@" public class c { public static c operator ++(c o) { return o; } static c pre(c o) => ++o; static c post(c o) => o++; public static void Main() {} }"); var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); var compilation = CSharpCompilation.Create(null, new[] { tree }, new[] { mscorlib }); var model = compilation.GetSemanticModel(tree); foreach (var node in tree.GetRoot().DescendantNodes().OfType<ArrowExpressionClauseSyntax>()) { var operation = model.GetOperation(node); var block = (IBlockStatement)operation; var statement = (IReturnStatement)block.Statements.First(); var increment = (IIncrementExpression)statement.ReturnedValue; // How to get lowered operations for increment here? } } } }

Código en github - https://github.com/isanych/so-39468373


Mira este ejemplo te ayudará a resolver su problema

using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp { /// <summary> /// The dynamic operation factories below return this struct so that the caller /// have the option of separating the call-site initialization from its invocation. /// /// Most callers just call <see cref="ToExpression"/> to get the combo but some (object and array initializers) /// hoist all call-site initialization code and emit multiple invocations of the same site. /// </summary> internal struct LoweredDynamicOperation { private readonly SyntheticBoundNodeFactory _factory; private readonly TypeSymbol _resultType; private readonly ImmutableArray<LocalSymbol> _temps; public readonly BoundExpression SiteInitialization; public readonly BoundExpression SiteInvocation; public LoweredDynamicOperation(SyntheticBoundNodeFactory factory, BoundExpression siteInitialization, BoundExpression siteInvocation, TypeSymbol resultType, ImmutableArray<LocalSymbol> temps) { _factory = factory; _resultType = resultType; _temps = temps; this.SiteInitialization = siteInitialization; this.SiteInvocation = siteInvocation; } public static LoweredDynamicOperation Bad( BoundExpression loweredReceiver, ImmutableArray<BoundExpression> loweredArguments, BoundExpression loweredRight, TypeSymbol resultType) { var children = ArrayBuilder<BoundNode>.GetInstance(); children.AddOptional(loweredReceiver); children.AddRange(loweredArguments); children.AddOptional(loweredRight); return LoweredDynamicOperation.Bad(resultType, children.ToImmutableAndFree()); } public static LoweredDynamicOperation Bad(TypeSymbol resultType, ImmutableArray<BoundNode> children) { Debug.Assert(children.Length > 0); var bad = new BoundBadExpression(children[0].Syntax, LookupResultKind.Empty, ImmutableArray<Symbol>.Empty, children, resultType); return new LoweredDynamicOperation(null, null, bad, resultType, default(ImmutableArray<LocalSymbol>)); } public BoundExpression ToExpression() { if (_factory == null) { Debug.Assert(SiteInitialization == null && SiteInvocation is BoundBadExpression && _temps.IsDefaultOrEmpty); return SiteInvocation; } // TODO (tomat): we might be able to use SiteInvocation.Type instead of resultType once we stop using GetLoweredType if (_temps.IsDefaultOrEmpty) { return _factory.Sequence(new[] { SiteInitialization }, SiteInvocation, _resultType); } else { return new BoundSequence(_factory.Syntax, _temps, ImmutableArray.Create(SiteInitialization), SiteInvocation, _resultType) { WasCompilerGenerated = true }; } } } }