public static T?Max <T, U>(T?x, U?y) where T : struct where U : struct { if (typeof(T) == typeof(DateTime) || typeof(U) == typeof(DateTime)) { throw new InvalidCastException(); } if (!x.HasValue && !y.HasValue) { return(null); } try { double?xValue = x.HasValue ? ToDouble(x.Value) : (double?)null; double?yValue = y.HasValue ? ToDouble(y.Value) : (double?)null; return((T)ChangeType(Max <double>(xValue, yValue), typeof(T))); } catch { throw new InvalidCastException(); } }
/// <summary> /// <para> /// `p.RunOnStream(stream,u,enc,name)` runs the parser `p` on the content of the /// `System.IO.Stream` `stream`, starting with the initial user state `u`. /// </para> /// <para> /// The `name` is used in error messages to describe the source of the input (e.g. a file /// path) and may be `null` or empty. /// </para> /// <para> /// In case no unicode byte order mark is found, the stream data is assumed to be encoded /// with the given `enc`. `Encoding.Default` will be used if `enc` was not specified. /// </para> /// <para>The parser's `Reply` is captured and returned as a `ParserResult` value.</para> /// </summary> public static ParserResult <TResult, U?> RunOnStream <U, TResult>( this FSharpFunc <CharStream <U?>, Reply <TResult> > p, Stream byteStream, U?userState = default, Encoding?encoding = null, string?streamName = null) => runParserOnStream(p, userState, streamName, byteStream, encoding ?? Encoding.Default);
public void NulableMethod() { // T where t : class must be not-Nullable //T hh; //T? tt = hh ?? new T(); // = ff ?? new T(); T ff = default(T); // in cazul dat lucrezi cu cimpurile interfetei // deci esti limitat cu ceia ce mostenesti/ implimentezi // in rest nu iti este numic acesibil ff.ShowName(); // ff += ff; int?e = default(int); e = null; U?uurr = new U(); uurr = null; U?gg = uurr ?? uurr ?? new U(); if (e.Value == null && e.HasValue) { Console.WriteLine(ff.ToString()); } }
/// <summary> /// <para> /// `p.RunOnString(s,index,count,u,name)` runs the parser `p` directly on the content of /// the string `s` between the indices `index` (inclusive) and `index + count` (exclusive), /// starting with the initial user state `u`. /// </para> /// <para> /// The `name` is used in error messages to describe the source of the input (e.g. a file /// path) and may be `null` or empty. /// </para> /// <para>The parser's `Reply` is captured and returned as a `ParserResult` value.</para> /// </summary> public static ParserResult <TResult, U?> RunOnString <U, TResult>( this FSharpFunc <CharStream <U?>, Reply <TResult> > p, string chars, int index, int length, U?userState = default, string?streamName = null) => runParserOnSubstring(p, userState, streamName, chars, index, length);
public static U?GetEnumValue <U>(U?defaultValue, string value) where U : struct { U?enumType = defaultValue; if ((!String.IsNullOrEmpty(value)) && (Contains(typeof(T), value))) { enumType = (U)Enum.Parse(typeof(U), value, true); } return(enumType); }
public ObjectItem(object instance, string name) { this.instance = instance; property = new ObjectItemValue(); itemProperty = instance.GetType().GetProperty(name) ?? throw new ArgumentException("The name must match to a property.", nameof(name)); itemElementNameProperty = instance.GetType().GetProperty(name + "ElementName") ?? throw new ArgumentException("The name must match to a property ending with \"ElementName\".", nameof(name)); itemValue = itemProperty.GetValue(instance, null) as object; itemElementNameValue = (U?)itemElementNameProperty.GetValue(instance, null); Initialize(); }
protected override void WriteValue(JsonWriter writer, U?value, JsonSerializer serializer) { Debug.Assert(value.HasValue); if (value.HasValue) { serializer.Serialize(writer, value.Value); } else { writer.WriteNull(); } }
/// <summary> /// Initialize a None if the given Nullable's HasValue property is false, otherwise initialize a Some. /// </summary> public static Option <U> Wrap <U>(U?value) where U : struct { if (!value.HasValue) { return(new Option <U>()); } else { return(new Option <U>(value.Value)); } }
public int Compare(U?x, U?y) { if (x is null) { return(1); } if (y is null) { return(-1); } return(((IComparable <U?>)x).CompareTo(y)); }
public Class1() { U? uError = U.NewCase(item: 123); SU?su = SU.NewCase(item: 123); SU u = su.Value; int t = u.Tag; int i = u.Item; bool isCaseError = u.IsCase; int tagsError = U.Tags.CaseA; U.Case c = (U.Case)u; }
void ExecuteCommand <T, U>(int command, ref T?request, ref U?response) where T : struct where U : struct { IntPtr requestAddr = IntPtr.Zero; IntPtr responseAddr = IntPtr.Zero; GCHandle requestHandle = default(GCHandle); GCHandle responseHandle = default(GCHandle); int requestSize = 0; int responseSize = 0; byte[] responseByteArray = null; if (request != null) { requestHandle = GCHandle.Alloc(request, GCHandleType.Pinned); requestAddr = requestHandle.AddrOfPinnedObject(); requestSize = Marshal.SizeOf(request); } if (response != null) { responseSize = Marshal.SizeOf(response); responseByteArray = new byte[responseSize]; responseHandle = GCHandle.Alloc(responseByteArray, GCHandleType.Pinned); responseAddr = responseHandle.AddrOfPinnedObject(); } if (OIV_Execute(command, requestSize, requestAddr, responseSize, responseAddr) != 0) { throw new Exception("Api function failed"); } if (requestHandle.IsAllocated) { requestHandle.Free(); } if (responseHandle.IsAllocated) { responseHandle.Free(); } if (responseSize > 0) { response = ByteArrayToStructure <U>(responseByteArray); } }
public static IMaybe <V> SelectMany <T, U, V>( this IMaybe <T> m, Func <T, U?> binder, Func <T, U, V> valueSelector) where U : struct { if (m.HasValue) { U?value = binder(m.Value); if (value.HasValue) { return(Some(valueSelector(m.Value, value.Value))); } } return(None <V>()); }
public static T Max <T, U>(T x, U?y) where T : struct where U : struct { if (typeof(T) == typeof(DateTime) || typeof(U) == typeof(DateTime)) { throw new InvalidCastException(); } try { double?yValue = y.HasValue ? ToDouble(y) : (double?)null; return((T)ChangeType(Max <double>(ToDouble(x), yValue), typeof(T))); } catch { throw new InvalidCastException(); } }
public Class1() { U?sa = U.NewCaseA(item: 123); U?sb = U.NewCaseB(named: 123); U?sc = U.NewCaseC(item1: 123, other: 123.0); U a = sa.Value; U b = sb.Value; U c = sc.Value; U.CaseA caError = (U.CaseA)a; U.CaseB cbError = (U.CaseB)b; U.CaseC ccError = (U.CaseC)c; int aItem = a.Item; int bItem = b.Item; int cItem = c.Item; int bNamed = b.Named; int cItem0 = c.Item1; double cOther = c.Other; int aItemError = a.Item; int bNamedError = b.Named; int cItem1Error = c.Item1; double cOtherError = c.Other; bool isA = a.IsCaseA; bool isB = a.IsCaseB; bool isC = a.IsCaseC; int tA = U.Tags.CaseA; int tB = U.Tags.CaseB; int tC = U.Tags.CaseC; int t = a.Tag; int m = U.Prop; }
public void Recalc() { m_cache = null; m_invalidate?.Invoke(m_src); }
public static U?GetOrDefault <T, U>(this IDictionary <T, U> values, T key, U?defaultValue) where T : notnull where U : notnull { return(values.TryGetValue(key, out var value) ? value : defaultValue); }
/// <summary> /// <para> /// `p.RunOnFile(path,u,enc)` runs the parser `p` on the content of the file at the given /// `path`, starting with the initial user state `u`. /// </para> /// <para> /// In case no unicode byte order mark is found, the file data is assumed to be encoded /// with the given `enc`. `Encoding.Default` will be used if `enc` was not specified. /// </para> /// <para>The parser's `Reply` is captured and returned as a `ParserResult` value.</para> /// </summary> public static ParserResult <TResult, U?> RunOnFile <U, TResult>( this FSharpFunc <CharStream <U?>, Reply <TResult> > p, string path, U?userState = default, Encoding?encoding = null) => runParserOnFile(p, userState, path, encoding ?? Encoding.Default);
public static U?And <T, U>(this T? @this, U?optb) where T : struct where U : struct { return(@this.HasValue ? optb : null); }
public string GetName(U?id) { return(id == null ? null : GetName((U)id)); }
public Union(U item) { u = item; tag = 1; }