Exemplo n.º 1
0
        public void Inequality()
        {
            var foo = new NamespacePrefix("foo");
            var bar = new NamespacePrefix("bar");

            Assert.That(foo.Equals(bar), Is.False);
            Assert.That(foo.Equals((object)bar), Is.False);
        }
Exemplo n.º 2
0
        public void Equality()
        {
            Assert.That(NamespacePrefix.None.Equals(NamespacePrefix.None), Is.True);
            Assert.That(NamespacePrefix.Any.Equals(NamespacePrefix.Any), Is.True);
            Assert.That(NamespacePrefix.Empty.Equals(NamespacePrefix.Empty), Is.True);
            var foo = new NamespacePrefix("foo");

            Assert.That(foo.Equals(foo), Is.True);
            Assert.That(foo.Equals((object)foo), Is.True);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            #line 1 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            // This template creates a <PackageName>_<StructName>Struct.cs file

            #line default
            #line hidden
            this.Write(@"//---------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool. Changes to this
//     file may cause incorrect behavior and will be lost
//     if the code is regenerated.
//
//     Generated on ");

            #line 13 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedTime));

            #line default
            #line hidden
            this.Write("\r\n// </auto-generated>\r\n//-------------------------------------------------------" +
                       "--\r\nusing System;\r\nusing System.CodeDom.Compiler;\r\nusing System.Runtime.Compiler" +
                       "Services;\r\n");

            #line 19 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(Environment.NewLine, UsingStatements)));

            #line default
            #line hidden
            this.Write("\r\n");

            #line 20 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            if (!NamespacePrefix.Equals("go"))
            {
            #line default
            #line hidden
                this.Write("using go;\r\n");

            #line 22 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n");

            #line 24 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceHeader));

            #line default
            #line hidden
            this.Write("\r\n    public static partial class ");

            #line 25 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package\r\n    {\r\n        [");

            #line 27 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]");

            #line 27 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"

            foreach (string promotedStruct in PromotedStructs)
            {
                if (!string.IsNullOrEmpty(promotedStruct))
                {
            #line default
            #line hidden
                    this.Write("\r\n        [PromotedStruct(typeof(");

            #line 34 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(promotedStruct));

            #line default
            #line hidden
                    this.Write("))]");

            #line 34 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                }
            }

            #line default
            #line hidden
            this.Write("\r\n        ");

            #line 38 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" partial struct ");

            #line 38 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" : EmptyInterface\r\n        {");

            #line 39 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"

            foreach (KeyValuePair <string, List <FunctionSignature> > kvp in PromotedFunctions)
            {
                foreach (var decl in kvp.Value)
                {
            #line default
            #line hidden

            #line 44 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(new StructFuncDeclTemplate
                    {
                        PromotedField      = kvp.Key,
                        FunctionName       = decl.Name,
                        Scope              = "public",
                        ParameterSignature = decl.Signature.GenerateParametersSignature(false),
                        ParameterNames     = GetParameterNames(decl),
                        ParameterTypes     = GetParameterTypes(decl),
                        ResultType         = decl.Signature.GenerateResultSignature()
                    }
                                                                       .TransformText()));

            #line default
            #line hidden

            #line 54 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                }
            }

            foreach (KeyValuePair <string, List <FieldInfo> > kvp in PromotedFields)
            {
                FieldInfo promotedStruct = GetPromotedStruct(kvp.Key);
                bool      isPointer      = promotedStruct?.Type.IsPointer ?? false;


            #line default
            #line hidden
                this.Write("\r\n            // ");

            #line 65 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write(" structure promotion - sourced from ");

            #line 65 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(isPointer ? "pointer" : "value copy"));

            #line default
            #line hidden
                this.Write("\r\n            private readonly Ref<");

            #line 66 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write("> m_");

            #line 66 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write("Ref;\r\n\r\n            private ref ");

            #line 68 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write(" ");

            #line 68 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write("_");

            #line 68 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(isPointer ? "ptr" : "val"));

            #line default
            #line hidden
                this.Write(" => ref m_");

            #line 68 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                this.Write("Ref.Value;\r\n");

            #line 69 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"


                foreach (var decl in kvp.Value)
                {
            #line default
            #line hidden
                    this.Write("\r\n            public ref ");

            #line 75 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Type.TypeName));

            #line default
            #line hidden
                    this.Write(" ");

            #line 75 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                    this.Write(" => ref m_");

            #line 75 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(kvp.Key));

            #line default
            #line hidden
                    this.Write("Ref.Value.");

            #line 75 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                    this.Write(";\r\n");

            #line 76 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                }
            }

            if (PromotedFunctions.Count > 0)
            {
            #line default
            #line hidden
                this.Write("            \r\n            [DebuggerStepperBoundary]\r\n            static ");

            #line 85 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
                this.Write("()\r\n            {\r\n                Type targetType = typeof(");

            #line 87 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
                this.Write(");\r\n                MethodInfo extensionMethod;");

            #line 88 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"


                foreach (KeyValuePair <string, List <FunctionSignature> > kvp in PromotedFunctions)
                {
                    foreach (var decl in kvp.Value)
                    {
            #line default
            #line hidden

            #line 94 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(new StructFuncInitTemplate
                        {
                            FunctionName = decl.Name
                        }
                                                                           .TransformText()));

            #line default
            #line hidden

            #line 98 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    }
                }

            #line default
            #line hidden
                this.Write("\r\n            }\r\n");

            #line 103 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n            // Constructors\r\n            public ");

            #line 108 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(NilType _)\r\n            {");

            #line 109 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"

            foreach (var decl in StructFields)
            {
                if (PromotedStructs.Contains(decl.Type.TypeName))
                {
                    // Promoted struct

            #line default
            #line hidden
                    this.Write("\r\n                this.m_");

            #line 116 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                    this.Write("Ref = new Ref<");

            #line 116 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Type.TypeName));

            #line default
            #line hidden
                    this.Write(">(new ");

            #line 116 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Type.TypeName));

            #line default
            #line hidden
                    this.Write("(nil));");

            #line 116 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                }
                else
                {
                    // Promoted interface or normal struct field

            #line default
            #line hidden
                    this.Write("\r\n                this.");

            #line 122 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                    this.Write(" = default;");

            #line 122 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                }
            }

            #line default
            #line hidden
            this.Write("\r\n            }");

            #line 126 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"


            if (StructFields.Length > 0)
            {
            #line default
            #line hidden
                this.Write("\r\n\r\n            public ");

            #line 132 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
                this.Write("(");

            #line 132 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(", ", StructFields.Select(field => $"{(field.Type.IsPointer ? "ref " : "")}{field.Type.TypeName} {field.Name}"))));

            #line default
            #line hidden
                this.Write(")\r\n            {");

            #line 133 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"

                foreach (var decl in StructFields)
                {
                    if (PromotedStructs.Contains(decl.Type.TypeName))
                    {
                        // Promoted struct

            #line default
            #line hidden
                        this.Write("\r\n                this.m_");

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                        this.Write("Ref = new Ref<");

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Type.TypeName));

            #line default
            #line hidden
                        this.Write(">(");

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Type.IsPointer ? "ref " : ""));

            #line default
            #line hidden

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                        this.Write(");");

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    }
                    else
                    {
                        // Promoted interface or normal struct field

            #line default
            #line hidden
                        this.Write("\r\n                this.");

            #line 146 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                        this.Write(" = ");

            #line 146 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(decl.Name));

            #line default
            #line hidden
                        this.Write(";");

            #line 146 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
                    }
                }

            #line default
            #line hidden
                this.Write("\r\n            }\r\n");

            #line 151 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n            // Enable comparisons between nil and ");

            #line 154 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" struct\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n        " +
                       "    public static bool operator ==(");

            #line 156 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => value.Equals(default(");

            #line 156 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("));\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n          " +
                       "  public static bool operator !=(");

            #line 159 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => !(value == nil);\r\n\r\n            [MethodImpl(MethodImplOpt" +
                       "ions.AggressiveInlining)]\r\n            public static bool operator ==(NilType ni" +
                       "l, ");

            #line 162 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value) => value == nil;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveI" +
                       "nlining)]\r\n            public static bool operator !=(NilType nil, ");

            #line 165 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value) => value != nil;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveI" +
                       "nlining)]\r\n            public static implicit operator ");

            #line 168 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(NilType nil) => default(");

            #line 168 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(");\r\n        }\r\n\r\n        [");

            #line 171 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 172 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" static ");

            #line 172 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" ");

            #line 172 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("_cast(dynamic value)\r\n        {\r\n            return new ");

            #line 174 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(");

            #line 174 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GetConstructorParameterNames()));

            #line default
            #line hidden
            this.Write(");\r\n        }\r\n    }\r\n");

            #line 177 "C:\Projects\go2cs\src\go2cs\Templates\StructTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceFooter));

            #line default
            #line hidden
            return(this.GenerationEnvironment.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            #line 1 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            // This template creates a <PackageName>_<InterfaceName>Interface.cs file

            #line default
            #line hidden
            this.Write(@"//---------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool. Changes to this
//     file may cause incorrect behavior and will be lost
//     if the code is regenerated.
//
//     Generated on ");

            #line 13 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedTime));

            #line default
            #line hidden
            this.Write(@"
// </auto-generated>
//---------------------------------------------------------
using System;
using System.CodeDom.Compiler;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
");

            #line 22 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(Environment.NewLine, UsingStatements)));

            #line default
            #line hidden
            this.Write("\r\n");

            #line 23 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            if (!NamespacePrefix.Equals("go"))
            {
            #line default
            #line hidden
                this.Write("using go;\r\n");

            #line 25 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n#pragma warning disable CS0660, CS0661\r\n\r\n");

            #line 29 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceHeader));

            #line default
            #line hidden
            this.Write("\r\n    public static partial class ");

            #line 30 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package\r\n    {\r\n        [");

            #line 32 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 33 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" partial interface ");

            #line 33 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("\r\n        {\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining), Debug" +
                       "gerNonUserCode]\r\n            public static ");

            #line 36 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" As<T>(in T target) => (");

            #line 36 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>)target!;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining), De" +
                       "buggerNonUserCode]\r\n            public static ");

            #line 39 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" As<T>(ptr<T> target_ptr) => (");

            #line 39 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>)target_ptr;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)," +
                       " DebuggerNonUserCode]\r\n            public static ");

            #line 42 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("? As(object target) =>\r\n                typeof(");

            #line 43 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<>).CreateInterfaceHandler<");

            #line 43 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(">(target);\r\n        }\r\n\r\n        [");

            #line 46 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 47 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" class ");

            #line 47 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> : ");

            #line 47 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@"
        {
            private T m_target;
            private readonly ptr<T>? m_target_ptr;
            private readonly bool m_target_is_ptr;

            public ref T Target
            {
                get
                {
                    if (m_target_is_ptr && !(m_target_ptr is null))
                        return ref m_target_ptr.Value;

                    return ref m_target;
                }
            }

            public ");

            #line 64 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("(in T target) => m_target = target;\r\n\r\n            public ");

            #line 66 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("(ptr<T> target_ptr)\r\n            {\r\n                m_target_ptr = target_ptr;\r\n " +
                       "               m_target_is_ptr = true;\r\n            }");

            #line 70 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"


            foreach (var decl in Functions)
            {
            #line default
            #line hidden

            #line 74 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(new InterfaceFuncDeclTemplate
                {
                    FunctionName       = decl.Name,
                    Scope              = "public",
                    ParameterSignature = decl.Signature.GenerateParametersSignature(false),
                    ParameterNames     = GetParameterNames(decl),
                    ParameterTypes     = GetParameterTypeNames(decl),
                    ResultType         = decl.Signature.GenerateResultSignature()
                }
                                                                   .TransformText()));

            #line default
            #line hidden

            #line 83 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n\r\n            [DebuggerStepperBoundary]\r\n            static ");

            #line 88 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("()\r\n            {\r\n                Type targetType = typeof(T);\r\n                " +
                       "Type targetTypeByRef = targetType.MakeByRefType();\r\n                MethodInfo e" +
                       "xtensionMethod;");

            #line 92 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"


            foreach (var decl in Functions)
            {
            #line default
            #line hidden

            #line 96 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(new InterfaceFuncInitTemplate
                {
                    FunctionName  = decl.Name,
                    InterfaceName = InterfaceName
                }
                                                                   .TransformText()));

            #line default
            #line hidden

            #line 101 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n            }\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)," +
                       " DebuggerNonUserCode]\r\n            public static explicit operator ");

            #line 107 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>(in ptr<T> target_ptr) => new ");

            #line 107 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>(target_ptr);\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)" +
                       ", DebuggerNonUserCode]\r\n            public static explicit operator ");

            #line 110 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>(in T target) => new ");

            #line 110 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>(target);\r\n\r\n            // Enable comparisons between nil and ");

            #line 112 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> interface instance\r\n            [MethodImpl(MethodImplOptions.AggressiveInlin" +
                       "ing)]\r\n            public static bool operator ==(");

            #line 114 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value, NilType nil) => Activator.CreateInstance<");

            #line 114 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>>().Equals(value);\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInli" +
                       "ning)]\r\n            public static bool operator !=(");

            #line 117 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value, NilType nil) => !(value == nil);\r\n\r\n            [MethodImpl(MethodImpl" +
                       "Options.AggressiveInlining)]\r\n            public static bool operator ==(NilType" +
                       " nil, ");

            #line 120 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value) => value == nil;\r\n\r\n            [MethodImpl(MethodImplOptions.Aggressi" +
                       "veInlining)]\r\n            public static bool operator !=(NilType nil, ");

            #line 123 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value) => value != nil;\r\n        }\r\n    }\r\n");

            #line 126 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceFooter));

            #line default
            #line hidden
            this.Write("\r\n\r\nnamespace go\r\n{\r\n    public static class ");

            #line 130 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_");

            #line 130 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("Extensions\r\n    {\r\n        private static readonly ConcurrentDictionary<Type, Met" +
                       "hodInfo> s_conversionOperators = new ConcurrentDictionary<Type, MethodInfo>();\r\n" +
                       "\r\n        [");

            #line 134 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static T _<T>(this ");

            #line 135 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 135 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 135 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" target)\r\n        {\r\n            try\r\n            {\r\n                return ((");

            #line 139 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 139 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 139 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@"<T>)target).Target;
            }
            catch (NotImplementedException ex)
            {
                throw new PanicException($""interface conversion: {GetGoTypeName(target.GetType())} is not {GetGoTypeName(typeof(T))}: missing method {ex.InnerException?.Message}"");
            }
        }

        [");

            #line 147 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static bool _<T>(this ");

            #line 148 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 148 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 148 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@" target, out T result)
        {
            try
            {
                result = target._<T>();
                return true;
            }
            catch (PanicException)
            {
                result = default!;
                return false;
            }
        }

        [");

            #line 162 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static object? _(this ");

            #line 163 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 163 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 163 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" target, Type type)\r\n        {\r\n            try\r\n            {\r\n                M" +
                       "ethodInfo? conversionOperator = s_conversionOperators.GetOrAdd(type, _ => typeof" +
                       "(");

            #line 167 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 167 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 167 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@"<>).GetExplicitGenericConversionOperator(type));

                if (conversionOperator is null)
                    throw new PanicException($""interface conversion: failed to create converter for {GetGoTypeName(target.GetType())} to {GetGoTypeName(type)}"");

                dynamic? result = conversionOperator.Invoke(null, new object[] { target });
                return result?.Target;
            }
            catch (NotImplementedException ex)
            {
                throw new PanicException($""interface conversion: {GetGoTypeName(target.GetType())} is not {GetGoTypeName(type)}: missing method {ex.InnerException?.Message}"");
            }
        }

        [");

            #line 181 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static bool _(this ");

            #line 182 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 182 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 182 "C:\Projects\go2cs\src\go2cs.Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@" target, Type type, out object? result)
        {
            try
            {
                result = target._(type);
                return true;
            }
            catch (PanicException)
            {
                result = type.IsValueType ? Activator.CreateInstance(type) : null;
                return false;
            }
        }
    }
}");
            return(this.GenerationEnvironment.ToString());
        }
Exemplo n.º 5
0
 public void Inequality()
 {
     var foo = new NamespacePrefix("foo");
     var bar = new NamespacePrefix("bar");
     Assert.That(foo.Equals(bar), Is.False);
     Assert.That(foo.Equals((object)bar), Is.False);
 }
Exemplo n.º 6
0
 public void Equality()
 {
     Assert.That(NamespacePrefix.None.Equals(NamespacePrefix.None), Is.True);
     Assert.That(NamespacePrefix.Any.Equals(NamespacePrefix.Any), Is.True);
     Assert.That(NamespacePrefix.Empty.Equals(NamespacePrefix.Empty), Is.True);
     var foo = new NamespacePrefix("foo");
     Assert.That(foo.Equals(foo), Is.True);
     Assert.That(foo.Equals((object) foo), Is.True);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            #line 1 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            // This template creates an inherited type, e.g., type MyFloat float64 in a <PackageName>_<StructName>StructOf(<GoTypeName>).cs file

            #line default
            #line hidden
            this.Write(@"//---------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool. Changes to this
//     file may cause incorrect behavior and will be lost
//     if the code is regenerated.
//
//     Generated on ");

            #line 10 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedTime));

            #line default
            #line hidden
            this.Write("\r\n// </auto-generated>\r\n//-------------------------------------------------------" +
                       "--\r\nusing System.CodeDom.Compiler;\r\nusing System.Runtime.CompilerServices;\r\n");

            #line 15 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            if (!NamespacePrefix.Equals("go"))
            {
            #line default
            #line hidden
                this.Write("using go;\r\n");

            #line 17 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n#nullable enable\r\n\r\n");

            #line 21 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceHeader));

            #line default
            #line hidden
            this.Write("\r\n    public static partial class ");

            #line 22 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package\r\n    {\r\n        [");

            #line 24 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 25 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" partial struct ");

            #line 25 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("\r\n        {\r\n            // Value of the ");

            #line 27 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" struct\r\n            private readonly ");

            #line 28 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(TypeName));

            #line default
            #line hidden
            this.Write(" m_value;\r\n\r\n            public ");

            #line 30 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(");

            #line 30 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(TypeName));

            #line default
            #line hidden
            this.Write(" value) => m_value = value;\r\n\r\n            // Enable implicit conversions between" +
                       " ");

            #line 32 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(TypeName));

            #line default
            #line hidden
            this.Write(" and ");

            #line 32 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" struct\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n        " +
                       "    public static implicit operator ");

            #line 34 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(");

            #line 34 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(TypeName));

            #line default
            #line hidden
            this.Write(" value) => new ");

            #line 34 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(value);\r\n            \r\n            [MethodImpl(MethodImplOptions.AggressiveInlin" +
                       "ing)]\r\n            public static implicit operator ");

            #line 37 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(TypeName));

            #line default
            #line hidden
            this.Write("(");

            #line 37 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value) => value.m_value;\r\n            \r\n            // Enable comparisons betwee" +
                       "n nil and ");

            #line 39 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" struct\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n        " +
                       "    public static bool operator ==(");

            #line 41 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => value.Equals(default(");

            #line 41 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("));\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n          " +
                       "  public static bool operator !=(");

            #line 44 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => !(value == nil);\r\n\r\n            [MethodImpl(MethodImplOpt" +
                       "ions.AggressiveInlining)]\r\n            public static bool operator ==(NilType ni" +
                       "l, ");

            #line 47 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value) => value == nil;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveI" +
                       "nlining)]\r\n            public static bool operator !=(NilType nil, ");

            #line 50 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(" value) => value != nil;\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveI" +
                       "nlining)]\r\n            public static implicit operator ");

            #line 53 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write("(NilType nil) => default(");

            #line 53 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(StructName));

            #line default
            #line hidden
            this.Write(");\r\n        }\r\n    }\r\n");

            #line 56 "D:\Projects\go2cs\src\go2cs.Templates\InheritedTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceFooter));

            #line default
            #line hidden
            this.Write("\r\n");
            return(this.GenerationEnvironment.ToString());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            #line 1 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            // This template creates a <PackageName>_<InterfaceName>Interface.cs file

            #line default
            #line hidden
            this.Write(@"//---------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool. Changes to this
//     file may cause incorrect behavior and will be lost
//     if the code is regenerated.
//
//     Generated on ");

            #line 13 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedTime));

            #line default
            #line hidden
            this.Write(@"
// </auto-generated>
//---------------------------------------------------------
using System;
using System.CodeDom.Compiler;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
");

            #line 22 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(Environment.NewLine, UsingStatements)));

            #line default
            #line hidden
            this.Write("\r\n");

            #line 23 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            if (!NamespacePrefix.Equals("go"))
            {
            #line default
            #line hidden
                this.Write("using go;\r\n");

            #line 25 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n#pragma warning disable CS0660, CS0661\r\n\r\n");

            #line 29 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceHeader));

            #line default
            #line hidden
            this.Write("\r\n    public static partial class ");

            #line 30 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package\r\n    {\r\n        [");

            #line 32 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 33 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" partial interface ");

            #line 33 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" : EmptyInterface\r\n        {\r\n        }\r\n\r\n        [");

            #line 37 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write("]\r\n        ");

            #line 38 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" struct ");

            #line 38 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> : ");

            #line 38 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("\r\n        {\r\n            private T m_target;\r\n\r\n            public T Target => m_" +
                       "target;");

            #line 42 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"


            foreach (var decl in Functions)
            {
            #line default
            #line hidden

            #line 46 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(new InterfaceFuncDeclTemplate
                {
                    FunctionName       = decl.Name,
                    Scope              = "public",
                    ParameterSignature = decl.Signature.GenerateParametersSignature(false),
                    ParameterNames     = GetParameterNames(decl),
                    ParameterTypes     = GetParameterTypes(decl),
                    ResultType         = decl.Signature.GenerateResultSignature()
                }
                                                                   .TransformText()));

            #line default
            #line hidden

            #line 55 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n\r\n            [DebuggerStepperBoundary]\r\n            static ");

            #line 60 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("()\r\n            {\r\n                Type targetType = typeof(T);\r\n                " +
                       "MethodInfo extensionMethod;");

            #line 63 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"


            foreach (var decl in Functions)
            {
            #line default
            #line hidden

            #line 67 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(new InterfaceFuncInitTemplate
                {
                    FunctionName  = decl.Name,
                    InterfaceName = InterfaceName
                }
                                                                   .TransformText()));

            #line default
            #line hidden

            #line 72 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\n            }\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInlining)," +
                       " DebuggerNonUserCode]\r\n            public static explicit operator ");

            #line 78 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>(T target) => new ");

            #line 78 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> { m_target = target };\r\n\r\n            // Enable comparisons between nil and ");

            #line 80 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> interface instance\r\n            [MethodImpl(MethodImplOptions.AggressiveInlin" +
                       "ing)]\r\n            public static bool operator ==(");

            #line 82 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value, NilType nil) => Activator.CreateInstance<");

            #line 82 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>>().Equals(value);\r\n\r\n            [MethodImpl(MethodImplOptions.AggressiveInli" +
                       "ning)]\r\n            public static bool operator !=(");

            #line 85 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value, NilType nil) => !(value == nil);\r\n\r\n            [MethodImpl(MethodImpl" +
                       "Options.AggressiveInlining)]\r\n            public static bool operator ==(NilType" +
                       " nil, ");

            #line 88 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value) => value == nil;\r\n\r\n            [MethodImpl(MethodImplOptions.Aggressi" +
                       "veInlining)]\r\n            public static bool operator !=(NilType nil, ");

            #line 91 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T> value) => value != nil;\r\n        }\r\n\r\n        [");

            #line 94 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " ");

            #line 95 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Scope));

            #line default
            #line hidden
            this.Write(" static ");

            #line 95 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" ");

            #line 95 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("_cast<T>(T target)\r\n        {\r\n            if (typeof(");

            #line 97 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(").IsAssignableFrom(typeof(T)))\r\n                return target as ");

            #line 98 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(";\r\n\r\n            return (");

            #line 100 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("<T>)target;\r\n        }\r\n    }\r\n");

            #line 103 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespaceFooter));

            #line default
            #line hidden
            this.Write("\r\n\r\nnamespace go\r\n{\r\n    public partial class NilType\r\n    {\r\n        // Enable c" +
                       "omparisons between nil and ");

            #line 109 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" interface\r\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n        p" +
                       "ublic static bool operator ==(");

            #line 111 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 111 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 111 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => (object)value == null || Activator.CreateInstance(value.G" +
                       "etType()).Equals(value);\r\n\r\n        [MethodImpl(MethodImplOptions.AggressiveInli" +
                       "ning)]\r\n        public static bool operator !=(");

            #line 114 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 114 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 114 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" value, NilType nil) => !(value == nil);\r\n\r\n        [MethodImpl(MethodImplOptions" +
                       ".AggressiveInlining)]\r\n        public static bool operator ==(NilType nil, ");

            #line 117 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 117 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 117 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" value) => value == nil;\r\n\r\n        [MethodImpl(MethodImplOptions.AggressiveInlin" +
                       "ing)]\r\n        public static bool operator !=(NilType nil, ");

            #line 120 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 120 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 120 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" value) => value != nil;\r\n    }\r\n\r\n    public static class ");

            #line 123 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_");

            #line 123 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write("Extensions\r\n    {\r\n        private static readonly ConcurrentDictionary<Type, Met" +
                       "hodInfo> s_conversionOperators = new ConcurrentDictionary<Type, MethodInfo>();\r\n" +
                       "\r\n        [");

            #line 127 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static T TypeAssert<T>(this ");

            #line 128 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 128 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 128 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" target)\r\n        {\r\n            try\r\n            {\r\n                return ((");

            #line 132 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 132 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 132 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@"<T>)target).Target;
            }
            catch (NotImplementedException ex)
            {
                throw new PanicException($""panic: interface conversion: {target.GetType().FullName} is not {typeof(T).FullName}: missing method {ex.InnerException?.Message}"");
            }
        }

        [");

            #line 140 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static bool TryTypeAssert<T>(this ");

            #line 141 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 141 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 141 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@" target, out T result)
        {
            try
            {
                result = target.TypeAssert<T>();
                return true;
            }
            catch (PanicException)
            {
                result = default(T);
                return false;
            }
        }

        [");

            #line 155 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static object TypeAssert(this ");

            #line 156 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 156 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 156 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(" target, Type type)\r\n        {\r\n            try\r\n            {\r\n                M" +
                       "ethodInfo conversionOperator = s_conversionOperators.GetOrAdd(type, _ => typeof(" +
                       "");

            #line 160 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 160 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 160 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@"<>).GetExplicitGenericConversionOperator(type));

                if ((object)conversionOperator == null)
                    throw new PanicException($""panic: interface conversion: failed to create converter for {target.GetType().FullName} to {type.FullName}"");

                dynamic result = conversionOperator.Invoke(null, new object[] { target });
                return result.Target;
            }
            catch (NotImplementedException ex)
            {
                throw new PanicException($""panic: interface conversion: {target.GetType().FullName} is not {type.FullName}: missing method {ex.InnerException?.Message}"");
            }
        }

        [");

            #line 174 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(GeneratedCodeAttribute));

            #line default
            #line hidden
            this.Write(", MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerNonUserCode]\r\n       " +
                       " public static bool TryTypeAssert(this ");

            #line 175 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(NamespacePrefix));

            #line default
            #line hidden
            this.Write(".");

            #line 175 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(PackageName));

            #line default
            #line hidden
            this.Write("_package.");

            #line 175 "C:\Projects\go2cs\src\go2cs\Templates\InterfaceTypeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName));

            #line default
            #line hidden
            this.Write(@" target, Type type, out object result)
        {
            try
            {
                result = target.TypeAssert(type);
                return true;
            }
            catch (PanicException)
            {
                result = type.IsValueType ? Activator.CreateInstance(type) : null;
                return false;
            }
        }
    }
}");
            return(this.GenerationEnvironment.ToString());
        }