Beispiel #1
0
        public void Sync(SyncContext ctx)
        {
            if (ctx.is_read)
            {
                types = ((SymbolFactory)ctx.factory).types;
            }
            else if (string.IsNullOrEmpty(_name))
            {
                throw new Exception("TypeProxy name is empty");
            }

            Marshall.Sync(ctx, ref _name);

            IMarshallableGeneric mg = null;

            if (ctx.is_read)
            {
                Marshall.SyncGeneric(ctx, ref mg);
                type = (IType)mg;
            }
            else
            {
                var resolved = Get();
                //TODO: make this check more robust
                bool defined_in_scope =
                    resolved is Symbol symb &&
                    (symb.scope is ModuleScope ||
                     symb is BuiltInSymbol ||
                     symb is ClassSymbolNative ||
                     symb is InterfaceSymbolNative ||
                     symb is EnumSymbol ||
                     (symb is ArrayTypeSymbol && !(symb is GenericArrayTypeSymbol))
                    );

                //NOTE: we want to marshall only those types which are not
                //      defined elsewhere otherwise we just want to keep
                //      string reference at them
                if (!defined_in_scope)
                {
                    mg = resolved as IMarshallableGeneric;
                    if (mg == null)
                    {
                        throw new Exception("Type is not marshallable: " + (resolved != null ? resolved.GetType().Name + " " : "<null> ") + _name);
                    }
                }
                Marshall.SyncGeneric(ctx, ref mg);
            }
        }