Skip to content

Instantly share code, notes, and snippets.

@xoofx
Created October 28, 2016 07:20
Show Gist options
  • Save xoofx/8e9be7d027e2eb0c359da37f77a1bb8a to your computer and use it in GitHub Desktop.
Save xoofx/8e9be7d027e2eb0c359da37f77a1bb8a to your computer and use it in GitHub Desktop.
.NET Code generated for a Shape F# discriminated union
// .NET Code generated for the F# type:
// type Shape =
// | Rectangle of width : float * length : float
// | Circle of radius : float
// | Triangle of width : float * height : float
using Microsoft.FSharp.Core;
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace TestFSharp
{
[CompilationMapping(SourceConstructFlags.SumType), DebuggerDisplay("{__DebugDisplay(),nq}")]
[Serializable]
[StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)]
public abstract class Shape : IEquatable<Shape>, IStructuralEquatable, IComparable<Shape>, IComparable, IStructuralComparable
{
public static class Tags
{
public const int Rectangle = 0;
public const int Circle = 1;
public const int Triangle = 2;
}
[DebuggerDisplay("{__DebugDisplay(),nq}"), DebuggerTypeProxy(typeof(Shape.Rectangle@DebugTypeProxy))]
[Serializable]
public class Rectangle : Shape
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal readonly double _width;
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal readonly double _length;
[CompilationMapping(SourceConstructFlags.Field, 0, 0), DebuggerNonUserCode, CompilerGenerated]
public double width
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._width;
}
}
[CompilationMapping(SourceConstructFlags.Field, 0, 1), DebuggerNonUserCode, CompilerGenerated]
public double length
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._length;
}
}
[DebuggerNonUserCode, CompilerGenerated]
internal Rectangle(double _width, double _length)
{
this._width = _width;
this._length = _length;
}
}
[DebuggerDisplay("{__DebugDisplay(),nq}"), DebuggerTypeProxy(typeof(Shape.Circle@DebugTypeProxy))]
[Serializable]
public class Circle : Shape
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal readonly double _radius;
[CompilationMapping(SourceConstructFlags.Field, 1, 0), DebuggerNonUserCode, CompilerGenerated]
public double radius
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._radius;
}
}
[DebuggerNonUserCode, CompilerGenerated]
internal Circle(double _radius)
{
this._radius = _radius;
}
}
[DebuggerDisplay("{__DebugDisplay(),nq}"), DebuggerTypeProxy(typeof(Shape.Triangle@DebugTypeProxy))]
[Serializable]
public class Triangle : Shape
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal readonly double _width;
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal readonly double _height;
[CompilationMapping(SourceConstructFlags.Field, 2, 0), DebuggerNonUserCode, CompilerGenerated]
public double width
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._width;
}
}
[CompilationMapping(SourceConstructFlags.Field, 2, 1), DebuggerNonUserCode, CompilerGenerated]
public double height
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._height;
}
}
[DebuggerNonUserCode, CompilerGenerated]
internal Triangle(double _width, double _height)
{
this._width = _width;
this._height = _height;
}
}
internal class Rectangle@DebugTypeProxy
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal Shape.Rectangle _obj;
[CompilationMapping(SourceConstructFlags.Field, 0, 0), DebuggerNonUserCode, CompilerGenerated]
public double width
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._obj._width;
}
}
[CompilationMapping(SourceConstructFlags.Field, 0, 1), DebuggerNonUserCode, CompilerGenerated]
public double length
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._obj._length;
}
}
[DebuggerNonUserCode, CompilerGenerated]
public Rectangle@DebugTypeProxy(Shape.Rectangle obj)
{
this._obj = obj;
}
}
internal class Circle@DebugTypeProxy
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal Shape.Circle _obj;
[CompilationMapping(SourceConstructFlags.Field, 1, 0), DebuggerNonUserCode, CompilerGenerated]
public double radius
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._obj._radius;
}
}
[DebuggerNonUserCode, CompilerGenerated]
public Circle@DebugTypeProxy(Shape.Circle obj)
{
this._obj = obj;
}
}
internal class Triangle@DebugTypeProxy
{
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
internal Shape.Triangle _obj;
[CompilationMapping(SourceConstructFlags.Field, 2, 0), DebuggerNonUserCode, CompilerGenerated]
public double width
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._obj._width;
}
}
[CompilationMapping(SourceConstructFlags.Field, 2, 1), DebuggerNonUserCode, CompilerGenerated]
public double height
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this._obj._height;
}
}
[DebuggerNonUserCode, CompilerGenerated]
public Triangle@DebugTypeProxy(Shape.Triangle obj)
{
this._obj = obj;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
public int Tag
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return (!(this is Shape.Triangle)) ? ((!(this is Shape.Circle)) ? 0 : 1) : 2;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
public bool IsRectangle
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this is Shape.Rectangle;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
public bool IsCircle
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this is Shape.Circle;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never), DebuggerNonUserCode, CompilerGenerated]
public bool IsTriangle
{
[DebuggerNonUserCode, CompilerGenerated]
get
{
return this is Shape.Triangle;
}
}
[DebuggerNonUserCode, CompilerGenerated]
internal Shape()
{
}
[CompilationMapping(SourceConstructFlags.UnionCase, 0)]
public static Shape NewRectangle(double _width, double _length)
{
return new Shape.Rectangle(_width, _length);
}
[CompilationMapping(SourceConstructFlags.UnionCase, 1)]
public static Shape NewCircle(double _radius)
{
return new Shape.Circle(_radius);
}
[CompilationMapping(SourceConstructFlags.UnionCase, 2)]
public static Shape NewTriangle(double _width, double _height)
{
return new Shape.Triangle(_width, _height);
}
[DebuggerNonUserCode, CompilerGenerated]
internal object __DebugDisplay()
{
return ExtraTopLevelOperators.PrintFormatToString<FSharpFunc<Shape, string>>(new PrintfFormat<FSharpFunc<Shape, string>, Unit, string, string, string>("%+0.8A")).Invoke(this);
}
[CompilerGenerated]
public sealed override int CompareTo(Shape obj)
{
if (this != null)
{
if (obj == null)
{
return 1;
}
int num = (!(this is Shape.Triangle)) ? ((!(this is Shape.Circle)) ? 0 : 1) : 2;
int num2 = (!(obj is Shape.Triangle)) ? ((!(obj is Shape.Circle)) ? 0 : 1) : 2;
if (num != num2)
{
return num - num2;
}
if (!(this is Shape.Rectangle))
{
if (!(this is Shape.Circle))
{
if (this is Shape.Triangle)
{
Shape.Triangle triangle = (Shape.Triangle)this;
Shape.Triangle triangle2 = (Shape.Triangle)obj;
IComparer genericComparer = LanguagePrimitives.GenericComparer;
double width = triangle._width;
double width2 = triangle2._width;
int num3 = (width >= width2) ? ((width <= width2) ? ((width != width2) ? LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(genericComparer, width, width2) : 0) : 1) : -1;
if (num3 < 0)
{
return num3;
}
if (num3 > 0)
{
return num3;
}
IComparer genericComparer2 = LanguagePrimitives.GenericComparer;
double height = triangle._height;
double height2 = triangle2._height;
if (height < height2)
{
return -1;
}
if (height > height2)
{
return 1;
}
if (height == height2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(genericComparer2, height, height2);
}
}
else
{
Shape.Circle circle = (Shape.Circle)this;
Shape.Circle circle2 = (Shape.Circle)obj;
IComparer genericComparer3 = LanguagePrimitives.GenericComparer;
double radius = circle._radius;
double radius2 = circle2._radius;
if (radius < radius2)
{
return -1;
}
if (radius > radius2)
{
return 1;
}
if (radius == radius2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(genericComparer3, radius, radius2);
}
}
Shape.Rectangle rectangle = (Shape.Rectangle)this;
Shape.Rectangle rectangle2 = (Shape.Rectangle)obj;
IComparer genericComparer4 = LanguagePrimitives.GenericComparer;
double width3 = rectangle._width;
double width4 = rectangle2._width;
int num4 = (width3 >= width4) ? ((width3 <= width4) ? ((width3 != width4) ? LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(genericComparer4, width3, width4) : 0) : 1) : -1;
if (num4 < 0)
{
return num4;
}
if (num4 > 0)
{
return num4;
}
IComparer genericComparer5 = LanguagePrimitives.GenericComparer;
double length = rectangle._length;
double length2 = rectangle2._length;
if (length < length2)
{
return -1;
}
if (length > length2)
{
return 1;
}
if (length == length2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(genericComparer5, length, length2);
}
else
{
if (obj != null)
{
return -1;
}
return 0;
}
}
[CompilerGenerated]
public sealed override int CompareTo(object obj)
{
return this.CompareTo((Shape)obj);
}
[CompilerGenerated]
public sealed override int CompareTo(object obj, IComparer comp)
{
Shape shape = (Shape)obj;
if (this != null)
{
if ((Shape)obj == null)
{
return 1;
}
int num = (!(this is Shape.Triangle)) ? ((!(this is Shape.Circle)) ? 0 : 1) : 2;
Shape shape2 = shape;
int num2 = (!(shape2 is Shape.Triangle)) ? ((!(shape2 is Shape.Circle)) ? 0 : 1) : 2;
if (num != num2)
{
return num - num2;
}
if (!(this is Shape.Rectangle))
{
if (!(this is Shape.Circle))
{
if (this is Shape.Triangle)
{
Shape.Triangle triangle = (Shape.Triangle)this;
Shape.Triangle triangle2 = (Shape.Triangle)shape;
double width = triangle._width;
double width2 = triangle2._width;
int num3 = (width >= width2) ? ((width <= width2) ? ((width != width2) ? LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(comp, width, width2) : 0) : 1) : -1;
if (num3 < 0)
{
return num3;
}
if (num3 > 0)
{
return num3;
}
double height = triangle._height;
double height2 = triangle2._height;
if (height < height2)
{
return -1;
}
if (height > height2)
{
return 1;
}
if (height == height2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(comp, height, height2);
}
}
else
{
Shape.Circle circle = (Shape.Circle)this;
Shape.Circle circle2 = (Shape.Circle)shape;
double radius = circle._radius;
double radius2 = circle2._radius;
if (radius < radius2)
{
return -1;
}
if (radius > radius2)
{
return 1;
}
if (radius == radius2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(comp, radius, radius2);
}
}
Shape.Rectangle rectangle = (Shape.Rectangle)this;
Shape.Rectangle rectangle2 = (Shape.Rectangle)shape;
double width3 = rectangle._width;
double width4 = rectangle2._width;
int num4 = (width3 >= width4) ? ((width3 <= width4) ? ((width3 != width4) ? LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(comp, width3, width4) : 0) : 1) : -1;
if (num4 < 0)
{
return num4;
}
if (num4 > 0)
{
return num4;
}
double length = rectangle._length;
double length2 = rectangle2._length;
if (length < length2)
{
return -1;
}
if (length > length2)
{
return 1;
}
if (length == length2)
{
return 0;
}
return LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<double>(comp, length, length2);
}
else
{
if ((Shape)obj != null)
{
return -1;
}
return 0;
}
}
[CompilerGenerated]
public sealed override int GetHashCode(IEqualityComparer comp)
{
if (this != null)
{
int num;
if (!(this is Shape.Rectangle))
{
if (this is Shape.Circle)
{
Shape.Circle circle = (Shape.Circle)this;
num = 1;
return -1640531527 + (LanguagePrimitives.HashCompare.GenericHashWithComparerIntrinsic<double>(comp, circle._radius) + ((num << 6) + (num >> 2)));
}
if (this is Shape.Triangle)
{
Shape.Triangle triangle = (Shape.Triangle)this;
num = 2;
num = -1640531527 + (LanguagePrimitives.HashCompare.GenericHashWithComparerIntrinsic<double>(comp, triangle._height) + ((num << 6) + (num >> 2)));
return -1640531527 + (LanguagePrimitives.HashCompare.GenericHashWithComparerIntrinsic<double>(comp, triangle._width) + ((num << 6) + (num >> 2)));
}
}
Shape.Rectangle rectangle = (Shape.Rectangle)this;
num = 0;
num = -1640531527 + (LanguagePrimitives.HashCompare.GenericHashWithComparerIntrinsic<double>(comp, rectangle._length) + ((num << 6) + (num >> 2)));
return -1640531527 + (LanguagePrimitives.HashCompare.GenericHashWithComparerIntrinsic<double>(comp, rectangle._width) + ((num << 6) + (num >> 2)));
}
return 0;
}
[CompilerGenerated]
public sealed override int GetHashCode()
{
return this.GetHashCode(LanguagePrimitives.GenericEqualityComparer);
}
[CompilerGenerated]
public sealed override bool Equals(object obj, IEqualityComparer comp)
{
if (this == null)
{
return obj == null;
}
Shape shape = obj as Shape;
if (shape == null)
{
return false;
}
Shape shape2 = shape;
int num = (!(this is Shape.Triangle)) ? ((!(this is Shape.Circle)) ? 0 : 1) : 2;
Shape shape3 = shape2;
int num2 = (!(shape3 is Shape.Triangle)) ? ((!(shape3 is Shape.Circle)) ? 0 : 1) : 2;
if (num == num2)
{
if (!(this is Shape.Rectangle))
{
if (this is Shape.Circle)
{
Shape.Circle circle = (Shape.Circle)this;
Shape.Circle circle2 = (Shape.Circle)shape2;
return circle._radius == circle2._radius;
}
if (this is Shape.Triangle)
{
Shape.Triangle triangle = (Shape.Triangle)this;
Shape.Triangle triangle2 = (Shape.Triangle)shape2;
return triangle._width == triangle2._width && triangle._height == triangle2._height;
}
}
Shape.Rectangle rectangle = (Shape.Rectangle)this;
Shape.Rectangle rectangle2 = (Shape.Rectangle)shape2;
return rectangle._width == rectangle2._width && rectangle._length == rectangle2._length;
}
return false;
}
[CompilerGenerated]
public sealed override bool Equals(Shape obj)
{
if (this == null)
{
return obj == null;
}
if (obj == null)
{
return false;
}
int num = (!(this is Shape.Triangle)) ? ((!(this is Shape.Circle)) ? 0 : 1) : 2;
int num2 = (!(obj is Shape.Triangle)) ? ((!(obj is Shape.Circle)) ? 0 : 1) : 2;
if (num != num2)
{
return false;
}
if (!(this is Shape.Rectangle))
{
if (this is Shape.Circle)
{
Shape.Circle circle = (Shape.Circle)this;
Shape.Circle circle2 = (Shape.Circle)obj;
double radius = circle._radius;
double radius2 = circle2._radius;
return (radius != radius && radius2 != radius2) || radius == radius2;
}
if (this is Shape.Triangle)
{
Shape.Triangle triangle = (Shape.Triangle)this;
Shape.Triangle triangle2 = (Shape.Triangle)obj;
double width = triangle._width;
double width2 = triangle2._width;
if ((width != width && width2 != width2) || width == width2)
{
double height = triangle._height;
double height2 = triangle2._height;
return (height != height && height2 != height2) || height == height2;
}
return false;
}
}
Shape.Rectangle rectangle = (Shape.Rectangle)this;
Shape.Rectangle rectangle2 = (Shape.Rectangle)obj;
double width3 = rectangle._width;
double width4 = rectangle2._width;
if ((width3 != width3 && width4 != width4) || width3 == width4)
{
double length = rectangle._length;
double length2 = rectangle2._length;
return (length != length && length2 != length2) || length == length2;
}
return false;
}
[CompilerGenerated]
public sealed override bool Equals(object obj)
{
Shape shape = obj as Shape;
return shape != null && this.Equals(shape);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment