Пример #1
0
        IEnumerable <AttributeListSyntax> GetTypeDeclarationAttributeLists()
        {
            // If a type is a GType, then decorate it with the GTypeAttribute
            if (IsGType)
            {
                var nameArgument     = string.Format("\"{0}\"", GTypeName);
                var registerArgument = string.Format(
                    "{0} = true",
                    nameof(GISharp.Runtime.GTypeAttribute.IsProxyForUnmanagedType));
                yield return(AttributeList().AddAttributes(
                                 Attribute(ParseName(typeof(GISharp.Runtime.GTypeAttribute).FullName))
                                 .AddArgumentListArguments(
                                     AttributeArgument(ParseExpression(nameArgument)),
                                     AttributeArgument(ParseExpression(registerArgument)))));
            }

            // If a type has an associate GType struct, decorate it with the GTypeStructAttribute
            if (GTypeStruct != null)
            {
                var typeArgument = GirType.ResolveType(GTypeStruct, Element.Document);
                yield return(AttributeList().AddAttributes(
                                 Attribute(ParseName(typeof(GISharp.Runtime.GTypeStructAttribute).FullName))
                                 .AddArgumentListArguments(
                                     AttributeArgument(ParseExpression($"typeof({typeArgument.FullName})")))));
            }
        }
Пример #2
0
        IEnumerable <BaseTypeSyntax> GetBaseTypes()
        {
            var opaqueTypeName = Element.Attribute(gs + "opaque")?.Value;

            if (opaqueTypeName != null)
            {
                switch (opaqueTypeName)
                {
                case "ref-counted":
                    opaqueTypeName = typeof(GISharp.Runtime.ReferenceCountedOpaque).FullName;
                    break;

                case "owned":
                    opaqueTypeName = typeof(GISharp.Runtime.OwnedOpaque).FullName;
                    break;

                case "static":
                    opaqueTypeName = typeof(GISharp.Runtime.StaticOpaque).FullName;
                    break;

                case "gtype-struct":
                    opaqueTypeName = GTypeStructParent.FullName;
                    break;

                default:
                    var message = string.Format("Unknown oqaue type '{0}.", opaqueTypeName);
                    throw new Exception(message);
                }
                yield return(SimpleBaseType(ParseTypeName(opaqueTypeName)));
            }
            if (IsGObject)
            {
                var parent = Element.Attribute("parent")?.Value;
                if (parent == null)
                {
                    yield return(SimpleBaseType(
                                     ParseTypeName(typeof(GISharp.Runtime.ReferenceCountedOpaque).FullName)));
                }
                else
                {
                    var parentType = GirType.ResolveType(parent, Element.Document);
                    yield return(SimpleBaseType(ParseTypeName(parentType.FullName)));
                }
                // TODO: add interfaces for objects
            }
            if (MethodInfos.Any(x => x.IsEquals))
            {
                var typeName = string.Concat(typeof(IEquatable <>).FullName.TakeWhile(x => x != '`'));
                typeName = string.Format("{0}<{1}>", typeName, ManagedName);
                yield return(SimpleBaseType(ParseTypeName(typeName)));
            }
            if (MethodInfos.Any(x => x.IsCompare))
            {
                var typeName = string.Concat(typeof(IComparable <>).FullName.TakeWhile(x => x != '`'));
                typeName = string.Format("{0}<{1}>", typeName, ManagedName);
                yield return(SimpleBaseType(ParseTypeName(typeName)));
            }
        }
Пример #3
0
 IEnumerable <BaseTypeSyntax> GetBaseTypes()
 {
     if (Element.Descendants(gi + "prerequisite").Any())
     {
         foreach (var prerequisite in Element.Descendants(gi + "prerequisite"))
         {
             var type = GirType.ResolveType(prerequisite.Attribute("name").Value, Element.Document);
             yield return(SimpleBaseType(ParseTypeName(type.FullName)));
         }
     }
     else
     {
         yield return(SimpleBaseType(ParseTypeName(typeof(GISharp.Runtime.IObject).FullName)));
     }
 }