Esempio n. 1
0
        private static void ProvideNestedToStringWithCultureMethod(CodeTypeDeclaration nest, CodeFieldReferenceExpression formatProviderRef)
        {
            CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression(typeof(object), "objectToConvert");
            CodeVariableReferenceExpression    callSite  = new CodeVariableReferenceExpression("t");
            CodeVariableReferenceExpression    left      = new CodeVariableReferenceExpression("method");
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(typeof(string), "ToStringWithCulture", "This is called from the compile/run appdomain to convert objects within an expression block to a string", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { CodeDomHelpers.CheckNullParameter(parameter.Name), new CodeVariableDeclarationStatement(typeof(Type), callSite.VariableName, parameter.Ref().Call("GetType", new CodeExpression[0])), new CodeVariableDeclarationStatement(typeof(MethodInfo), left.VariableName, callSite.Call("GetMethod", new CodeExpression[] { "ToString".Prim(), new CodeArrayCreateExpression(typeof(Type), new CodeExpression[] { new CodeTypeOfExpression(typeof(IFormatProvider)) }) })), new CodeConditionStatement(new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityEquality, CodeDomHelpers.nullEx), new CodeStatement[] { new CodeMethodReturnStatement(parameter.Ref().Call("ToString", new CodeExpression[0])) }, new CodeStatement[] { new CodeMethodReturnStatement(new CodeCastExpression(typeof(string), left.Call("Invoke", new CodeExpression[] { parameter.Ref(), new CodeArrayCreateExpression(typeof(object), new CodeExpression[] { formatProviderRef }) }))) }) });

            method.Parameters.Add(parameter);
            nest.Members.Add(method);
        }
Esempio n. 2
0
        private static void ProvideNestedToStringWithCultureMethod(CodeTypeDeclaration nest, CodeFieldReferenceExpression formatProviderRef)
        {
            CodeParameterDeclarationExpression codeParameterDeclarationExpression = new CodeParameterDeclarationExpression(typeof(object), "objectToConvert");
            CodeVariableReferenceExpression    codeVariableReferenceExpression    = new CodeVariableReferenceExpression("t");
            CodeVariableReferenceExpression    codeVariableReferenceExpression2   = new CodeVariableReferenceExpression("method");
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(typeof(string), "ToStringWithCulture", "This is called from the compile/run appdomain to convert objects within an expression block to a string", (MemberAttributes)24578, CodeDomHelpers.CheckNullParameter(codeParameterDeclarationExpression.Name), new CodeVariableDeclarationStatement(typeof(Type), codeVariableReferenceExpression.VariableName, codeParameterDeclarationExpression.Ref().Call("GetType")), new CodeVariableDeclarationStatement(typeof(MethodInfo), codeVariableReferenceExpression2.VariableName, codeVariableReferenceExpression.Call("GetMethod", "ToString".Prim(), new CodeArrayCreateExpression(typeof(Type), new CodeExpression[1]
            {
                new CodeTypeOfExpression(typeof(IFormatProvider))
            }))), new CodeConditionStatement(new CodeBinaryOperatorExpression(codeVariableReferenceExpression2, CodeBinaryOperatorType.IdentityEquality, CodeDomHelpers.nullEx), new CodeStatement[1]
            {
                new CodeMethodReturnStatement(codeParameterDeclarationExpression.Ref().Call("ToString"))
            }, new CodeStatement[1]
            {
                new CodeMethodReturnStatement(new CodeCastExpression(typeof(string), codeVariableReferenceExpression2.Call("Invoke", codeParameterDeclarationExpression.Ref(), new CodeArrayCreateExpression(typeof(object), new CodeExpression[1]
                {
                    formatProviderRef
                }))))
            }));

            codeMemberMethod.Parameters.Add(codeParameterDeclarationExpression);
            nest.Members.Add(codeMemberMethod);
        }