Опакечивание gsscoder/commandline |
Разработка на C# для Gentoo
F# в проектах на C# |
//------------------------------------------------------------------------- | |
// Options | |
//------------------------------------------------------------------------- | |
[<DefaultAugmentation(false)>] | |
#if !FX_NO_DEBUG_DISPLAYS | |
[<DebuggerDisplay("Some({Value})")>] | |
#endif | |
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>] | |
[<CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId="Option")>] | |
[<StructuralEquality; StructuralComparison>] | |
[<CompiledName("FSharpOption`1")>] | |
type Option<'T> = | |
| None : 'T option | |
| Some : Value:'T -> 'T option | |
[<CompilationRepresentation(CompilationRepresentationFlags.Instance)>] | |
member x.Value = match x with Some x -> x | None -> raise (new System.InvalidOperationException("Option.Value")) | |
#if !FX_NO_DEBUG_DISPLAYS | |
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>] | |
#endif | |
member x.IsNone = match x with None -> true | _ -> false | |
#if !FX_NO_DEBUG_DISPLAYS | |
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>] | |
#endif | |
member x.IsSome = match x with Some _ -> true | _ -> false | |
#if !FX_NO_DEBUG_DISPLAYS | |
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>] | |
#endif | |
static member None : 'T option = None | |
static member Some(x) : 'T option = Some(x) | |
static member op_Implicit(x) : 'T option = Some(x) | |
override x.ToString() = | |
// x is non-null, hence Some | |
"Some("^anyToStringShowingNull x.Value^")" | |
and 'T option = Option<'T> | |
public static bool IsSome(object value) { return (bool)typeof(FSharpOption<>) .MakeGenericType(GetUnderlyingType(value.GetType())) .StaticMethod( "get_IsSome", value); }
public class Sample { public void Example(string typeName) { Type myType = FindType(typeName); // What goes here to call GenericMethod<T>()? GenericMethod<myType>(); // This doesn't work // What changes to call StaticMethod<T>()? Sample.StaticMethod<myType>(); // This also doesn't work } public void GenericMethod<T>() { // ... } public static void StaticMethod<T>() { //... } }
using System; using System.Collections; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Microsoft.FSharp.Core { [StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)] public sealed class FSharpOption : IEquatable >, IStructuralEquatable, IComparable >, IComparable, IStructuralComparable { T thisValue; public T Value { get { return thisValue; } } public static FSharpOption Some(T value) { return new FSharpOption (value); } public static FSharpOption None { get { return null; } } public FSharpOption(T value) { thisValue = value; } public bool IsNone { get { return this == null; } } public bool IsSome { get { return this != null; } } public static int GetTag(FSharpOption fSharpOption) { return (fSharpOption == null) ? 0 : 1; } public /*sealed override*/ int CompareTo(object obj, IComparer comp) { throw new NotImplementedException(); } public /*sealed override*/ int CompareTo(object obj) { return this.CompareTo((FSharpOption )obj); } public /*sealed override*/ int CompareTo(FSharpOption obj) { throw new NotImplementedException(); } public /*sealed override*/ bool Equals(FSharpOption obj) { throw new NotImplementedException(); } public /*sealed override*/ bool Equals(object obj, IEqualityComparer comp) { throw new NotImplementedException(); } public sealed override bool Equals(object obj) { throw new NotImplementedException(); } public /*sealed override*/ int GetHashCode(IEqualityComparer comp) { throw new NotImplementedException(); } public sealed override int GetHashCode() { throw new NotImplementedException(); } public override string ToString() { throw new NotImplementedException(); } } }