public CodeTypeDeclaration CreateInterface(CodeTypeDeclaration wrapper) { var iface = new CodeTypeDeclaration ("I" + Name) { TypeAttributes = TypeAttributes.Interface | (wrapper != null? TypeAttributes.NestedPublic : TypeAttributes.Public), Attributes = MemberAttributes.Public, IsInterface = true }; foreach (var arg in TemplateArguments) iface.TypeParameters.Add (arg); if (wrapper != null) iface.BaseTypes.Add (new CodeTypeReference (typeof (ICppClassOverridable<>).Name, wrapper.TypeReference ())); else iface.BaseTypes.Add (new CodeTypeReference (typeof (ICppClass).Name)); foreach (var atom in Atoms) atom.Visit (iface); return iface; }
public CodeTypeDeclaration CreateWrapperClass() { var wrapper = new CodeTypeDeclaration (Name) { Attributes = MemberAttributes.Public, TypeAttributes = TypeAttributes.Public }; foreach (var arg in TemplateArguments) wrapper.TypeParameters.Add (arg); if (Atoms.Count == 0) { wrapper.Comments.Add (new CodeCommentStatement ("FIXME: This type is a stub.")); string m = CreateBaseImplementation (wrapper); wrapper.BaseTypes.Add (m); wrapper.Members.Add (new CodeMemberMethod { Name = "Dispose", Attributes = MemberAttributes.Public}); var ctor = new CodeConstructor { Name = this.Name, Attributes = MemberAttributes.Assembly }; ctor.Parameters.Add (new CodeParameterDeclarationExpression (typeof (CppTypeInfo).Name, "subClass")); wrapper.Members.Add (ctor); return wrapper; } var iface = CreateInterface (wrapper); wrapper.Members.Add (iface); var native = CreateNativeLayout (); wrapper.Members.Add (native); // FIXME: For now, we'll have the managed wrapper extend from the first public base class string managedBase = Bases.Where (b => b.Access == Access.Public).Select (b => b.Name).FirstOrDefault (); bool hasOverrides = true; if (managedBase == null) { hasOverrides = false; managedBase = CreateBaseImplementation (wrapper); } wrapper.BaseTypes.Add (managedBase); // add static impl field var implField = new CodeMemberField (iface.TypeReference (), "impl") { Attributes = MemberAttributes.Static | MemberAttributes.Private }; if (StaticCppLibrary != null) { CodeTypeReference [] types = new CodeTypeReference [] { iface.TypeReference (), native.TypeReference (), wrapper.TypeReference () }; var getClassMethod = new CodeMethodReferenceExpression (new CodeTypeReferenceExpression (new CodeTypeReference (StaticCppLibrary, CodeTypeReferenceOptions.GlobalReference)), "GetClass", types); implField.InitExpression = new CodeMethodInvokeExpression (getClassMethod, new CodePrimitiveExpression (Name)); } wrapper.Members.Add (implField); // always add native subclass ctor wrapper.Members.Add (CreateNativeSubclassConstructor (hasOverrides)); CodeMemberMethod dispose = null; foreach (var atom in Atoms) { Method method = atom as Method; if (method != null && method.IsDestructor) { dispose = (CodeMemberMethod)method.InsideCodeTypeDeclaration (wrapper); atom.Visit (dispose); } else atom.Visit (wrapper); } if (dispose == null) { dispose = CreateDestructorlessDispose (); wrapper.Members.Add (dispose); } if (hasOverrides) dispose.Attributes |= MemberAttributes.Override; return wrapper; }