Exemple #1
0
        public override void WriteLoad(CodeWriter writer)
        {
            Type   elementType     = _type.GetGenericArguments() [0];
            string elementTypeName = EditorMetaCommon.GetNestedClassName(elementType);

            writer.WriteLine("int {0}Count = reader.ReadInt32();", _name);
            writer.WriteLine("if (null == {0}) {{ {0} = new List<{1}>({0}Count); }} else {{ {0}.Clear(); }}", _name, elementTypeName);
            writer.WriteLine("for (int index= 0; index < {0}Count; ++index)", _name);

            using (CodeScope.CreateCSharpScope(writer))
            {
                writer.WriteLine("{0}.Add (default({1}));", _name, elementTypeName);
                _WriteLoadType(writer, elementType, _name + "[index]");
            }
        }
Exemple #2
0
        private void _WriteEqualsToMethod(Type type, List <MemberBase> members)
        {
            _writer.WriteLine("[Export(ExportFlags.AutoCode)]");
            if (_rootTypes.Contains(type))
            {
                _writer.WriteLine("public virtual bool EqualsTo (IMetadata other)");
                using (CodeScope.CreateCSharpScope(_writer))
                {
                    _writer.WriteLine("throw new NotImplementedException(\"This method should be override~\");");
                }
            }
            else
            {
                var overrideText = _rootTypes.Contains(EditorMetaCommon.GetRootMetadata(type)) ? "override " : string.Empty;
                _writer.WriteLine("public {0}bool EqualsTo (IMetadata other)", overrideText);

                using (CodeScope.CreateCSharpScope(_writer))
                {
                    var typeName = EditorMetaCommon.GetNestedClassName(type);
                    _writer.WriteLine("var that = ({0}) other;", typeName);

                    if (type.IsClass)
                    {
                        _writer.WriteLine("if (null == that)");
                        using (CodeScope.CreateCSharpScope(_writer))
                        {
                            _writer.WriteLine("return false;");
                        }
                    }

                    var memberCount = members.Count;

                    for (int index = 0; index < memberCount; ++index)
                    {
                        var member = members[index];
                        member.WriteNotEqualsReturn(_writer);
                    }

                    _writer.WriteLine("return true;");
                }
            }
        }
Exemple #3
0
        public override void WriteLoad(CodeWriter writer)
        {
            string childtype = EditorMetaCommon.GetNestedClassName(_type.GetElementType()).Replace("+", ".");
            string prefix    = childtype;
            string postfix   = string.Empty;
            int    first     = childtype.IndexOf("[", StringComparison.Ordinal);

            if (first >= 0)
            {
                prefix  = childtype.Substring(0, first);
                postfix = childtype.Substring(first);
            }

            writer.WriteLine("{0} = new {1}[reader.ReadInt32()]{2};", _name, prefix, postfix);
            writer.WriteLine("for (int i{1} = 0; i{1} < {0}.Length; i{1}++)", _name, writer.Indent);
            using (CodeScope.CreateCSharpScope(writer))
            {
                _WriteLoadType(writer, _type.GetElementType(), _name + string.Format("[i{0}]", writer.Indent - 1));
            }
        }
Exemple #4
0
 public override void WriteLoad(CodeWriter writer)
 {
     writer.WriteLine("{0} = ({1}) reader.ReadUInt16();", _name, EditorMetaCommon.GetNestedClassName(_type));
 }