Beispiel #1
0
 protected IEnumerable <ProcessedProperty> PostProcessSubscriptProperties(IEnumerable <PropertyInfo> properties)
 {
     foreach (PropertyInfo property in properties)
     {
         ProcessedProperty processedProperty = new ProcessedProperty(property, this);
         yield return(processedProperty);
     }
 }
        protected override void Generate(ProcessedProperty property)
        {
            PropertyInfo pi     = property.Property;
            var          getter = pi.GetGetMethod();
            var          setter = pi.GetSetMethod();

            // setter-only properties are handled as methods (and should not reach this code)
            if (getter == null && setter != null)
            {
                throw new EmbeddinatorException(99, "Internal error `setter only`. Please file a bug report with a test case (https://github.com/mono/Embeddinator-4000/issues");
            }

            var name = pi.Name.CamelCase();

            headers.Write("@property (nonatomic");
            if (getter.IsStatic)
            {
                headers.Write(", class");
            }
            if (setter == null)
            {
                headers.Write(", readonly");
            }
            var pt            = pi.PropertyType;
            var property_type = NameGenerator.GetTypeName(pt);

            if (types.Contains(pt))
            {
                property_type += " *";
            }

            var spacing = property_type [property_type.Length - 1] == '*' ? string.Empty : " ";

            headers.WriteLine($") {property_type}{spacing}{name};");

            ImplementMethod(getter, name, false, pi);
            if (setter == null)
            {
                return;
            }

            ImplementMethod(setter, "set" + pi.Name, false, pi);
        }
Beispiel #3
0
        protected void GenerateSubscript(ProcessedProperty property)
        {
            PropertyInfo pi = property.Property;

            bool hasRead  = pi.GetGetMethod() != null;
            bool hasWrite = pi.GetSetMethod() != null;

            Type indexType = hasWrite ? pi.GetSetMethod().GetParameters()[0].ParameterType : pi.GetGetMethod().ReturnType;
            Type paramType = pi.PropertyType;

            switch (Type.GetTypeCode(indexType))
            {
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
                if (hasRead)
                {
                    GenerateIndexedSubscriptingRead(indexType, paramType);
                }
                if (hasWrite)
                {
                    GenerateIndexedSubscriptingWrite(indexType, paramType);
                }
                return;

            default:
                if (hasRead)
                {
                    GenerateKeyedSubscriptingRead(indexType, paramType);
                }
                if (hasWrite)
                {
                    GenerateKeyedSubscriptingWrite(indexType, paramType);
                }
                return;
            }
        }