Example #1
0
        private static CodeTypeMember GenerateProperty(RequestParameter parameter, Type convertedType)
        {
            var field = new CodeMemberField
            {
                Attributes       = MemberAttributes.Public | MemberAttributes.Final,
                Name             = parameter.Name,
                Type             = new CodeTypeReference(convertedType ?? parameter.Type),
                CustomAttributes =
                {
                    new CodeAttributeDeclaration(
                        new CodeTypeReference(typeof(ProtoMemberAttribute)),
                        new CodeAttributeArgument(
                            new CodePrimitiveExpression(parameter.ProtoIndex)))
                }
            };

            field.Name += " { get; set; }//";

            return(field);
        }
Example #2
0
        private static CodeAssignStatement GenerateConvertBackStatement(RequestParameter parameter, int?converterIndex)
        {
            var parametersReference = new CodeVariableReferenceExpression(parametersName);
            var castedOObjReference = new CodeVariableReferenceExpression(castedObjName);

            CodeExpression propertyReference = new CodePropertyReferenceExpression(
                castedOObjReference, parameter.Name);

            return(new CodeAssignStatement(
                       new CodeArrayIndexerExpression(
                           parametersReference,
                           new CodePrimitiveExpression(parameter.Index)),
                       converterIndex.HasValue
                                ? new CodeMethodInvokeExpression(
                           new CodeArrayIndexerExpression(
                               new CodeFieldReferenceExpression(
                                   new CodeThisReferenceExpression(), convertersFieldName),
                               new CodePrimitiveExpression(converterIndex)),
                           "Convert", propertyReference)
                                : propertyReference));
        }
Example #3
0
        private static CodeAssignStatement GenerateConvertStatement(RequestParameter parameter,
                                                                    Type convertedType,
                                                                    int?converterIndex)
        {
            var parametersReference = new CodeVariableReferenceExpression(parametersName);
            var objReference        = new CodeVariableReferenceExpression(objParameterName);
            var parameterIndex      = new CodeArrayIndexerExpression(
                parametersReference,
                new CodePrimitiveExpression(parameter.Index));

            return(new CodeAssignStatement(
                       new CodePropertyReferenceExpression(
                           objReference, parameter.Name),
                       new CodeCastExpression(
                           new CodeTypeReference(convertedType ?? parameter.Type),
                           converterIndex.HasValue
                        ? (CodeExpression) new CodeMethodInvokeExpression(
                               new CodeArrayIndexerExpression(
                                   new CodeFieldReferenceExpression(
                                       new CodeThisReferenceExpression(), convertersFieldName),
                                   new CodePrimitiveExpression(converterIndex)),
                               "ConvertBack", parameterIndex)
                        : parameterIndex)));
        }