Beispiel #1
0
 private IEnumerable<string> GetBody() => this.Type.Type.GetProperties()
             .Select(property => new
             {
                 Attributes = Attribute.GetCustomAttributes(property),
                 Property = property
             })
             // do not write attribute that are not serialize throught the [IgnoreDataMember] attribute
             .Where(a => a.Attributes.OfType<IgnoreDataMemberAttribute>().IsEmpty())
             .Select(a =>
             {
                 var nullable = !a.Attributes.OfType<JetBrains.Annotations.NotNullAttribute>().Any();
                 var attributeName = a.Attributes.OfType<DataMemberAttribute>().FirstOrDefault()?.Name;
                 string propertyName = string.IsNullOrWhiteSpace(attributeName) ? a.Property.Name : attributeName;
                 Predicate<Type> includeNamespacePredicate = type => this.Type.Namespace != type.Namespace;
                 var options = new ToTypeScriptOptions().WithIncludeNamespace(includeNamespacePredicate)
                                                        .WithNullable(this.StrictNullCheck && nullable);
                 return $"{propertyName}: { a.Property.PropertyType.ToTypeScript().ToString(options)};";
             });
        /// <summary>
        /// Return method signature in typescript of a C# method
        /// </summary>
        /// <param name="method">The method</param>
        public string GetMethodSignature(MethodInfo method)
        {
            var options = new ToTypeScriptOptions(type => type.Namespace != this.Type.Namespace, true, this.StrictNullCheck);
            var arguments = method.GetParameters()
                    .Select(param => $", {param.Name}: {param.ParameterType.ToTypeScript().ToString(options)}")
                    .Join("");

            return $"{method.Name}(restApi: RestApi{arguments}, config?: RequestConfig)";
        }