Exemple #1
0
            private object /*!*/ ReadObject()
            {
                RubyClass theClass   = ReadType();
                int       count      = ReadInt32();
                var       attributes = new Dictionary <string, object>();

                for (int i = 0; i < count; i++)
                {
                    string name = ReadIdentifier();
                    attributes[name] = ReadAnObject(false);
                }
                return(RubyUtils.CreateObject(theClass, attributes));
            }
Exemple #2
0
            private object /*!*/ ReadObject()
            {
                RubyClass theClass   = ReadType();
                int       count      = ReadInt32();
                Hash      attributes = new Hash(_context);

                for (int i = 0; i < count; i++)
                {
                    string name = ReadSymbol();
                    attributes[name] = ReadAnObject(false);
                }
                return(RubyUtils.CreateObject(theClass, attributes, false));
            }
Exemple #3
0
        private static object ConstructPrivateObject(RubyConstructor /*!*/ ctor, string className, Node node)
        {
            MappingNode mapping = node as MappingNode;

            if (mapping == null)
            {
                throw new ConstructorException("can only construct private type from mapping node");
            }
            RubyModule      module;
            RubyGlobalScope globalScope = ctor.GlobalScope;

            if (globalScope.Context.TryGetModule(globalScope, className, out module))
            {
                if (!module.IsClass)
                {
                    throw new ConstructorException("Cannot construct module");
                }
                Hash           values = ctor.ConstructMapping(mapping);
                RubyMethodInfo method = module.GetMethod("yaml_initialize") as RubyMethodInfo;
                if (method != null)
                {
                    // TODO: call allocate here:
                    object result = RubyUtils.CreateObject((RubyClass)module);
                    ctor._yamlInitializeSite.Target(ctor._yamlInitializeSite, result, className, values);
                    return(result);
                }
                else
                {
                    return(RubyUtils.CreateObject((RubyClass)module, EnumerateAttributes(globalScope.Context, values)));
                }
            }
            else
            {
                //TODO: YAML::Object
                throw new NotImplementedError("YAML::Object is not implemented yet");
            }
        }
        public static object ConstructPrivateObject(IConstructor ctor, string className, Node node)
        {
            MappingNode mapping = node as MappingNode;

            if (mapping == null)
            {
                throw new ConstructorException("can only construct private type from mapping node");
            }
            RubyModule module;
            RubyScope  scope = ctor.Scope;

            if (scope.RubyContext.TryGetModule(scope.GlobalScope, className, out module))
            {
                if (!module.IsClass)
                {
                    throw new ConstructorException("Cannot construct module");
                }
                Hash           values = ctor.ConstructMapping(mapping);
                RubyMethodInfo method = (module.GetMethod("yaml_initialize") as RubyMethodInfo);
                if (method != null)
                {
                    object result = RubyUtils.CreateObject((RubyClass)module);
                    _YamlInitialize.Target(_YamlInitialize, scope.RubyContext, result, className, values);
                    return(result);
                }
                else
                {
                    return(RubyUtils.CreateObject((RubyClass)module, values, true));
                }
            }
            else
            {
                //TODO: YAML::Object
                throw new NotImplementedError("YAML::Object is not implemented yet");
            }
        }
Exemple #5
0
 private object /*!*/ UnmarshalNewObject()
 {
     return(RubyUtils.CreateObject(ReadType()));
 }