Esempio n. 1
0
        private void BuildCode(PropertySymbol propertySymbol)
        {
            if (propertySymbol.IsAbstract || propertySymbol.IsAutoProperty())
            {
                return;
            }

            ImplementationBuilder implBuilder = new ImplementationBuilder(options, errorHandler);

            if (implBuilder.TryBuildPropertyGetter(propertySymbol, out SymbolImplementation getter))
            {
                propertySymbol.AddImplementation(getter, /* getter */ true);
                implementations.Add(getter);
            }

            if (implBuilder.TryBuildPropertySetter(propertySymbol, out SymbolImplementation setter))
            {
                propertySymbol.AddImplementation(setter, /* getter */ false);
                implementations.Add(setter);
            }

            if (propertySymbol.AnonymousMethods != null)
            {
                foreach (AnonymousMethodSymbol anonymousMethod in propertySymbol.AnonymousMethods)
                {
                    Debug.Assert(anonymousMethod.Implementation != null);

                    implementations.Add(anonymousMethod.Implementation);
                }
            }
        }
Esempio n. 2
0
        private static void GenerateProperty(ScriptGenerator generator, string typeName, PropertySymbol propertySymbol)
        {
            if (propertySymbol.IsAbstract)
            {
                return;
            }

            ScriptTextWriter writer = generator.Writer;

            bool instanceMember = true;

            if ((propertySymbol.Visibility & MemberVisibility.Static) != 0)
            {
                instanceMember = false;
            }

            if (propertySymbol.HasGetter)
            {
                GeneratePropertyGetter(generator, typeName, propertySymbol, writer, instanceMember);
            }

            if (propertySymbol.HasSetter)
            {
                if (instanceMember && propertySymbol.HasGetter)
                {
                    writer.WriteLine(",");
                }

                GeneratePropertySetter(generator, typeName, propertySymbol, writer, instanceMember);
            }

            if (propertySymbol.Visibility.HasFlag(MemberVisibility.Static) && propertySymbol.IsAutoProperty())
            {
                writer.Write(DSharpStringResources.ScriptExportMember("defineProperty"));
                writer.Write($"({((ClassSymbol)propertySymbol.Parent).FullGeneratedName}, '{propertySymbol.GeneratedName}');");
                writer.WriteLine();
            }
        }