Ejemplo n.º 1
0
        public void Fixup()
        {
            ContractDescription cd = context.Contract;

            ml_context.FindClientType(context);
            var parentClass = ml_context.ClientType;

            string name = cd.Name + "Channel";

            if (name [0] == 'I')
            {
                name = name.Substring(1);
            }

            var gt             = new CodeTypeReference(cd.Name);
            var clientBaseType = new CodeTypeReference("System.ServiceModel.ClientBase", gt);
            // this omits namespace, but should compile
            var channelBase = new CodeTypeReference("ChannelBase", gt);
            var type        = new CodeTypeDeclaration(name);

            parentClass.Members.Add(type);
            type.BaseTypes.Add(channelBase);
            type.BaseTypes.Add(new CodeTypeReference(cd.Name));
            type.TypeAttributes |= TypeAttributes.NestedPrivate;

            ml_context.ChannelType = type;

            // .ctor(ClientBase<T> client)
            var ctor = new CodeConstructor();

            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    clientBaseType, "client"));
            ctor.BaseConstructorArgs.Add(
                new CodeArgumentReferenceExpression("client"));
            type.Members.Add(ctor);
        }
Ejemplo n.º 2
0
        public void Fixup()
        {
            ContractDescription cd = context.Contract;

            ml_context.FindClientType(context);
            var parentClass = ml_context.ClientType;

            if (!generate_sync)
            {
                EliminateSync();
            }

            string name = cd.Name + "Channel";

            if (name [0] == 'I')
            {
                name = name.Substring(1);
            }

            var gt             = new CodeTypeReference(cd.Name);
            var clientBaseType = new CodeTypeReference("System.ServiceModel.ClientBase", gt);
            // this omits namespace, but should compile
            var channelBase = new CodeTypeReference("ChannelBase", gt);
            var type        = new CodeTypeDeclaration(name);

            parentClass.Members.Add(type);
            type.BaseTypes.Add(channelBase);
            type.BaseTypes.Add(new CodeTypeReference(cd.Name));
            type.TypeAttributes |= TypeAttributes.NestedPrivate;

            ml_context.ChannelType = type;

            // .ctor(ClientBase<T> client)
            var ctor = new CodeConstructor();

            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    clientBaseType, "client"));
            ctor.BaseConstructorArgs.Add(
                new CodeArgumentReferenceExpression("client"));
            type.Members.Add(ctor);

            // In Client type:
            // protected override TChannel CreateChannel()
            var creator = new CodeMemberMethod();

            creator.Name = "CreateChannel";
            // Analysis disable BitwiseOperatorOnEnumWithoutFlags
            creator.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            // Analysis restore BitwiseOperatorOnEnumWithoutFlags
            creator.ReturnType = gt;
            creator.Statements.Add(
                new CodeMethodReturnStatement(
                    new CodeCastExpression(
                        gt,
                        new CodeObjectCreateExpression(
                            new CodeTypeReference(name),
                            new CodeThisReferenceExpression()))));
            parentClass.Members.Add(creator);

            // clear IExtensibleDataObject. Since there is *no* way
            // to identify the type of a TypeReference, I cannot do
            // anything but this brutal removal.
            // Also clear ExtensionDataObject members.
            foreach (CodeNamespace cns in context.ServiceContractGenerator.TargetCompileUnit.Namespaces)
            {
                foreach (CodeTypeDeclaration ct in cns.Types)
                {
                    if (!ShouldPreserveBaseTypes(ct))
                    {
                        ct.BaseTypes.Clear();
                    }
                    CodeTypeMember cp = null, cf = null;
                    foreach (CodeTypeMember cm in ct.Members)
                    {
                        if (cm is CodeMemberProperty && cm.Name == "ExtensionData")
                        {
                            cp = cm;
                        }
                        else if (cm is CodeMemberField && cm.Name == "extensionDataField")
                        {
                            cf = cm;
                        }
                    }
                    if (cf != null)
                    {
                        ct.Members.Remove(cf);
                    }
                    if (cp != null)
                    {
                        ct.Members.Remove(cp);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Fixup()
        {
            ContractDescription cd = context.Contract;

            ml_context.FindClientType(context);
            var parentClass = ml_context.ClientType;

            if (!generate_sync)
            {
                EliminateSync();
            }

            string name = cd.Name + "Channel";

            if (name [0] == 'I')
            {
                name = name.Substring(1);
            }

            var gt             = new CodeTypeReference(cd.Name);
            var clientBaseType = new CodeTypeReference("System.ServiceModel.ClientBase", gt);
            // this omits namespace, but should compile
            var channelBase = new CodeTypeReference("ChannelBase", gt);
            var type        = new CodeTypeDeclaration(name);

            parentClass.Members.Add(type);
            type.BaseTypes.Add(channelBase);
            type.BaseTypes.Add(new CodeTypeReference(cd.Name));
            type.TypeAttributes |= TypeAttributes.NestedPrivate;

            ml_context.ChannelType = type;

            // .ctor(ClientBase<T> client)
            var ctor = new CodeConstructor();

            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    clientBaseType, "client"));
            ctor.BaseConstructorArgs.Add(
                new CodeArgumentReferenceExpression("client"));
            type.Members.Add(ctor);

            // In Client type:
            // protected override TChannel CreateChannel()
            var creator = new CodeMemberMethod();

            creator.Name       = "CreateChannel";
            creator.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            creator.ReturnType = gt;
            creator.Statements.Add(
                new CodeMethodReturnStatement(
                    new CodeCastExpression(
                        gt,
                        new CodeObjectCreateExpression(
                            new CodeTypeReference(name),
                            new CodeThisReferenceExpression()))));
            parentClass.Members.Add(creator);

            // clear IExtensibleDataObject. Since there is *no* way
            // to identify the type of a TypeReference, I cannot do
            // anything but this brutal removal.
            foreach (CodeNamespace cns in context.ServiceContractGenerator.TargetCompileUnit.Namespaces)
            {
                foreach (CodeTypeDeclaration ct in cns.Types)
                {
                    if (ct != ml_context.ClientType && !ct.Name.EndsWith("EventArgs", StringComparison.Ordinal))
                    {
                        ct.BaseTypes.Clear();
                    }
                }
            }
        }