Ejemplo n.º 1
0
        public static bool TryParse(PropertyDeclarationSyntax propertyDeclarationSyntax, out ListMemberDefinition propertyDefintion)
        {
            propertyDefintion = null;
            var name = propertyDeclarationSyntax.Identifier.Text;

            if (!(propertyDeclarationSyntax.Type is GenericNameSyntax typeNameSyntax))
            {
                return(false);
            }

            if (!(typeNameSyntax.Identifier.Text == "List" || typeNameSyntax.Identifier.Text == "System.Collections.Generic.List"))
            {
                return(false);
            }

            if (typeNameSyntax.TypeArgumentList.Arguments.Count != 1)
            {
                return(false);
            }

            var type = typeNameSyntax.TypeArgumentList.Arguments[0].ToString();

            Utils.TryGetValueType(type, out var valueTypeKind, out var nullable);

            propertyDefintion = new ListMemberDefinition(name, valueTypeKind, nullable);

            return(propertyDefintion != null);
        }
        public ListDeserializerTemplate(Model.ListMemberDefinition list)
        {
            List = list;

            /*
             * bw.Write(<#= List.Name #>.Count);
             * foreach (var item in <#= List.Name #>)
             * {
             * <# if (List.Type != NativePack.Model.ValueTypeKind.Undefined) { #>
             *
             * <# if (!List.Nullable) { #>
             * writer.Write(item);
             * <# } else {#>
             * writer.Write(item != null ? (byte)1 : (byte)0);
             * if (item != null)
             * writer.Write(item);
             * <# } #>
             *
             * <# } #>
             * }
             */
        }
 public ListSerializerTemplate(Model.ListMemberDefinition list)
 {
     List = list;
 }