internal void AddMethod(ContractMethodInfo methodInfo)
        {
            if (methodInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("methodInfo");
            }

            MemberSignature signature = new MemberSignature(methodInfo);

            if (this.GetMemberHelper <MethodInfo>(BindingFlags.Public | BindingFlags.Instance,
                                                  signature,
                                                  ref this.methods) != null)
            {
                return;
            }
            else
            {
                List <MethodInfo> localMethods = new List <MethodInfo>();
                if (this.methods != null)
                {
                    localMethods.AddRange(this.methods);
                }
                localMethods.Add(methodInfo);
                this.methods = new MethodInfo[localMethods.Count];
                localMethods.CopyTo(this.methods);
            }
        }
        internal ContractMethodParameterInfo(ContractMethodInfo member,
            OperationParameterInfo parameterInfo)
        {
            if (member == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("member");
            }
            if (parameterInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameterInfo");
            }

            this.AttrsImpl = parameterInfo.Attributes;

            this.MemberImpl = member;
            this.PositionImpl = parameterInfo.Position;
            if (parameterInfo.Position >= 0)
            {
                this.NameImpl = parameterInfo.Name;

                string typeName = parameterInfo.ParameterType.FullName;
                if ((this.AttrsImpl & ParameterAttributes.Out) > 0)
                {
                    typeName += '&'; // Append with & for (ref & out) parameter types

                    if (this.Member.DeclaringType is DesignTimeType)
                    {
                        this.ClassImpl = (this.Member.DeclaringType as DesignTimeType).ResolveType(typeName);
                    }
                    else if (parameterInfo.ParameterType is DesignTimeType)
                    {
                        this.ClassImpl = (parameterInfo.ParameterType as DesignTimeType).ResolveType(typeName);
                    }
                    else
                    {
                        typeName += ", " + parameterInfo.ParameterType.Assembly.FullName;
                        this.ClassImpl = Type.GetType(typeName);
                    }
                }
                else
                {
                    this.ClassImpl = parameterInfo.ParameterType;
                }
            }
            else
            {
                this.ClassImpl = parameterInfo.ParameterType;
            }
        }
        internal ContractMethodParameterInfo(ContractMethodInfo member,
                                             OperationParameterInfo parameterInfo)
        {
            if (member == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("member");
            }
            if (parameterInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameterInfo");
            }

            this.AttrsImpl = parameterInfo.Attributes;

            this.MemberImpl   = member;
            this.PositionImpl = parameterInfo.Position;
            if (parameterInfo.Position >= 0)
            {
                this.NameImpl = parameterInfo.Name;

                string typeName = parameterInfo.ParameterType.FullName;
                if ((this.AttrsImpl & ParameterAttributes.Out) > 0)
                {
                    typeName += '&'; // Append with & for (ref & out) parameter types

                    if (this.Member.DeclaringType is DesignTimeType)
                    {
                        this.ClassImpl = (this.Member.DeclaringType as DesignTimeType).ResolveType(typeName);
                    }
                    else if (parameterInfo.ParameterType is DesignTimeType)
                    {
                        this.ClassImpl = (parameterInfo.ParameterType as DesignTimeType).ResolveType(typeName);
                    }
                    else
                    {
                        typeName      += ", " + parameterInfo.ParameterType.Assembly.FullName;
                        this.ClassImpl = Type.GetType(typeName);
                    }
                }
                else
                {
                    this.ClassImpl = parameterInfo.ParameterType;
                }
            }
            else
            {
                this.ClassImpl = parameterInfo.ParameterType;
            }
        }
        static Dictionary <string, ContractType> BuildContractTypes(Activity contextActivity)
        {
            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextActivity");
            }

            Dictionary <string, ContractType> types = new Dictionary <string, ContractType>();

            Walker walker = new Walker(true);

            walker.FoundActivity += delegate(Walker w, WalkerEventArgs args)
            {
                ReceiveActivity currentActivity = args.CurrentActivity as ReceiveActivity;
                if (currentActivity == null)
                {
                    return;
                }
                OperationInfo operationInfo = currentActivity.ServiceOperationInfo as OperationInfo;
                if (operationInfo == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(operationInfo.ContractName) ||
                    string.IsNullOrEmpty(operationInfo.Name))
                {
                    return;
                }

                if (!types.ContainsKey(operationInfo.ContractName))
                {
                    types.Add(operationInfo.ContractName,
                              new ContractType(operationInfo.ContractName));
                }

                bool       hasReturnValue      = false;
                bool       duplicatedPositions = false;
                int        maxPosition         = -1;
                List <int> parameterIndexs     = new List <int>();

                foreach (OperationParameterInfo operationParameterInfo in operationInfo.Parameters)
                {
                    if (operationParameterInfo.Position == -1)
                    {
                        hasReturnValue = true;
                    }
                    else
                    {
                        maxPosition = (maxPosition < operationParameterInfo.Position) ? operationParameterInfo.Position : maxPosition;
                    }

                    if (parameterIndexs.Contains(operationParameterInfo.Position))
                    {
                        duplicatedPositions = true;
                        break;
                    }
                    else
                    {
                        parameterIndexs.Add(operationParameterInfo.Position);
                    }
                }

                if (duplicatedPositions ||
                    maxPosition > (operationInfo.Parameters.Count - (hasReturnValue ? 2 : 1)))
                {
                    return;
                }

                ContractType       contract   = types[operationInfo.ContractName];
                ContractMethodInfo methodInfo = new ContractMethodInfo(contract, operationInfo);
            };

            walker.Walk(contextActivity);

            return(types);
        }
        static Dictionary<string, ContractType> BuildContractTypes(Activity contextActivity)
        {
            if (contextActivity == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextActivity");
            }

            Dictionary<string, ContractType> types = new Dictionary<string, ContractType>();

            Walker walker = new Walker(true);
            walker.FoundActivity += delegate(Walker w, WalkerEventArgs args)
            {
                ReceiveActivity currentActivity = args.CurrentActivity as ReceiveActivity;
                if (currentActivity == null)
                {
                    return;
                }
                OperationInfo operationInfo = currentActivity.ServiceOperationInfo as OperationInfo;
                if (operationInfo == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(operationInfo.ContractName) ||
                    string.IsNullOrEmpty(operationInfo.Name))
                {
                    return;
                }

                if (!types.ContainsKey(operationInfo.ContractName))
                {
                    types.Add(operationInfo.ContractName,
                        new ContractType(operationInfo.ContractName));
                }

                bool hasReturnValue = false;
                bool duplicatedPositions = false;
                int maxPosition = -1;
                List<int> parameterIndexs = new List<int>();

                foreach (OperationParameterInfo operationParameterInfo in operationInfo.Parameters)
                {
                    if (operationParameterInfo.Position == -1)
                    {
                        hasReturnValue = true;
                    }
                    else
                    {
                        maxPosition = (maxPosition < operationParameterInfo.Position) ? operationParameterInfo.Position : maxPosition;
                    }

                    if (parameterIndexs.Contains(operationParameterInfo.Position))
                    {
                        duplicatedPositions = true;
                        break;
                    }
                    else
                    {
                        parameterIndexs.Add(operationParameterInfo.Position);
                    }
                }

                if (duplicatedPositions ||
                    maxPosition > (operationInfo.Parameters.Count - (hasReturnValue ? 2 : 1)))
                {
                    return;
                }

                ContractType contract = types[operationInfo.ContractName];
                ContractMethodInfo methodInfo = new ContractMethodInfo(contract, operationInfo);
            };

            walker.Walk(contextActivity);

            return types;
        }