Esempio n. 1
0
        async void OnRendererContextMemberReferenceRequested(object sender, MemberReferenceRequestArgs args)
        {
            // TODO: Use this in HtmlRendererBase.CreateRenderedTypeNameElement
            // Trim the monkey from submission-declared types
            var interactiveObjectTypeName = args.InteractiveObjectType.Name;

            if (interactiveObjectTypeName.StartsWith("🐵", StringComparison.Ordinal))
            {
                interactiveObjectTypeName = interactiveObjectTypeName.Substring(
                    interactiveObjectTypeName.IndexOf('+') + 1);
            }

            var buffer = new StringWriter();
            var writer = new CSharpWriter(buffer)
            {
                WriteLanguageKeywords = true
            };

            writer.VisitTypeSpec(TypeSpec.Parse(interactiveObjectTypeName));
            var interactiveObjectTypeStr = buffer.ToString();

            var eval = "var selectedMember = " +
                       $"GetObject<{interactiveObjectTypeStr}> " +
                       $"(0x{args.InteractiveObject.RepresentedObjectHandle:x})";

            if (args.MemberName != null)
            {
                eval += $".{args.MemberName}";
            }

            await EvaluateAsync(eval);
        }
Esempio n. 2
0
        /// <summary>
        /// Get a C#-compatible type name string. For example, "My.Generic+Inner`1[System.String]" becomes
        /// "My.Generic.Inner<System.String>".
        /// </summary>
        public static string GetCSharpTypeName(this Type type)
        {
            var buffer = new StringWriter();
            var writer = new CSharpWriter(buffer)
            {
                WriteLanguageKeywords = true
            };

            writer.VisitTypeSpec(TypeSpec.Create(type));
            return(buffer.ToString());
        }
Esempio n. 3
0
        static void AssertCsharp(string expectedRendering, TypeSpec typeSpec)
        {
            var buffer = new StringWriter();
            var writer = new CSharpWriter(buffer)
            {
                WriteLanguageKeywords = true
            };

            writer.VisitTypeSpec(typeSpec);
            Assert.AreEqual(expectedRendering, buffer.ToString());
        }
Esempio n. 4
0
        public override void VisitTypeSpec(TypeSpec typeSpec, bool writeByRefModifier)
        {
            var stringWriter = new StringWriter();
            var csharpWriter = new CSharpWriter(stringWriter);

            csharpWriter.VisitTypeSpec(typeSpec, writeByRefModifier);

            Writer.Write("<span class=\"typespec\" title=\"");
            Writer.WriteEscaped(stringWriter.ToString());
            Writer.Write("\">");

            base.VisitTypeSpec(typeSpec, writeByRefModifier);

            Writer.Write("</span>");
        }