Пример #1
0
        public static void AddDeferredMarshalCall(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string marshal_name, string var_name, params RpcMarshalArgument[] additional_args)
        {
            List <CodeExpression> args = new List <CodeExpression>
            {
                GetVariable(var_name)
            };

            List <CodeTypeReference> marshal_args = new List <CodeTypeReference>();

            marshal_args.Add(descriptor.CodeType);
            marshal_args.AddRange(descriptor.AdditionalArgs.Select(a => a.CodeType));
            marshal_args.AddRange(additional_args.Select(a => a.CodeType));

            string method_name;

            if (descriptor.Constructed)
            {
                method_name = "WriteEmbeddedStructPointer";
            }
            else
            {
                method_name = "WriteEmbeddedPointer";
                var create_delegate = new CodeDelegateCreateExpression(CreateActionType(marshal_args.ToArray()),
                                                                       GetVariable(marshal_name), descriptor.MarshalMethod);

                args.Add(create_delegate);
                args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
                args.AddRange(additional_args.Select(r => r.Expression));
            }
            CodeMethodReferenceExpression write_pointer = new CodeMethodReferenceExpression(GetVariable(marshal_name), method_name, marshal_args.ToArray());
            CodeMethodInvokeExpression    invoke        = new CodeMethodInvokeExpression(write_pointer, args.ToArray());

            method.Statements.Add(invoke);
        }
Пример #2
0
 public RpcTypeDescriptor(RpcTypeDescriptor original_desc, RpcPointerType pointer_type)
     : this(original_desc.CodeType, original_desc.ValueType, original_desc.UnmarshalMethod, original_desc.UnmarshalGeneric,
            original_desc.MarshalMethod, original_desc.NdrType, original_desc.ConformanceDescriptor, original_desc.VarianceDescriptor, original_desc.AdditionalArgs)
 {
     PointerType = pointer_type;
     Constructed = original_desc.Constructed;
 }
Пример #3
0
        public static void AddUnmarshalReturn(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string unmarshal_name, params RpcMarshalArgument[] additional_args)
        {
            List <CodeExpression> args = new List <CodeExpression>();

            args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
            args.AddRange(additional_args.Select(r => r.Expression));
            CodeMethodReturnStatement ret = new CodeMethodReturnStatement(new CodeMethodInvokeExpression(descriptor.GetUnmarshalMethod(GetVariable(unmarshal_name)), args.ToArray()));

            method.Statements.Add(ret);
        }
Пример #4
0
        public static void AddUnmarshalCall(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string unmarshal_name, string var_name, params CodeExpression[] additional_args)
        {
            List <CodeExpression> args = new List <CodeExpression>();

            args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
            args.AddRange(additional_args);

            CodeAssignStatement assign = new CodeAssignStatement(GetVariable(var_name), new CodeMethodInvokeExpression(descriptor.GetUnmarshalMethod(GetVariable(unmarshal_name)), args.ToArray()));

            method.Statements.Add(assign);
        }
Пример #5
0
        public static void AddConstructorMethod(this CodeTypeDeclaration type, RpcTypeDescriptor complex_type, IEnumerable <Tuple <CodeTypeReference, string> > parameters)
        {
            if (!parameters.Any())
            {
                return;
            }

            CodeMemberMethod method = type.AddConstructor(MemberAttributes.Public | MemberAttributes.Final);

            method.AddAssignmentStatements(new CodeThisReferenceExpression(), parameters);
        }
Пример #6
0
        public static void AddMarshalCall(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string marshal_name, string var_name, params RpcMarshalArgument[] additional_args)
        {
            List <CodeExpression> args = new List <CodeExpression>
            {
                GetVariable(var_name)
            };

            args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
            args.AddRange(additional_args.Select(r => r.Expression));
            CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(descriptor.GetMarshalMethod(GetVariable(marshal_name)), args.ToArray());

            method.Statements.Add(invoke);
        }
Пример #7
0
        public static void AddPointerUnmarshalCall(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string unmarshal_name, string var_name, params CodeExpression[] additional_args)
        {
            List <CodeExpression> args = new List <CodeExpression>();

            args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
            args.AddRange(additional_args);
            CodeAssignStatement assign      = new CodeAssignStatement(GetVariable(var_name), new CodeMethodInvokeExpression(descriptor.GetUnmarshalMethod(GetVariable(unmarshal_name)), args.ToArray()));
            CodeAssignStatement assign_null = new CodeAssignStatement(GetVariable(var_name), new CodeDefaultValueExpression(descriptor.GetParameterType()));

            CodeConditionStatement if_statement = new CodeConditionStatement(
                new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(GetVariable(unmarshal_name), "ReadReferent"), CodeBinaryOperatorType.IdentityInequality, GetPrimitive(0)),
                new CodeStatement[] { assign }, new CodeStatement[] { assign_null });

            method.Statements.Add(if_statement);
        }
Пример #8
0
        public static void AddDeferredEmbeddedUnmarshalCall(this CodeMemberMethod method, RpcTypeDescriptor descriptor, string unmarshal_name, string var_name, params RpcMarshalArgument[] additional_args)
        {
            string method_name         = null;
            List <CodeExpression> args = new List <CodeExpression>();

            List <CodeTypeReference> marshal_args = new List <CodeTypeReference>();

            marshal_args.Add(descriptor.CodeType);
            marshal_args.AddRange(descriptor.AdditionalArgs.Select(a => a.CodeType));
            marshal_args.AddRange(additional_args.Select(a => a.CodeType));

            if (descriptor.Constructed)
            {
                method_name = "ReadEmbeddedStructPointer";
            }
            else
            {
                if (descriptor.UnmarshalGeneric)
                {
                    method.ThrowNotImplemented("Can't support generic pointer unmarshal");
                    return;
                }
                method_name = "ReadEmbeddedPointer";
                var create_delegate = new CodeDelegateCreateExpression(CreateFuncType(descriptor.CodeType, marshal_args.Skip(1).ToArray()),
                                                                       GetVariable(unmarshal_name), descriptor.UnmarshalMethod);
                args.Add(create_delegate);
            }

            args.AddRange(descriptor.AdditionalArgs.Select(r => r.Expression));
            args.AddRange(additional_args.Select(r => r.Expression));
            CodeMethodReferenceExpression read_pointer = new CodeMethodReferenceExpression(GetVariable(unmarshal_name), method_name, marshal_args.ToArray());
            CodeMethodInvokeExpression    invoke       = new CodeMethodInvokeExpression(read_pointer, args.ToArray());
            CodeAssignStatement           assign       = new CodeAssignStatement(GetVariable(var_name), invoke);

            method.Statements.Add(assign);
        }
Пример #9
0
        public static void AddArrayConstructorMethod(this CodeTypeDeclaration type, string name, RpcTypeDescriptor complex_type)
        {
            CodeMemberMethod method = type.AddMethod(name, MemberAttributes.Public | MemberAttributes.Final);

            method.AddParam(new CodeTypeReference(typeof(int)), "size");
            method.ReturnType = complex_type.GetArrayType();
            method.AddReturn(new CodeArrayCreateExpression(complex_type.CodeType, GetVariable("size")));
        }
Пример #10
0
        public static void AddConstructorMethod(this CodeTypeDeclaration type, string name, RpcTypeDescriptor complex_type, IEnumerable <Tuple <CodeTypeReference, string> > parameters)
        {
            if (!parameters.Any())
            {
                return;
            }

            CodeMemberMethod method = type.AddMethod(name, MemberAttributes.Public | MemberAttributes.Final);

            method.ReturnType = complex_type.CodeType;
            method.Statements.Add(new CodeVariableDeclarationStatement(complex_type.CodeType, "ret", new CodeObjectCreateExpression(complex_type.CodeType)));
            CodeExpression return_value = GetVariable("ret");

            method.AddAssignmentStatements(return_value, parameters);
            method.AddReturn(return_value);
        }
Пример #11
0
        public static void AddDefaultConstructorMethod(this CodeTypeDeclaration type, string name, MemberAttributes attributes, RpcTypeDescriptor complex_type, Dictionary <string, CodeExpression> initialize_expr)
        {
            CodeMemberMethod method = type.AddMethod(name, attributes);

            method.ReturnType = complex_type.CodeType;
            CodeExpression return_value = new CodeObjectCreateExpression(complex_type.CodeType);

            if (initialize_expr.Count > 0)
            {
                method.Statements.Add(new CodeVariableDeclarationStatement(complex_type.CodeType, "ret", return_value));
                return_value = GetVariable("ret");
                method.Statements.AddRange(initialize_expr.Select(p => new CodeAssignStatement(return_value.GetFieldReference(p.Key), p.Value)).ToArray());
            }
            method.AddReturn(return_value);
        }
Пример #12
0
        private RpcTypeDescriptor GetTypeDescriptorInternal(NdrBaseTypeReference type)
        {
            if (type is NdrSimpleTypeReference)
            {
                switch (type.Format)
                {
                case NdrFormatCharacter.FC_BYTE:
                case NdrFormatCharacter.FC_USMALL:
                    return(new RpcTypeDescriptor(typeof(byte), "ReadByte", false, "WriteByte", type, null, null));

                case NdrFormatCharacter.FC_SMALL:
                case NdrFormatCharacter.FC_CHAR:
                    return(new RpcTypeDescriptor(typeof(sbyte), "ReadSByte", false, "WriteSByte", type, null, null));

                case NdrFormatCharacter.FC_WCHAR:
                    return(new RpcTypeDescriptor(typeof(char), "ReadChar", false, "WriteChar", type, null, null));

                case NdrFormatCharacter.FC_SHORT:
                    return(new RpcTypeDescriptor(typeof(short), "ReadInt16", false, "WriteInt16", type, null, null));

                case NdrFormatCharacter.FC_USHORT:
                    return(new RpcTypeDescriptor(typeof(ushort), "ReadUInt16", false, "WriteUInt16", type, null, null));

                case NdrFormatCharacter.FC_LONG:
                case NdrFormatCharacter.FC_ENUM16:
                case NdrFormatCharacter.FC_ENUM32:
                    return(new RpcTypeDescriptor(typeof(int), "ReadInt32", false, "WriteInt32", type, null, null));

                case NdrFormatCharacter.FC_ULONG:
                case NdrFormatCharacter.FC_ERROR_STATUS_T:
                    return(new RpcTypeDescriptor(typeof(uint), "ReadUInt32", false, "WriteUInt32", type, null, null));

                case NdrFormatCharacter.FC_FLOAT:
                    return(new RpcTypeDescriptor(typeof(float), "ReadFloat", false, "WriteFloat", type, null, null));

                case NdrFormatCharacter.FC_HYPER:
                    return(new RpcTypeDescriptor(typeof(long), "ReadInt64", false, "WriteInt64", type, null, null));

                case NdrFormatCharacter.FC_DOUBLE:
                    return(new RpcTypeDescriptor(typeof(double), "ReadDouble", false, "WriteDouble", type, null, null));

                case NdrFormatCharacter.FC_INT3264:
                    return(new RpcTypeDescriptor(typeof(NdrInt3264), "ReadInt3264", false, "WriteInt3264", type, null, null));

                case NdrFormatCharacter.FC_UINT3264:
                    return(new RpcTypeDescriptor(typeof(NdrUInt3264), "ReadUInt3264", false, "WriteUInt3264", type, null, null));

                case NdrFormatCharacter.FC_C_WSTRING:
                    return(new RpcTypeDescriptor(typeof(string), "ReadConformantString", false, "WriteConformantString", type, null, null));

                case NdrFormatCharacter.FC_C_CSTRING:
                    return(new RpcTypeDescriptor(typeof(string), "ReadAnsiConformantString", false, "WriteAnsiConformantString", type, null, null));

                case NdrFormatCharacter.FC_CSTRING:
                case NdrFormatCharacter.FC_WSTRING:
                    break;
                }
            }
            else if (type is NdrKnownTypeReference known_type)
            {
                switch (known_type.KnownType)
                {
                case NdrKnownTypes.GUID:
                    return(new RpcTypeDescriptor(typeof(Guid), "ReadGuid", false, "WriteGuid", type, null, null));

                case NdrKnownTypes.BSTR:
                case NdrKnownTypes.HSTRING:
                    // Implement these custom marshallers.
                    break;
                }
            }
            else if (type is NdrBaseStringTypeReference)
            {
                if (type is NdrConformantStringTypeReference conformant_str)
                {
                    if (conformant_str.Format == NdrFormatCharacter.FC_C_CSTRING)
                    {
                        return(new RpcTypeDescriptor(typeof(string), "ReadAnsiConformantString", false, "WriteAnsiConformantString", type, null, null));
                    }
                    return(new RpcTypeDescriptor(typeof(string), "ReadConformantString", false, "WriteConformantString", type, null, null));
                }
            }
            else if (type is NdrSystemHandleTypeReference system_handle)
            {
                return(new RpcTypeDescriptor(system_handle.GetSystemHandleType(),
                                             "ReadSystemHandle", true, "WriteSystemHandle", type, null, null));
            }
            else if (type is NdrSimpleArrayTypeReference simple_array)
            {
                RpcTypeDescriptor  element_type = GetTypeDescriptor(simple_array.ElementType);
                RpcMarshalArgument arg          = new RpcMarshalArgument
                {
                    CodeType   = new CodeTypeReference(typeof(int)),
                    Expression = CodeGenUtils.GetPrimitive(simple_array.ElementCount)
                };
                if (element_type.BuiltinType == typeof(char))
                {
                    return(new RpcTypeDescriptor(typeof(string), "ReadFixedString", false, "WriteFixedString", type, null, null, arg)
                    {
                        FixedCount = simple_array.ElementCount
                    });
                }
                else if (element_type.BuiltinType == typeof(byte))
                {
                    return(new RpcTypeDescriptor(typeof(byte[]), "ReadBytes", false, "WriteFixedBytes", type, null, null, arg)
                    {
                        FixedCount = simple_array.ElementCount
                    });
                }
            }
            else if (type is NdrPointerTypeReference pointer)
            {
                var            desc         = GetTypeDescriptor(pointer.Type);
                RpcPointerType pointer_type = RpcPointerType.None;
                switch (pointer.Format)
                {
                case NdrFormatCharacter.FC_UP:
                    pointer_type = RpcPointerType.Unique;
                    break;

                case NdrFormatCharacter.FC_RP:
                    pointer_type = RpcPointerType.Reference;
                    break;

                default:
                    pointer_type = RpcPointerType.Full;
                    break;
                }
                return(new RpcTypeDescriptor(desc, pointer_type));
            }
            else if (type is NdrSupplementTypeReference supp)
            {
                return(GetTypeDescriptor(supp.SupplementType));
            }
            else if (type is NdrHandleTypeReference handle)
            {
                if (handle.Format == NdrFormatCharacter.FC_BIND_CONTEXT)
                {
                    return(new RpcTypeDescriptor(typeof(NdrContextHandle), "ReadContextHandle", false, "WriteContextHandle", type, null, null));
                }
            }
            else if (type is NdrRangeTypeReference range)
            {
                return(GetTypeDescriptor(range.RangeType));
            }
            else if (type is NdrBogusArrayTypeReference bogus_array)
            {
                RpcTypeDescriptor element_type = GetTypeDescriptor(bogus_array.ElementType);
                if (bogus_array.VarianceDescriptor.IsValid && bogus_array.VarianceDescriptor.ValidateCorrelation() &&
                    !bogus_array.ConformanceDescriptor.IsValid && element_type.Constructed)
                {
                    // For now we only support constructed types with variance and no conformance.
                    // The variance also needs to be a constant or a normal correlation.
                    return(new RpcTypeDescriptor(new CodeTypeReference(element_type.CodeType, 1), false,
                                                 "ReadVaryingBogusArrayStruct", true, "WriteVaryingBogusArrayStruct",
                                                 type, null, bogus_array.VarianceDescriptor)
                    {
                        FixedCount = bogus_array.ElementCount
                    });
                }
            }

            var type_name_arg = new RpcMarshalArgument()
            {
                CodeType   = new CodeTypeReference(typeof(string)),
                Expression = new CodePrimitiveExpression(type.Format.ToString())
            };

            return(new RpcTypeDescriptor(typeof(NdrUnsupported), "ReadUnsupported", false, "WriteUnsupported", type, null, null, type_name_arg));
        }
Пример #13
0
        private void GenerateClient(string name, CodeNamespace ns, int complex_type_count)
        {
            CodeTypeDeclaration type = ns.AddType(name);

            type.IsClass        = true;
            type.TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed;
            type.BaseTypes.Add(typeof(RpcAlpcClientBase));

            CodeConstructor constructor = type.AddConstructor(MemberAttributes.Public | MemberAttributes.Final);

            constructor.BaseConstructorArgs.Add(CodeGenUtils.GetPrimitive(_server.InterfaceId.ToString()));
            constructor.BaseConstructorArgs.Add(CodeGenUtils.GetPrimitive(_server.InterfaceVersion.Major));
            constructor.BaseConstructorArgs.Add(CodeGenUtils.GetPrimitive(_server.InterfaceVersion.Minor));

            foreach (var proc in _server.Procedures)
            {
                string proc_name = proc.Name;
                if (!_proc_names.Add(proc_name))
                {
                    proc_name = $"{proc_name}_{proc.ProcNum}";
                    if (!_proc_names.Add(proc_name))
                    {
                        throw new ArgumentException($"Duplicate name {proc.Name}");
                    }
                }

                var method = type.AddMethod(proc_name, MemberAttributes.Public | MemberAttributes.Final);
                RpcTypeDescriptor return_type = GetTypeDescriptor(proc.ReturnValue.Type);
                if (return_type == null)
                {
                    method.ThrowNotImplemented("Return type unsupported.");
                    continue;
                }

                var offset_to_name =
                    proc.Params.Select(p => Tuple.Create(p.Offset, p.Name)).ToList();

                method.ReturnType = return_type.CodeType;
                method.CreateMarshalObject(MARSHAL_NAME);
                foreach (var p in proc.Params)
                {
                    if (p == proc.Handle)
                    {
                        continue;
                    }
                    RpcTypeDescriptor p_type = GetTypeDescriptor(p.Type);

                    List <RpcMarshalArgument> extra_marshal_args = new List <RpcMarshalArgument>();
                    if (p_type.VarianceDescriptor.IsValid)
                    {
                        extra_marshal_args.Add(p_type.VarianceDescriptor.CalculateCorrelationArgument(p.Offset, offset_to_name));
                    }

                    var p_obj = method.AddParam(p_type.GetParameterType(), p.Name);
                    p_obj.Direction = p.GetDirection();
                    if (!p.IsIn)
                    {
                        continue;
                    }
                    if (p_type.Pointer)
                    {
                        if (p_type.PointerType == RpcPointerType.Reference)
                        {
                            method.AddNullCheck(MARSHAL_NAME, p.Name);
                        }
                        else
                        {
                            method.AddWriteReferent(MARSHAL_NAME, p.Name);
                        }
                    }
                    else if (!p_type.ValueType)
                    {
                        method.AddNullCheck(MARSHAL_NAME, p.Name);
                    }
                    method.AddMarshalCall(p_type, MARSHAL_NAME, p.Name, extra_marshal_args.ToArray());
                    // If it's a constructed type then ensure any deferred writes are flushed.
                    if (p_type.Constructed)
                    {
                        method.AddFlushDeferredWrites(MARSHAL_NAME);
                    }
                }

                method.SendReceive(MARSHAL_NAME, UNMARSHAL_NAME, proc.ProcNum);

                foreach (var p in proc.Params.Where(x => x.IsOut))
                {
                    if (p == proc.Handle)
                    {
                        continue;
                    }

                    RpcTypeDescriptor p_type = GetTypeDescriptor(p.Type);
                    if (p_type.Pointer)
                    {
                        method.AddPointerUnmarshalCall(p_type, UNMARSHAL_NAME, p.Name);
                    }
                    else
                    {
                        method.AddUnmarshalCall(p_type, UNMARSHAL_NAME, p.Name);
                    }
                    if (p_type.Constructed)
                    {
                        method.AddPopluateDeferredPointers(UNMARSHAL_NAME);
                    }
                }

                method.AddUnmarshalReturn(return_type, UNMARSHAL_NAME);
            }

            if (complex_type_count > 0 && HasFlag(RpcClientBuilderFlags.GenerateConstructorProperties))
            {
                var constructor_type = new CodeTypeReference(CodeGenUtils.MakeIdentifier(CONSTRUCTOR_STRUCT_NAME));
                var prop             = type.AddProperty("New", constructor_type, MemberAttributes.Public | MemberAttributes.Final,
                                                        new CodeMethodReturnStatement(new CodeObjectCreateExpression(constructor_type)));
                constructor_type = new CodeTypeReference(CodeGenUtils.MakeIdentifier(ARRAY_CONSTRUCTOR_STRUCT_NAME));
                type.AddProperty("NewArray", constructor_type, MemberAttributes.Public | MemberAttributes.Final,
                                 new CodeMethodReturnStatement(new CodeObjectCreateExpression(constructor_type)));
            }
        }
Пример #14
0
        private int GenerateComplexTypes(CodeNamespace ns)
        {
            int type_count = 0;

            // First populate the type cache.
            foreach (var complex_type in _server.ComplexTypes)
            {
                if (complex_type is NdrBaseStructureTypeReference struct_type)
                {
                    _type_descriptors[complex_type] = new RpcTypeDescriptor(complex_type.Name, true,
                                                                            "ReadStruct", true, "WriteStruct", complex_type, null, null);
                    type_count++;
                }
            }

            if (type_count == 0)
            {
                return(0);
            }

            bool create_constructor_properties         = HasFlag(RpcClientBuilderFlags.GenerateConstructorProperties);
            CodeTypeDeclaration constructor_type       = null;
            CodeTypeDeclaration array_constructor_type = null;

            if (create_constructor_properties)
            {
                constructor_type                = ns.AddType(CONSTRUCTOR_STRUCT_NAME);
                constructor_type.IsStruct       = true;
                array_constructor_type          = ns.AddType(ARRAY_CONSTRUCTOR_STRUCT_NAME);
                array_constructor_type.IsStruct = true;
            }

            // Now generate the complex types.
            foreach (var complex_type in _server.ComplexTypes)
            {
                if (!(complex_type is NdrBaseStructureTypeReference struct_type))
                {
                    ns.Comments.Add(new CodeCommentStatement($"Unsupported type {complex_type.GetType()} {complex_type.Name}"));
                    continue;
                }

                var s_type = ns.AddType(complex_type.Name);
                s_type.IsStruct = true;
                s_type.BaseTypes.Add(new CodeTypeReference(typeof(INdrStructure)));

                var marshal_method = s_type.AddMarshalMethod(MARSHAL_NAME);
                marshal_method.AddAlign(MARSHAL_NAME, struct_type.Alignment + 1);
                var unmarshal_method = s_type.AddUnmarshalMethod(UNMARSHAL_NAME);
                unmarshal_method.AddAlign(UNMARSHAL_NAME, struct_type.Alignment + 1);

                var offset_to_name =
                    struct_type.Members.Select(m => Tuple.Create(m.Offset, m.Name)).ToList();
                var default_initialize_expr = new Dictionary <string, CodeExpression>();
                var member_parameters       = new List <Tuple <CodeTypeReference, string> >();

                foreach (var member in struct_type.Members)
                {
                    var f_type = GetTypeDescriptor(member.MemberType);
                    s_type.AddField(f_type.GetStructureType(), member.Name, MemberAttributes.Public);
                    member_parameters.Add(Tuple.Create(f_type.GetParameterType(), member.Name));

                    List <RpcMarshalArgument> extra_marshal_args = new List <RpcMarshalArgument>();
                    if (f_type.VarianceDescriptor.IsValid)
                    {
                        extra_marshal_args.Add(f_type.VarianceDescriptor.CalculateCorrelationArgument(member.Offset, offset_to_name));
                    }

                    if (f_type.Pointer)
                    {
                        marshal_method.AddDeferredMarshalCall(f_type, MARSHAL_NAME, member.Name, extra_marshal_args.ToArray());
                        unmarshal_method.AddDeferredEmbeddedUnmarshalCall(f_type, UNMARSHAL_NAME, member.Name);
                    }
                    else
                    {
                        if (!f_type.ValueType)
                        {
                            marshal_method.AddNullCheck(MARSHAL_NAME, member.Name);
                        }

                        marshal_method.AddMarshalCall(f_type, MARSHAL_NAME, member.Name, extra_marshal_args.ToArray());
                        unmarshal_method.AddUnmarshalCall(f_type, UNMARSHAL_NAME, member.Name);
                    }

                    if (!f_type.Pointer || f_type.PointerType == RpcPointerType.Reference)
                    {
                        if (f_type.CodeType.ArrayRank > 0)
                        {
                            default_initialize_expr.Add(member.Name, new CodeArrayCreateExpression(f_type.CodeType, CodeGenUtils.GetPrimitive(f_type.FixedCount)));
                        }
                        else if (f_type.BuiltinType == typeof(string) && f_type.FixedCount > 0)
                        {
                            default_initialize_expr.Add(member.Name, new CodeObjectCreateExpression(f_type.CodeType, CodeGenUtils.GetPrimitive('\0'),
                                                                                                    CodeGenUtils.GetPrimitive(f_type.FixedCount)));
                        }
                    }
                }

                var p_type = _type_descriptors[complex_type];

                if (!create_constructor_properties)
                {
                    s_type.AddDefaultConstructorMethod("CreateDefault", MemberAttributes.Public | MemberAttributes.Static, p_type, default_initialize_expr);
                    s_type.AddConstructorMethod(p_type, member_parameters);
                }
                else
                {
                    constructor_type.AddDefaultConstructorMethod(complex_type.Name, MemberAttributes.Public | MemberAttributes.Final, p_type, default_initialize_expr);
                    constructor_type.AddConstructorMethod(complex_type.Name, p_type, member_parameters);
                    array_constructor_type.AddArrayConstructorMethod(complex_type.Name, p_type);
                }
            }

            return(type_count);
        }