Skip to content

Instantly share code, notes, and snippets.

View MNie's full-sized avatar
🎯
#dd

Michał Niegrzybowski MNie

🎯
#dd
View GitHub Profile
private static string ToString(IContainer container, IFieldType field, Type toResolve, int deep) =>
toResolve.IsAssignableTo<IComplexGraphType>()
? ToStringAsField(container, field, toResolve, deep, FieldFormat)
: ToStringAsUnion(container, field, toResolve, deep);
private static string FormatWithPropertiesForUnions(IContainer container, IFieldType field, Type toResolve, int deep)
{
var unionTypes = (UnionGraphType) container.Resolve(toResolve);
var unions = unionTypes.Types
.Select(type => FormatAsField(container, field, type, deep, UnionFormat));
internal class QueryTest
{
public readonly string Name;
public readonly string Arguments;
public readonly IEnumerable<string> Fields;
public QueryTest(string name, string arguments, IEnumerable<string> fields)
{
this.Name = name;
this.Arguments = arguments;
private static QueryTest BuildQuery(string type, TArguments args, IEnumerable<string> fields)
{
var arguments = args == null ? "" : GetArguments(args);
var query = $"{{{type}{arguments}{{{string.Join(' ', fields)}}}}}";
return new QueryTest(query);
}
 
private static string GetArguments(TArguments args)
{
var values = args.GetType()
${
using Typewriter.Extensions.WebApi;
using System.Text.RegularExpressions;
const string ContractPrefix = "App.Contract";
static string[] NotIncluedeControllers = new []{"Excel", "Diagnostics", "Download"};
string FileNameFromType(string fullName) {
var fullNameWithoutGenericParameter = Regex.Replace(fullName, @" ?\<.*?\>", string.Empty);
return fullNameWithoutGenericParameter
.Split(new string[]{ContractPrefix}, StringSplitOptions.None)
const string ContractPrefix = "App.Contract";
string ImportStatements(Class @class)
{
var otherTypesInFile = new List<Type>()
.Concat(@class.Methods.Select(x => x.Type))
.Concat(@class.Methods.SelectMany(x => x.Type.TypeArguments))
.Concat(@class.Methods.SelectMany(x => x.Parameters).Select(x => x.Type))
.Concat(@class.Methods.SelectMany(x => x.Parameters).SelectMany(x => x.Type.TypeArguments))
.SelectMany(GetTypes)
.ToList();
@MNie
MNie / AllPackages.fsx
Last active December 13, 2017 17:33
Short example of how to install all packages from packages.config via single command.
open FSharp.Data
type packages = XmlProvider<"""<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Machine.Fakes.RhinoMocks" version="2.3.0" targetFramework="net462" />
<package id="Machine.Specifications" version="0.9.3" targetFramework="net462" />
<package id="Machine.Specifications.Should" version="0.7.2" targetFramework="net462" />
<package id="RhinoMocks" version="3.6.1" targetFramework="net462" />
</packages>""">
type CsvParser(path: string) =
let _path = path
let index(headers: string[] option, column) = headers.Value |> Seq.findIndex (fun k -> k = column)
 
let getValuesFor(func) =
use data = CsvFile.Load(_path)
data.Rows
|> Seq.map(fun x -> func(data.Headers, x))
|> Seq.toArray
type CsvParser(path: string) =
let _path = path
let index(headers: string[] option, column) = headers.Value |> Seq.findIndex (fun k -> k = column)
 
let getValuesFor(func) =
use data = CsvFile.Load(_path)
data.Rows
|> Seq.map(fun x -> func(data.Headers, x))
|> Seq.toArray
type CsvParserType = CsvProvider<"base.csv", IgnoreErrors=true>
[<Literal>]
let schema = "Column 1 (float),Column 2 (string),Date (DateTime option)"
type CsvParserType = CsvProvider<"base.csv", schema=schema>