示例#1
0
        public override void GeneratePropertyInit(Property property, Source constuctorBody)
        {
            if (property.IsUICollection)
            {
                string descriptorName    = PropertyDescriptorName(property);
                string propertyFieldName = PropertyFieldName(property);

                constuctorBody.AddLines(
                    $"{propertyFieldName} = new {PropertyOutputTypeName(property)}(this);",
                    $"SetValue({descriptorName}, {propertyFieldName});");
            }
        }
示例#2
0
        public override void GeneratePropertyMethods(Property property, Source source)
        {
            var    usings = source.Usings;
            string propertyOutputTypeName = PropertyOutputTypeName(property);

            // Add the type - for interface type and the framework type (if different)
            usings.AddTypeNamespace(property.Type);
            if (IsWrappedType(property.Type) || Utils.IsUIModelInterfaceType(property.Type))
            {
                usings.AddNamespace(ToFrameworkNamespaceName(property.Type.ContainingNamespace));
            }

            AddTypeAliasUsingIfNeeded(usings, propertyOutputTypeName);

            bool classPropertyTypeDiffersFromInterface = property.TypeName != propertyOutputTypeName;

#if LATER
            SyntaxTokenList modifiers;
            if (includeXmlComment)
            {
                modifiers = TokenList(
                    Token(
                        TriviaList(xmlCommentTrivia),
                        SyntaxKind.PublicKeyword,
                        TriviaList()));
            }
            else
            {
                modifiers = TokenList(Token(SyntaxKind.PublicKeyword));
            }
#endif

            source.AddBlankLineIfNonempty();
            string descriptorName = PropertyDescriptorName(property);

            string getterValue;
            if (property.IsUICollection)
            {
                getterValue = $"{PropertyFieldName(property)}";
            }
            else
            {
                getterValue = $"({propertyOutputTypeName}) GetValue({descriptorName})";
            }

            if (property.IsReadOnly)
            {
                source.AddLine($"public {propertyOutputTypeName} {property.Name} => {getterValue};");
            }
            else
            {
                source.AddLines(
                    $"public {propertyOutputTypeName} {property.Name}",
                    "{");
                using (source.Indent())
                {
                    source.AddLine(
                        $"get => {getterValue};");
                    source.AddLine(
                        $"set => SetValue({descriptorName}, value);");
                }
                source.AddLine(
                    "}");
            }

#if LATER
            //if (!includeXmlComment)
            propertyDeclaration = propertyDeclaration.WithLeadingTrivia(
                TriviaList(propertyDeclaration.GetLeadingTrivia()
                           .Insert(0, CarriageReturnLineFeed)
                           .Insert(0, CarriageReturnLineFeed)));
#endif

            // If the interface property has a different type, add another property that explicitly implements it
            if (classPropertyTypeDiffersFromInterface)
            {
                string otherGetterValue;
                string setterAssignment;
                if (IsWrappedType(property.Type))
                {
                    otherGetterValue = $"{property.Name}.{property.TypeName}";
                    setterAssignment = $"{property.Name} = new {propertyOutputTypeName}(value)";
                }
                else if (Utils.IsUICollectionType(property.Type, out var elementType) && propertyOutputTypeName.StartsWith("UIElementCollection<"))
                {
                    otherGetterValue = $"{property.Name}.ToStandardUIElementCollection()";
                    setterAssignment = ""; // Not used
                }
                else
                {
                    otherGetterValue = property.Name;
                    setterAssignment = $"{property.Name} = ({propertyOutputTypeName}) value";
                }

                if (property.IsReadOnly)
                {
                    source.AddLine(
                        $"{property.TypeName} {property.Interface.Name}.{property.Name} => {otherGetterValue};");
                }
                else
                {
                    source.AddLines(
                        $"{property.TypeName} {property.Interface.Name}.{property.Name}",
                        "{");
                    using (source.Indent())
                    {
                        source.AddLine(
                            $"get => {otherGetterValue};");
                        source.AddLine(
                            $"set => {setterAssignment};");
                    }
                    source.AddLine(
                        "}");
                }
            }
        }
示例#3
0
        public override void GeneratePropertyMethods(Property property, Source source)
        {
            var usings = source.Usings;

            // Add the type - for interface type and the framework type (if different)
            usings.AddTypeNamespace(property.Type);
            if (IsWrappedType(property.Type) || Utils.IsUIModelInterfaceType(property.Type))
            {
                usings.AddNamespace(ToFrameworkNamespaceName(property.Type.ContainingNamespace));
            }

            var propertyOutputTypeName = PropertyOutputTypeName(property);

            AddTypeAliasUsingIfNeeded(usings, propertyOutputTypeName);

            bool classPropertyTypeDiffersFromInterface = property.TypeName != propertyOutputTypeName;

#if LATER
            SyntaxTokenList modifiers;
            if (includeXmlComment)
            {
                modifiers = TokenList(
                    Token(
                        TriviaList(xmlCommentTrivia),
                        SyntaxKind.PublicKeyword,
                        TriviaList()));
            }
            else
            {
                modifiers = TokenList(Token(SyntaxKind.PublicKeyword));
            }
#endif

            source.AddBlankLineIfNonempty();

            string propertyFieldName = PropertyFieldName(property);

            if (property.IsReadOnly)
            {
                source.AddLine($"public {propertyOutputTypeName} {property.Name} => {propertyFieldName};");
            }
            else
            {
                source.AddLines(
                    $"public {propertyOutputTypeName} {property.Name}",
                    "{");
                using (source.Indent())
                {
                    source.AddLine(
                        $"get => {propertyFieldName};");
                    source.AddLine(
                        $"set => {propertyFieldName} = value;");
                }
                source.AddLine(
                    "}");
            }

#if LATER
            // If the interface property has a different type, add another property that explicitly implements it
            if (classPropertyTypeDiffersFromInterface)
            {
                string otherGetterValue;
                string setterAssignment;
                if (property.Context.IsWrappedType(property.Type))
                {
                    otherGetterValue = $"{property.Name}.{property.TypeName}";
                    setterAssignment = $"{property.Name} = new {property.FrameworkTypeName}(value)";
                }
                else
                {
                    otherGetterValue = property.Name;
                    setterAssignment = $"{property.Name} = ({property.FrameworkTypeName}) value";
                }

                if (!property.HasSetter)
                {
                    source.AddLine(
                        $"{property.TypeName} {property.Interface.Name}.{property.Name} => {otherGetterValue};");
                }
                else
                {
                    source.AddLines(
                        $"{property.TypeName} {property.Interface.Name}.{property.Name}",
                        "{");
                    using (source.Indent())
                    {
                        source.AddLine(
                            $"get => {otherGetterValue};");
                        source.AddLine(
                            $"set => {setterAssignment};");
                    }
                    source.AddLine(
                        "}");
                }
            }
#endif
        }