コード例 #1
0
        protected Dictionary <string, object> CreatePrimitiveMapping(PonyTextStructureBase mapStruct)
        {
            if (mapStruct.StructureType != StructureType.MapStruct)
            {
                return(null);
            }
            PonyTextMapStruct           pony     = (PonyTextMapStruct)mapStruct;
            Dictionary <string, object> mappings = new Dictionary <string, object>();

            foreach (var kvpair in pony.GetMappings())
            {
                switch (kvpair.Value.StructureType)
                {
                case StructureType.MarcoStruct:
                    mappings.Add(kvpair.Key, GetText(kvpair.Value));
                    break;

                case StructureType.NumberStruct:
                    mappings.Add(kvpair.Key, kvpair.Value.GetUnderlyingObject());
                    break;

                case StructureType.LiteralStruct:
                    mappings.Add(kvpair.Key, kvpair.Value.GetUnderlyingObject());
                    break;

                default:
                    throw new PreProcessorException($"Mapping can only contain primitive type, but {kvpair.Value.StructureType} was found.");
                }
            }
            return(mappings);
        }
コード例 #2
0
        protected override void OnPreProcessInternal(PonyTextStructureBase[] args)
        {
            string objName = args[0].GetUnderlyingObject() as string;

            objName = $"pt.{objName}";
            PonyTextMapStruct mapStruct = (PonyTextMapStruct)args[1];

            if (objectTable.ContainObject(objName))
            {
                throw new PreProcessorException($"Object \"{objName}\" already defined.");
            }

            ExpandoObject obj = new ExpandoObject();

            foreach (var item in mapStruct.GetMappings())
            {
                if (!AddObjectMember(obj, item.Key, item.Value))
                {
                    throw new PreProcessorException($"Field \"{item.Key}\" already defined.");
                }
            }
            objectTable.TrySetObject(objName, obj);
        }