public static SafeIdentifier ( string proposedName ) : string | ||
proposedName | string | |
return | string |
private void WriteParameters(IList <Parameter> parameters) { for (var i = 0; i < parameters.Count; i++) { if (i != 0) { Write(", "); } var type = CSharpLanguage.TypeName(Generator.CppTypeToManaged(parameters [i].Type), Context.Parameter); var mangleAs = parameters [i].Type.ToString(); if (mangleAs != "" && mangleAs != type) { Write("[MangleAs (\"{0}\")] ", mangleAs); } if (Generator.IsByVal(parameters [i].Type)) { Write("[ByVal] "); } if (Generator.IsByVal(parameters [i].Type)) { Write("[ByVal] "); } if (Generator.IsCppType(parameters [i].Type)) { Write("[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (" + type + ".Marshaler))] "); } Write(type); Write(" "); Write(CSharpLanguage.SafeIdentifier(parameters [i].Name)); } }
private void WriteParameters(IList <Parameter> parameters, bool writeType, bool writeAttributes) { for (var i = 0; i < parameters.Count; i++) { if (i != 0) { Write(", "); } var type = CSharpLanguage.TypeName(Generator.CppTypeToManaged(parameters [i].Type), Context.Parameter); if (writeAttributes) { var mangleAs = parameters [i].Type.ToString(); if (mangleAs != "" && mangleAs != type) { Write("[MangleAs (\"{0}\")] ", mangleAs); } if (Generator.IsByVal(parameters [i].Type)) { Write("[ByVal] "); } } if (writeType) { Write(type); Write(" "); } else { if (type.StartsWith("ref ")) { Write("ref "); } } Write(CSharpLanguage.SafeIdentifier(parameters [i].Name)); } }
public override string TransformText() { this.GenerationEnvironment = null; #line 6 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" var hasBase = Class.BaseClasses.Count > 0; var wrapper = Class.Name; var iface = "I" + Class.Name; var layout = "_" + Class.Name; var layoutClass = (hasBase? "\t: base (impl.TypeInfo)\n\t\t{" : "{") + "\n\t\t\t__cxxi_LayoutClass ();"; var overrideInitBases = Generator.CheckPrimaryBases(Class, c => c.BaseClasses.Count > 1); var initBases = ((overrideInitBases || Class.BaseClasses.Count > 1) ? "\t__cxxi_InitBases ();\n\t\t}" : "}"); var @namespace = Generator.Lib.BaseNamespace + (Class.ParentNamespace != null? "." + string.Join(".", Class.ParentNamespace.FullyQualifiedName) : ""); if (!Nested) { #line default #line hidden #line 18 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("// -------------------------------------------------------------------------\n// Managed wrapper for "); #line default #line hidden #line 19 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Class.Name)); #line default #line hidden #line 19 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n// Generated from "); #line default #line hidden #line 20 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Path.GetFileName(Generator.InputFileName))); #line default #line hidden #line 20 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" on "); #line default #line hidden #line 20 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now)); #line default #line hidden #line 20 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n//\n// This file was auto generated. Do not edit.\n// -------------------------------------------------------------------------\n\nusing System;\nusing Mono.Cxxi;\n\nnamespace "); #line default #line hidden #line 28 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(@namespace)); #line default #line hidden #line 28 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" {\n"); #line default #line hidden #line 29 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } /* if !Nested */ #line default #line hidden #line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\tpublic partial class "); #line default #line hidden #line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" : "); #line default #line hidden #line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetBaseString())); #line default #line hidden #line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" {\n\n\t\tprivate static readonly "); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(iface)); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" impl = Libs."); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Generator.Lib.BaseName)); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(".GetClass<"); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(iface + "," + layout + "," + wrapper)); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("> (\""); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Class.Name)); #line default #line hidden #line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\");\n"); #line default #line hidden #line 33 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" if (!hasBase) { #line default #line hidden #line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\tpublic CppInstancePtr Native { get; protected set; }\n"); #line default #line hidden #line 35 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 36 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 37 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Interface */ #line default #line hidden #line 38 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t[MangleAs (\""); #line default #line hidden #line 38 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Class.MangleType.ToString())); #line default #line hidden #line 38 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\")]\n\t\tpublic partial interface "); #line default #line hidden #line 39 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(iface)); #line default #line hidden #line 39 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" : ICppClassOverridable<"); #line default #line hidden #line 39 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 39 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("> {\n"); #line default #line hidden #line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t\t"); foreach (var method in Class.Methods) { Write(CurrentIndent); if (method.IsVirtual) { Write("[Virtual] "); } if (method.IsStatic) { Write("[Static] "); } if (method.IsArtificial) { Write("[Artificial] "); } if (method.IsInline) { Write("[Inline] "); } if (method.IsConst) { Write("[Const] "); } if (method.IsConstructor) { Write("[Constructor] "); } if (method.IsDestructor) { Write("[Destructor] "); } if (method.IsCopyCtor) { Write("[CopyConstructor] "); } if (Generator.IsByVal(method.ReturnType)) { Write("[return: ByVal] "); } if (method.IsConstructor) { Write("CppInstancePtr"); } else { Write(CSharpLanguage.TypeName(Generator.CppTypeToManaged(method.ReturnType), Context.Interface | Context.Return)); } Write(" "); Write(CSharpLanguage.SafeIdentifier(method.Name)); Write(" ("); if (!method.IsStatic) { Write("CppInstancePtr @this"); if (method.Parameters.Count != 0) { Write(", "); } } WriteParameters(method.Parameters, true, !method.IsVirtual); Write(");\n"); } foreach (var field in Class.Fields.Where(f => f.Access != Access.@private)) { WriteLine("CppField<{0}> {1} {{ get; }}", CSharpLanguage.TypeName(Generator.CppTypeToManaged(field.Type), Context.Interface | Context.Generic), CSharpLanguage.SafeIdentifier(field.Name)); } PopIndent(); #line default #line hidden #line 77 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t}\n"); #line default #line hidden #line 78 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Native layout */ #line default #line hidden #line 79 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\tpublic unsafe struct "); #line default #line hidden #line 79 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(layout)); #line default #line hidden #line 79 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" {\n"); #line default #line hidden #line 80 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t\t"); foreach (var field in Class.Fields) { // handle byval fields var fieldType = CSharpLanguage.TypeName(Generator.CppTypeToManaged(field.Type), Context.Generic); if (Generator.GetFilterOrDefault(field.Type).ImplType == ImplementationType.@class && Generator.IsByVal(field.Type)) { fieldType = fieldType + "._" + fieldType; } // handle fixed-length arrays var array = field.Type.Modifiers.OfType <CppModifiers.ArrayModifier> ().SingleOrDefault(); //FIXME: Handle more than one? if (array != null && array.Size.HasValue) { fieldType = fieldType.TrimEnd('[', ']'); WriteLine("public fixed {0} {1} [{2}];", fieldType, CSharpLanguage.SafeIdentifier(field.Name), array.Size.Value); } else { WriteLine("public {0} {1};", fieldType, CSharpLanguage.SafeIdentifier(field.Name)); } } PopIndent(); #line default #line hidden #line 97 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t}\n\n"); #line default #line hidden #line 99 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Native fields */ #line default #line hidden #line 100 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t"); foreach (var field in Class.Fields.Where(f => f.Access != Access.@private)) { var fieldName = CSharpLanguage.SafeIdentifier(field.Name); WriteLine("{0} {1} {2} {{", field.Access, CSharpLanguage.TypeName(Generator.CppTypeToManaged(field.Type), Context.Wrapper | Context.Return), fieldName); #line default #line hidden #line 104 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\tget {\n\t\t\t\treturn impl."); #line default #line hidden #line 105 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(fieldName)); #line default #line hidden #line 105 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" [Native];\n\t\t\t}\n\t\t\tset {\n\t\t\t\timpl."); #line default #line hidden #line 108 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(fieldName)); #line default #line hidden #line 108 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" [Native] = value;\n\t\t\t}\n\t\t}\n"); #line default #line hidden #line 111 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } PopIndent(); #line default #line hidden #line 112 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 113 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Nested classes */ #line default #line hidden #line 114 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" foreach (var klass in Class.NestedClasses) { var nestedTempl = new CSharpClass { Generator = this.Generator, Class = klass, Nested = true }; Write(nestedTempl.TransformText()); } #line default #line hidden #line 122 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 123 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Nested enums */ #line default #line hidden #line 124 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" foreach (var @enum in Class.NestedEnums) { Generator.EnumTemplate.Generator = Generator; Generator.EnumTemplate.Enum = @enum; Generator.EnumTemplate.Nested = true; Write(Generator.EnumTemplate.TransformText()); } #line default #line hidden #line 130 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 131 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Subclass constructor */ #line default #line hidden #line 132 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\tpublic "); #line default #line hidden #line 132 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 132 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" (CppTypeInfo subClass)\n\t\t"); #line default #line hidden #line 133 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(layoutClass)); #line default #line hidden #line 133 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n\t\t\tsubClass.AddBase (impl.TypeInfo);\n\t\t}\n\n"); #line default #line hidden #line 137 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Native constructor */ #line default #line hidden #line 138 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\tpublic "); #line default #line hidden #line 138 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 138 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" (CppInstancePtr native)\n\t\t"); #line default #line hidden #line 139 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(layoutClass)); #line default #line hidden #line 139 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n\t\t\tNative = native;\n\t\t"); #line default #line hidden #line 141 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(initBases)); #line default #line hidden #line 141 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n\n"); #line default #line hidden #line 143 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Wrapper methods */ #line default #line hidden #line 144 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t"); foreach (var method in Class.Methods.Where(m => m.GenWrapperMethod)) { var methodName = CSharpLanguage.SafeIdentifier(method.Name); WriteMethodHeader(method, layoutClass, false, false); if (method.IsConstructor) { Write("Native = "); } Write("impl.{0} (", methodName); if (!method.IsStatic) { if (method.IsConstructor) { Write("impl.Alloc (this)"); } else { Write("Native"); } if (method.Parameters.Count != 0) { Write(", "); } } WriteParameters(method.Parameters, false, false); Write(");\n"); PopIndent(); if (method.IsConstructor) { WriteLine(initBases); } else { WriteLine("}"); } } PopIndent(); #line default #line hidden #line 172 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 173 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Wrapper properties */ #line default #line hidden #line 174 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t"); foreach (var prop in Class.Properties) { var propName = CSharpLanguage.SafeIdentifier(prop.Name); var type = CSharpLanguage.TypeName(Generator.CppTypeToManaged(prop.Type), Context.Wrapper | Context.Return); Write(CurrentIndent + "public "); if ((prop.GetMethod == null || prop.GetMethod.IsVirtual) && (prop.SetMethod == null || prop.SetMethod.IsVirtual)) { Write("virtual "); } Write(type); Write(" "); Write(propName); Write(" {\n"); PushIndent("\t"); Write(CurrentIndent); if (prop.GetMethod != null) { if (prop.GetMethod.IsVirtual) { Write("[OverrideNative (\"{0}\")] ", prop.GetMethod.Name); } Write("get {\n"); PushIndent("\t"); WriteLine("return impl.{0} (Native);", prop.GetMethod.Name); PopIndent(); WriteLine("}"); } if (prop.SetMethod != null) { if (prop.SetMethod.IsVirtual) { Write("[OverrideNative (\"{0}\")] ", prop.SetMethod.Name); } WriteLine("set {"); PushIndent("\t"); WriteLine("impl.{0} (Native, value);", prop.SetMethod.Name); PopIndent(); WriteLine("}"); } PopIndent(); WriteLine("}\n"); } PopIndent(); #line default #line hidden #line 218 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n\t\tpartial void BeforeDestruct ();\n\t\tpartial void AfterDestruct ();\n\n\t\tpublic "); #line default #line hidden #line 222 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(hasBase? "override" : "virtual")); #line default #line hidden #line 222 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" void Dispose ()\n\t\t{\n\t\t\tBeforeDestruct ();\n"); #line default #line hidden #line 225 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" if (Class.Methods.Any(m => m.IsDestructor && !m.IsArtificial)) { #line default #line hidden #line 226 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\timpl.Destruct (Native);\n"); #line default #line hidden #line 227 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 228 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\tNative.Dispose ();\n\t\t\tAfterDestruct ();\n\t\t}\n\n\t\tprivate void __cxxi_LayoutClass ()\n\t\t{\n"); #line default #line hidden #line 234 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" foreach (var npBase in Class.BaseClasses.Skip(1)) { #line default #line hidden #line 235 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\tnew "); #line default #line hidden #line 235 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 235 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" (impl.TypeInfo);\n"); #line default #line hidden #line 236 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 237 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\timpl.TypeInfo.CompleteType ();\n\t\t}\n\n"); #line default #line hidden #line 240 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Make this wrapper castable to non-primary bases */ foreach (var npBase in Class.BaseClasses.Skip(1)) { #line default #line hidden #line 242 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n#region Non-primary base class implementation for "); #line default #line hidden #line 243 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 243 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n\t\tprivate class "); #line default #line hidden #line 244 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper + "__" + npBase.Name)); #line default #line hidden #line 244 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" : "); #line default #line hidden #line 244 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 244 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" {\n\t\t\tpublic "); #line default #line hidden #line 245 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 245 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" instance;\n\t\t\tpublic "); #line default #line hidden #line 246 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper + "__" + npBase.Name)); #line default #line hidden #line 246 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" ("); #line default #line hidden #line 246 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 246 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" instance)\n\t\t\t\t: base ("); #line default #line hidden #line 247 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 247 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(".impl.TypeInfo.Cast (instance, typeof ("); #line default #line hidden #line 247 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 247 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(")))\n\t\t\t{\n\t\t\t\t"); #line default #line hidden #line 249 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 249 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(".impl.TypeInfo.InitNonPrimaryBase (this, instance, typeof ("); #line default #line hidden #line 249 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 249 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("));\n\t\t\t\tthis.instance = instance;\n\t\t\t}\n\n"); #line default #line hidden #line 253 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t\t"); foreach (var method in npBase.Methods.Where(m => m.IsVirtual)) { if (!method.GenWrapperMethod || Class.Methods.Any(m => m.Node.CheckValue("overrides", method.Node.Id))) { continue; } /* this is the managed override that has to call the subclass's method */ WriteMethodHeader(method, null, true, false); Write("instance.{0} (", npBase.Name + "__" + method.FormattedName); WriteParameters(method.Parameters, false, false); PopIndent(); Write(");\n{0}}}\n\n", CurrentIndent); /* this is the method that calls the base implementation that the subclass will use */ WriteMethodHeader(method, npBase.Name + "__" + method.FormattedName, true, false); Write("base.{0} (", method.FormattedName); WriteParameters(method.Parameters, false, false); PopIndent(); Write(");\n{0}}}\n\n", CurrentIndent); } PopIndent(); #line default #line hidden #line 278 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t}\n\t\tprivate "); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("__"); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" __cxxi_"); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 279 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(";\n\t\tpublic "); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" "); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" { get { return __cxxi_"); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 280 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("; } }\n\t\tpublic static implicit operator "); #line default #line hidden #line 281 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 281 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("("); #line default #line hidden #line 281 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 281 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" subClass)\n\t\t{\n\t\t\treturn subClass."); #line default #line hidden #line 283 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 283 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(";\n\t\t}\n\t\tpublic static explicit operator "); #line default #line hidden #line 285 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper)); #line default #line hidden #line 285 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("("); #line default #line hidden #line 285 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 285 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" baseClass)\n\t\t{\n\t\t\tif (baseClass == null) return null;\n\t\t\tvar obj = baseClass as "); #line default #line hidden #line 288 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper + "__" + npBase.Name)); #line default #line hidden #line 288 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(";\n\t\t\tif (obj == null) throw new InvalidCastException ();\n\t\t\treturn obj.instance;\n\t\t}\n\n"); #line default #line hidden #line 293 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" /* Add virtual methods of non-primary bases to this class proper so they can be overridden */ #line default #line hidden #line 294 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" PushIndent("\t\t"); foreach (var method in npBase.Methods.Where(m => m.IsVirtual)) { if (!method.GenWrapperMethod || Class.Methods.Any(m => m.Node.CheckValue("overrides", method.Node.Id))) { continue; } WriteMethodHeader(method, npBase.Name + "__" + method.FormattedName, true, true); Write("{0}.{1} (", "__cxxi_" + npBase.Name, npBase.Name + "__" + method.FormattedName); WriteParameters(method.Parameters, false, false); PopIndent(); Write(");\n{0}}}\n\n", CurrentIndent); } PopIndent(); WriteLine("#endregion"); } if (overrideInitBases || Class.BaseClasses.Count > 1) { #line default #line hidden #line 313 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\tprotected "); #line default #line hidden #line 313 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(overrideInitBases ? "override" : "virtual")); #line default #line hidden #line 313 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" void __cxxi_InitBases ()\n\t\t{\n\t\t\t"); #line default #line hidden #line 315 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(overrideInitBases? "base.__cxxi_InitBases ();" : "")); #line default #line hidden #line 315 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden #line 316 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" foreach (var npBase in Class.BaseClasses.Skip(1)) { #line default #line hidden #line 317 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t\t__cxxi_"); #line default #line hidden #line 317 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(npBase.Name)); #line default #line hidden #line 317 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" = new "); #line default #line hidden #line 317 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(this.ToStringHelper.ToStringWithCulture(wrapper + "__" + npBase.Name)); #line default #line hidden #line 317 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write(" (this);\n"); #line default #line hidden #line 318 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 319 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t\t}\n"); #line default #line hidden #line 320 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 321 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\t}\n"); #line default #line hidden #line 322 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" if (!Nested) { #line default #line hidden #line 323 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("}\n"); #line default #line hidden #line 324 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" } #line default #line hidden #line 325 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt" this.Write("\n"); #line default #line hidden return(this.GenerationEnvironment.ToString()); }
public override string TransformText() { this.GenerationEnvironment = null; #line 2 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write("// -------------------------------------------------------------------------\n// " + "C++ library declarations\n// Generated on "); #line default #line hidden #line 4 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now)); #line default #line hidden #line 4 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write("\n//\n// This file was auto generated. Do not edit.\n// ---------------------------" + "----------------------------------------------\n\nusing System;\nusing Mono.Cxxi;\nu" + "sing Mono.Cxxi.Abi;\n\nnamespace "); #line default #line hidden #line 13 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Generator.Lib.BaseNamespace)); #line default #line hidden #line 13 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(" {\n\n\tpublic static partial class Libs {\n"); #line default #line hidden #line 16 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" foreach (var lib in Libs) { #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write("\t\tpublic static readonly CppLibrary "); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(CSharpLanguage.SafeIdentifier(lib.BaseName))); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(" = new CppLibrary (\""); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(lib.BaseName)); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write("\", "); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(lib.AbiType)); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(".Instance, InlineMethods."); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(lib.InlinePolicy)); #line default #line hidden #line 17 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write(");\n"); #line default #line hidden #line 18 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" } #line default #line hidden #line 19 "C:\Users\Kevin\code\VisualStudio\cxxi\src\generator\Templates\CSharp\CSharpLibs.tt" this.Write("\t}\n}\n"); #line default #line hidden return(this.GenerationEnvironment.ToString()); }
public override string TransformText() { this.GenerationEnvironment = null; #line 2 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write("// -------------------------------------------------------------------------\n// C++ library declarations\n// Generated on "); #line default #line hidden #line 4 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now)); #line default #line hidden #line 4 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write("\n//\n// This file was auto generated. Do not edit.\n// -------------------------------------------------------------------------\n\nusing System;\nusing Mono.Cxxi;\n\nnamespace "); #line default #line hidden #line 12 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Generator.Lib.BaseNamespace)); #line default #line hidden #line 12 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(" {\n\n\tpublic static partial class Libs {\n"); #line default #line hidden #line 15 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" foreach (var lib in Libs) { #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write("\t\tpublic static readonly CppLibrary "); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(CSharpLanguage.SafeIdentifier(lib.BaseName))); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(" = new CppLibrary (\""); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(lib.BaseName)); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write("\", InlineMethods."); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(this.ToStringHelper.ToStringWithCulture(lib.InlinePolicy)); #line default #line hidden #line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write(");\n"); #line default #line hidden #line 17 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" } #line default #line hidden #line 18 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt" this.Write("\t}\n}\n"); #line default #line hidden return(this.GenerationEnvironment.ToString()); }