Пример #1
0
        private void _WriteOneClassOrStruct(Type type, ExportFlags flags)
        {
            var classOrStruct = type.IsClass ? "class" : "struct";
            var sealedClass   = type.IsClass && EditorMetaCommon.IsFinalType(type) ? "sealed " : string.Empty;

            _writer.WriteLine("[Serializable]");
            _writer.WriteLine("{0}partial {1} {2} : {3}", sealedClass, classOrStruct, type.Name, typeof(ILoadable).Name);

            using (MacroScope.CreateEditorScope(_writer.BaseWriter))
            {
                _writer.WriteLine(", {0}", typeof(ISavable).Name);
            }

            using (CodeScope.CreateCSharpScope(_writer))
            {
                var nestedTypes = type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Public);
                _WriteNestedTypes(nestedTypes, flags);

                var members = new List <MemberBase>();
                _CollectSerializableMembers(type, members);

                _WriteSaveMethod(type, members);
                _WriteLoadMethod(type, members);
                _WriteToStringMethod(type, members);
                _WriteGetMetadataTypeMethod(type);
            }
        }
Пример #2
0
        private void _WriteSaveMetadata(CodeWriter writer)
        {
            if (!EditorMetaCommon.IsFinalType(_type))
            {
                writer.WriteLine("var {0}Type = {0}.GetMetadataType();", _name);
                writer.WriteLine("writer.Write({0}Type);", _name);
            }

            writer.WriteLine("{0}.Save(writer);", _name);
        }
Пример #3
0
        private void _WriteLoadMetadata(CodeWriter writer)
        {
            if (EditorMetaCommon.IsFinalType(_type))
            {
                writer.WriteLine("{0} = new {1}();", _name, EditorMetaCommon.GetMetaTypeName(_type));
            }
            else
            {
                Console.Error.WriteLine("IMetadata must be assignableFrom from MetadataMemmbers!");
            }

            writer.WriteLine("{0}.Load(reader);", _name);
        }