Example #1
0
 internal ArgumentsMapping(ArgumentMapping returnValue, ArgumentMapping[] arguments,
                           string[] contextElementKeys)
 {
     m_arguments          = arguments;
     m_returnValue        = returnValue;
     m_contextElementKeys = contextElementKeys;
 }
Example #2
0
            internal object DeserialiseResponseArgs(out object[] outArgs,
                                                    CdrInputStream sourceStream)
            {
                // demarshal first the return value;
                object retValue = null;

                if (m_returnValue.IsNonVoidReturn())
                {
                    retValue = m_returnValue.Deserialize(sourceStream);
                }

                // ... then the outargs
                outArgs = new object[m_arguments.Length];
                bool outArgFound = false;

                for (int actualParamNr = 0; actualParamNr < m_arguments.Length; actualParamNr++)
                {
                    ArgumentMapping paramInfo = m_arguments[actualParamNr];
                    if (paramInfo.IsOutArg() || paramInfo.IsRefArg())
                    {
                        outArgs[actualParamNr] = paramInfo.Deserialize(sourceStream);
                        outArgFound            = true;
                    } // else: for an in param null must be added to out-args
                }

                // prepare the result
                // need to return empty array, if no out-arg is present, because otherwise async calls fail
                if (!outArgFound)
                {
                    outArgs = new object[0];
                }
                return(retValue);
            }
Example #3
0
 private ArgumentMapping[] DetermineParamMappings(MethodInfo method, SerializerFactory serFactory)
 {
     ParameterInfo[]   parameters    = method.GetParameters();
     ArgumentMapping[] paramMappings = new ArgumentMapping[parameters.Length];
     for (int actualParamNr = 0; actualParamNr < parameters.Length; actualParamNr++)
     {
         ParameterInfo paramInfo = parameters[actualParamNr];
         // iterate through the parameters to determine mapping for each
         ArgumentsKind argKind = ArgumentsKind.Unknown;
         if (ReflectionHelper.IsInParam(paramInfo))
         {
             argKind = ArgumentsKind.InArg;
         }
         else if (ReflectionHelper.IsOutParam(paramInfo))
         {
             argKind = ArgumentsKind.OutArg;
         }
         else if (ReflectionHelper.IsRefParam(paramInfo))
         {
             argKind = ArgumentsKind.RefArg;
         }
         AttributeExtCollection paramAttrs =
             ReflectionHelper.CollectParameterAttributes(paramInfo,
                                                         method);
         Serializer paramSer = serFactory.Create(paramInfo.ParameterType, paramAttrs);
         paramMappings[actualParamNr] = new ArgumentMapping(paramSer, argKind);
     }
     return(paramMappings);
 }
Example #4
0
        private ArgumentsMapping DetermineMethodMapping(MethodInfo method, SerializerFactory serFactory)
        {
            ArgumentMapping returnMapping =
                DetermineReturnParamMapping(method, serFactory);

            ArgumentMapping[] paramMappings =
                DetermineParamMappings(method, serFactory);
            string[] contextElementNames = DetermineContextElements(method);
            return(new ArgumentsMapping(returnMapping, paramMappings, contextElementNames));
        }
Example #5
0
 internal object[] DeserialiseRequestArgs(CdrInputStream sourceStream,
                                          out IDictionary contextElements,
                                          Serializer contextElementSer)
 {
     object[] result = new object[m_arguments.Length];
     for (int actualParamNr = 0; actualParamNr < m_arguments.Length; actualParamNr++)
     {
         ArgumentMapping paramInfo = m_arguments[actualParamNr];
         if (paramInfo.IsInArg() || paramInfo.IsRefArg())
         {
             result[actualParamNr] = paramInfo.Deserialize(sourceStream);
         } // else: null for an out parameter
     }
     contextElements = DeserializeContextElements(sourceStream, contextElementSer);
     return(result);
 }
Example #6
0
 internal void SerializeRequestArgs(object[] arguments, CdrOutputStream targetStream,
                                    LogicalCallContext context, Serializer contextElementSer)
 {
     for (int actualParamNr = 0; actualParamNr < arguments.Length; actualParamNr++)
     {
         ArgumentMapping paramInfo = m_arguments[actualParamNr];
         // iterate through the parameters, nonOut and nonRetval params are serialised for a request
         if (paramInfo.IsInArg() || paramInfo.IsRefArg())
         {
             paramInfo.Serialize(targetStream, arguments[actualParamNr]);
         }
         // move to next parameter
         // out-args are also part of the arguments array -> move to next for those whithout doing something
     }
     SerializeContextElements(targetStream, context, contextElementSer);
 }
Example #7
0
        private ArgumentMapping DetermineReturnParamMapping(MethodInfo method, SerializerFactory serFactory)
        {
            ArgumentMapping returnMapping;

            // return value
            if (!method.ReturnType.Equals(ReflectionHelper.VoidType))
            {
                AttributeExtCollection returnAttrs =
                    ReflectionHelper.CollectReturnParameterAttributes(method);
                Serializer retMappingSer = serFactory.Create(method.ReturnType, returnAttrs);
                returnMapping = new ArgumentMapping(retMappingSer, ArgumentsKind.Return);
            }
            else
            {
                // no retrun value to serialise/deserialise
                returnMapping = new ArgumentMapping();
            }
            return(returnMapping);
        }
Example #8
0
            internal void SerializeResponseArgs(object result, object[] outArgs,
                                                CdrOutputStream targetStream)
            {
                // first serialise the return value,
                if (m_returnValue.IsNonVoidReturn())
                {
                    m_returnValue.Serialize(targetStream, result);
                }
                // ... then the out/ref args
                int outParamNr = 0;

                for (int actualParamNr = 0; actualParamNr < m_arguments.Length; actualParamNr++)
                {
                    ArgumentMapping paramInfo = m_arguments[actualParamNr];
                    // iterate through the parameters, out/ref parameters are serialised
                    if (paramInfo.IsOutArg() || paramInfo.IsRefArg())
                    {
                        paramInfo.Serialize(targetStream, outArgs[outParamNr]);
                        outParamNr++;
                    }
                }
            }
 internal ArgumentsMapping(ArgumentMapping returnValue, ArgumentMapping[] arguments,
                           string[] contextElementKeys) {
     m_arguments = arguments;
     m_returnValue = returnValue;
     m_contextElementKeys = contextElementKeys;
 }
 private ArgumentMapping[] DetermineParamMappings(MethodInfo method, SerializerFactory serFactory) {
     ParameterInfo[] parameters = method.GetParameters();
     ArgumentMapping[] paramMappings = new ArgumentMapping[parameters.Length];
     for (int actualParamNr = 0; actualParamNr < parameters.Length; actualParamNr++) {
         ParameterInfo paramInfo = parameters[actualParamNr];
         // iterate through the parameters to determine mapping for each
         ArgumentsKind argKind = ArgumentsKind.Unknown;
         if (ReflectionHelper.IsInParam(paramInfo)) {
             argKind = ArgumentsKind.InArg;
         } else if (ReflectionHelper.IsOutParam(paramInfo)) {
             argKind = ArgumentsKind.OutArg;
         } else if (ReflectionHelper.IsRefParam(paramInfo)) {
             argKind = ArgumentsKind.RefArg;
         }
         AttributeExtCollection paramAttrs =
             ReflectionHelper.CollectParameterAttributes(paramInfo,
                                                         method);
         Serializer paramSer = serFactory.Create(paramInfo.ParameterType, paramAttrs);
         paramMappings[actualParamNr] = new ArgumentMapping(paramSer, argKind);
     }
     return paramMappings;
 }
 private ArgumentMapping DetermineReturnParamMapping(MethodInfo method, SerializerFactory serFactory) {
     ArgumentMapping returnMapping;
     // return value
     if (!method.ReturnType.Equals(ReflectionHelper.VoidType)) {
         AttributeExtCollection returnAttrs =
             ReflectionHelper.CollectReturnParameterAttributes(method);
         Serializer retMappingSer = serFactory.Create(method.ReturnType, returnAttrs);
         returnMapping = new ArgumentMapping(retMappingSer, ArgumentsKind.Return);
     } else {
         // no retrun value to serialise/deserialise
         returnMapping = new ArgumentMapping();
     }
     return returnMapping;
 }
        private ArgumentMapping[] ConvertToOpenImplementationArgumentMappingsForType(
           ArgumentMapping mapping, Type type, IList<Type> processedTypes)
        {
            var arguments = mapping.Argument.GetGenericArguments();
            var concreteTypes = type.GetGenericArguments();

            if (concreteTypes.Length != arguments.Length)
            {
                // The length of the concrete list and the generic argument list does not match. This normally
                // means that the generic argument contains a argument that is not generic (so Int32 instead
                // of T). In that case we can ignore everything, because the type will be unusable.
                return Helpers.Array<ArgumentMapping>.Empty;
            }

            return (
                from subMapping in ArgumentMapping.Zip(arguments, concreteTypes)
                from arg in this.ConvertToOpenImplementationArgumentMappings(subMapping, processedTypes).ToArray()
                select arg)
                .ToArray();
        }
        private ArgumentMapping[] ConvertToOpenImplementationArgumentMappingsRecursive(
            ArgumentMapping mapping, IList<Type> processedTypes)
        {
            // If we're dealing with a generic type argument here (which means we're in the verification
            // phase testing open generic types), we must just return the mapping, because we can't deduce
            // things any further.
            if (mapping.ConcreteType.IsGenericParameter)
            {
                return new ArgumentMapping[] { mapping };
            }

            var argumentTypeDefinition = mapping.Argument.GetGenericTypeDefinition();

            // Try to get mappings for each type in the type hierarchy that is compatible to the  argument.
            return (
                from type in mapping.ConcreteType.GetTypeBaseTypesAndInterfacesFor(argumentTypeDefinition)
                from arg in this.ConvertToOpenImplementationArgumentMappingsForType(mapping, type, processedTypes)
                select arg)
                .ToArray();
        }
        private ArgumentMapping[] GetTypeConstraintArgumentMappingsRecursive(ArgumentMapping mapping, IList<Type> processedTypes)
        {
            IEnumerable<Type> constraints = Enumerable.Empty<Type>();

            if (mapping.Argument.IsGenericParameter)
            {
                //// If the type itself is a generic parameter such as TKey (and not for instance IBar<TValue>)
                //// We must skip it, since there is no mappings we can extract from it (while IBar<TValue> could).
                constraints =
                    from constraint in mapping.Argument.Info().GetGenericParameterConstraints()
                    where !constraint.IsGenericParameter
                    select constraint;
            }
            else
            {
                // In case we're dealing with partial generic type's (such as Lazy<List<T>>) the argument is
                // not a generic parameter and the argument (List<T> for instance) itself becomes the
                // constraints.
            }

            return (
                from constraint in constraints
                let constraintMapping = new ArgumentMapping(constraint, mapping.ConcreteType)
                from arg in this.ConvertToOpenImplementationArgumentMappings(constraintMapping, processedTypes).ToArray()
                select arg)
                .ToArray();
        }
        private IEnumerable<ArgumentMapping> ConvertToOpenImplementationArgumentMappings(
            ArgumentMapping mapping, IList<Type> processedTypes)
        {
            // We are only interested in generic parameters
            if (mapping.Argument.IsGenericArgument() && !processedTypes.Contains(mapping.Argument))
            {
                processedTypes.Add(mapping.Argument);

                if (this.implementationTypeDefinitionArguments.Contains(mapping.Argument))
                {
                    // The argument is one of the type's generic arguments. We can directly return it.
                    yield return mapping;

                    foreach (var arg in this.GetTypeConstraintArgumentMappingsRecursive(mapping, processedTypes))
                    {
                        yield return arg;
                    }
                }
                else
                {
                    // The argument is not in the type's list, which means that the real type is (or are)
                    // buried in a generic type (i.e. Nullable<KeyValueType<TKey, TValue>>). This can result
                    // in multiple values.
                    foreach (var arg in this.ConvertToOpenImplementationArgumentMappingsRecursive(mapping, processedTypes))
                    {
                        yield return arg;
                    }
                }
            }
        }