コード例 #1
0
        public CSProperty CompileProperty(CSUsingPackages packs, string propertyName,
                                          FunctionDeclaration getter, FunctionDeclaration setter, CSMethodKind methodKind = CSMethodKind.None)
        {
            var           swiftPropertyType = GetPropertyType(getter, setter);
            NetTypeBundle propertyType      = null;

            if (TypeMapper.IsCompoundProtocolListType(swiftPropertyType))
            {
                propertyType = new NetTypeBundle("System", "object", false, false, EntityType.ProtocolList);
            }
            else
            {
                propertyType = typeMap.MapType(getter, swiftPropertyType, false, true);
            }
            propertyName = propertyName ?? typeMap.SanitizeIdentifier(getter != null ? getter.PropertyName : setter.PropertyName);
            bool isSubscript = getter != null ? getter.IsSubscript :
                               setter.IsSubscript;

            if (!getter.IsTypeSpecGeneric(swiftPropertyType))
            {
                AddUsingBlock(packs, propertyType);
            }

            var uselessLine = new ICodeElement [] { CSReturn.ReturnLine(new CSIdentifier("useless")) };

            CSCodeBlock getterBlock = null;

            if (getter != null)
            {
                getterBlock = new CSCodeBlock(uselessLine);
            }
            CSCodeBlock setterBlock = null;

            if (setter != null)
            {
                setterBlock = new CSCodeBlock(uselessLine);
            }

            CSProperty theProp = null;

            if (isSubscript)
            {
                List <ParameterItem> swiftParms = null;
                if (getter != null)
                {
                    swiftParms = getter.ParameterLists [1];
                }
                else
                {
                    swiftParms = setter.ParameterLists [1].Skip(1).ToList();
                }
                var args = typeMap.MapParameterList(getter, swiftParms, false, false, null, null);
                args.ForEach(a => AddUsingBlock(packs, a.Type));

                var csParams =
                    new CSParameterList(
                        args.Select(a =>
                                    new CSParameter(a.Type.ToCSType(packs),
                                                    new CSIdentifier(a.Name), a.Type.IsReference ? CSParameterKind.Ref : CSParameterKind.None, null)));
                theProp = new CSProperty(propertyType.ToCSType(packs), methodKind, CSVisibility.Public, getterBlock,
                                         CSVisibility.Public, setterBlock, csParams);
            }
            else
            {
                theProp = new CSProperty(propertyType.ToCSType(packs), methodKind,
                                         new CSIdentifier(propertyName), CSVisibility.Public, getterBlock, CSVisibility.Public, setterBlock);
            }
            if (getterBlock != null)
            {
                getterBlock.Clear();
            }
            if (setterBlock != null)
            {
                setterBlock.Clear();
            }

            return(theProp);
        }