Beispiel #1
0
        IEnumerable <MethodDeclarationSyntax> GetGTypeInterfaceMethodImpls()
        {
            foreach (var f in NestedTypeInfos.Single(x => x.ManagedName == ManagedName + "Struct").FieldInfos.Where(x => x.IsCallback))
            {
                var methodName = f.ManagedName;
                var returnType = f.CallbackInfo.MethodInfo.UnmanagedReturnParameterInfo.TypeInfo.Type;

                var method = MethodDeclaration(returnType, methodName)
                             .AddModifiers(Token(SyntaxKind.StaticKeyword))
                             .WithParameterList(f.CallbackInfo.MethodInfo.UnmanagedParameterList)
                             .WithBody(Block(f.CallbackInfo.MethodInfo.VirtualMethodImplStatements));

                yield return(method);
            }
        }
Beispiel #2
0
        IEnumerable <MemberDeclarationSyntax> GetClassMemberDeclarations()
        {
            foreach (var d in NestedTypeInfos.SelectMany(x => x.Declarations))
            {
                yield return(d);
            }
            foreach (var d in FieldInfos.SelectMany(x => x.Declarations))
            {
                yield return(d);
            }
            if (HasDefaultConstructor)
            {
                yield return(DefaultConstructor);
            }
            if (IsGTypeStruct)
            {
                // taking advantage of the face that interfaces can't inherit,
                // so parent will always be GISharp.GObject.TypeInterface for
                // interfaces.
                if (GTypeStructParent == typeof(GISharp.GObject.TypeInterface))
                {
                    yield return(GetGTypeStructCreateInterfaceInfoMethod());

                    yield return(GetGTypeStructInterfaceInitMethod());

                    foreach (var m in GetGTypeInterfaceMethodImpls())
                    {
                        yield return(m);
                    }
                }
                else
                {
                    yield return(GetGTypeStructGetInfoMethod());
                }
            }
            foreach (var d in MethodInfos.SelectMany(x => x.Declarations))
            {
                yield return(d);
            }
        }
Beispiel #3
0
        IEnumerable <StatementSyntax> GetGTypeStructInterfaceInitStatements()
        {
            string statement;

            foreach (var f in NestedTypeInfos.Single(x => x.ManagedName == ManagedName + "Struct").FieldInfos.Where(x => x.IsCallback))
            {
                var methodName   = f.ManagedName;
                var delegateName = "Unmanaged" + f.CallbackInfo.ManagedName;
                var prefix       = methodName.ToCamelCase();
                var structName   = ManagedName + "Struct";

                statement = string.Format("var {0}Offset = {1}.OffsetOf<{2}> (nameof ({2}.{3}));\n",
                                          prefix, typeof(Marshal).FullName, structName, methodName);
                yield return(ParseStatement(statement));

                statement = string.Format("var {0}Ptr = {1}.GetFunctionPointerForDelegate<{2}.{3}> ({4});\n",
                                          prefix, typeof(Marshal).FullName, structName, delegateName, methodName);
                yield return(ParseStatement(statement));

                statement = string.Format("{0}.WriteIntPtr (gIface, (int){1}Offset, {1}Ptr);\n",
                                          typeof(Marshal).FullName, prefix);
                yield return(ParseStatement(statement));
            }
        }
Beispiel #4
0
 IEnumerable <MemberDeclarationSyntax> GetStructMemberDeclarations()
 {
     return(NestedTypeInfos.SelectMany(x => x.Declarations)
            .Concat(FieldInfos.SelectMany(x => x.Declarations))
            .Concat(MethodInfos.SelectMany(x => x.Declarations)));
 }
Beispiel #5
0
 internal override IEnumerable <BaseInfo> GetChildInfos()
 {
     return(NestedTypeInfos.Cast <BaseInfo> ().Concat(FieldInfos).Concat(MethodInfos));
 }