private static AttributeSyntax GetAttributeSyntax(AttributeGenerationData data)
        {
            var syntax = SyntaxFactory.Attribute(NameSyntaxUtility.GetNameSyntax(data.m_AttributeName));

            if (data.m_AttributeArguments != null && data.m_AttributeArguments.Count > 0)
            {
                syntax = syntax.WithArgumentList(GetAttributeArgumentListSyntax(data.m_AttributeArguments));
            }

            return(syntax);
        }
Esempio n. 2
0
        /// <summary> Create a field initializer with new keyword. Example: IntReactiveProperty a = new IntReactiveProperty()</summary>
        private static EqualsValueClauseSyntax CreateNewFieldInitializer(FieldGenerationData data)
        {
            var arguments = SyntaxFactory.ArgumentList();

            if (!string.IsNullOrEmpty(data.m_InitializerValue) || VariableTypeCheckerUtility.IsVariableBoolean(data.m_VariableType))
            {
                arguments = arguments.AddArguments(SyntaxFactory.Argument(LiteralExpressionUtility.CreateLiteralExpression(data.m_VariableType, data.m_InitializerValue)));
            }

            return(SyntaxFactory.EqualsValueClause(SyntaxFactory.ObjectCreationExpression(
                                                       NameSyntaxUtility.GetNameSyntax(data.m_VariableType), arguments, null)));
        }
        private static AttributeArgumentSyntax GetAttributeArgumentSyntax(AttributeArgumentData data)
        {
            var argumentSyntax = SyntaxFactory.AttributeArgument(LiteralExpressionUtility.CreateLiteralExpression(data.m_ArgumentType, data.m_ArgumentValue));

            if (data.m_IsPartOfConstructor)
            {
                argumentSyntax = argumentSyntax.WithNameEquals(NameSyntaxUtility.GetNameEqualsSyntax(data.m_ArgumentName));
            }
            else
            {
                argumentSyntax = argumentSyntax.WithNameColon(NameSyntaxUtility.GetNameColonSyntax(data.m_ArgumentName));
            }

            return(argumentSyntax);
        }