nullable

Nullable<T> implementation

痴心易碎 提交于 2019-12-02 01:46:05
问题 I am trying to implement Nullable type. But below mentioned code doesn't support null value for valuetype datatypes. using System; using System.Runtime; using System.Runtime.InteropServices; namespace Nullable { [Serializable, StructLayout(LayoutKind.Sequential)] public struct Nullable<T> where T : struct { private bool hasValue; public bool HasValue { get { return hasValue; } } internal T value; public Nullable(T value) { this.value = value; this.hasValue = true; } public T Value { get { if

Nullable<T> implementation

ε祈祈猫儿з 提交于 2019-12-01 23:02:12
I am trying to implement Nullable type. But below mentioned code doesn't support null value for valuetype datatypes. using System; using System.Runtime; using System.Runtime.InteropServices; namespace Nullable { [Serializable, StructLayout(LayoutKind.Sequential)] public struct Nullable<T> where T : struct { private bool hasValue; public bool HasValue { get { return hasValue; } } internal T value; public Nullable(T value) { this.value = value; this.hasValue = true; } public T Value { get { if (!this.hasValue) { new InvalidOperationException("No value assigned"); } return this.value; } } public

LINQ 2 Entities , howto check DateTime.HasValue within the linq query

旧城冷巷雨未停 提交于 2019-12-01 20:47:54
I have this method that is supposed to get the latest messages posted, from the Table (& EntitySet) called ENTRY ///method gets "days" as parameter, used in new TimeSpan(days,0,0,0);!! using (Entities db = new Entities()) { var entries = from ent in db.ENTRY where ent.DATECREATE.Value > DateTime.Today.Subtract(new TimeSpan(days, 0, 0, 0)) select new ForumEntryGridView() { id = ent.id, baslik = ent.header, tarih = ent.entrydate.Value, membername = ent.Member.ToString() }; return entries.ToList<ForumEntryGridView>(); } Here the DATECREATED is Nullable in the database. I cant place "if"s in this

LINQ 2 Entities , howto check DateTime.HasValue within the linq query

白昼怎懂夜的黑 提交于 2019-12-01 19:40:44
问题 I have this method that is supposed to get the latest messages posted, from the Table (& EntitySet) called ENTRY ///method gets "days" as parameter, used in new TimeSpan(days,0,0,0);!! using (Entities db = new Entities()) { var entries = from ent in db.ENTRY where ent.DATECREATE.Value > DateTime.Today.Subtract(new TimeSpan(days, 0, 0, 0)) select new ForumEntryGridView() { id = ent.id, baslik = ent.header, tarih = ent.entrydate.Value, membername = ent.Member.ToString() }; return entries.ToList

Kotlin: eliminate nulls from a List (or other functional transformation)

我的梦境 提交于 2019-12-01 15:40:01
Problem What is the idiomatic way of working around this limitation of the null-safety in the Kotlin type system? val strs1:List<String?> = listOf("hello", null, "world") // ERROR: Type Inference Failed: Expected Type Mismatch: // required: List<String> // round: List<String?> val strs2:List<String> = strs1.filter { it != null } This question is not just about eliminating nulls, but also to make the type system recognize that the nulls are removed from the collection by the transformation. I'd prefer not to loop, but I will if that's the best way to do it. Work-Around The following compiles,

Creating Nullables types in java

元气小坏坏 提交于 2019-12-01 15:15:25
I am trying to create a nullalble object in Java but no idea how to do this , in C# this would be done like this int? someTestInt; This allows me to check for for null , while in certain cases i can use a 0 value ,this isnt always possible since certain execution paths allow 0 values I'm not entirely sure what you want, but if you want to have an integer value that also can be declared null , you probably want to use the Integer class: Integer nullableInteger = 1; nullableInteger = null; System.out.println(nullableInteger); // "null" There are corresponding classes for each primitive:

kotlin reflection check nullable types

假如想象 提交于 2019-12-01 05:53:37
How can I test if a KType variable holds a value of a nullable kotlin type, (e.G. Int?)? I have var type: KType variable coming from a KProperty<*>.returnType and I need to detect if it is equal to certain kotlin types (Int, Long, etc). This works with: when (type) { Int::class.defaultType -> ... Long::class.defaultType -> ... else -> ... } but this only works for non-nullable types, so the first branch does not match to Int? However I was yet unable to figure out how I could detect is type is Int? other then to obvious but not so nice type.toString().equals("kotlin.Int?") As you can see from

Nullable Int Column in DataSet

佐手、 提交于 2019-12-01 05:06:55
I'm working with .NET strongly-typed datasets and have a table with a nullable int column (and a nullable DateTime column as well). Apparently there is a bug with the dataset designer that prevents having nullable columns on these data types. The designer only allows "throw exception" as the default behavior for null values. Unfortunately, when using a nullable data type in the database, a null value IS a legitimate value but results in a thrown exception when attempting to retrieve this value from a data row. I've seen several newsgroup postings about this problem but have yet to see any

kotlin reflection check nullable types

三世轮回 提交于 2019-12-01 04:45:41
问题 How can I test if a KType variable holds a value of a nullable kotlin type, (e.G. Int?)? I have var type: KType variable coming from a KProperty<*>.returnType and I need to detect if it is equal to certain kotlin types (Int, Long, etc). This works with: when (type) { Int::class.defaultType -> ... Long::class.defaultType -> ... else -> ... } but this only works for non-nullable types, so the first branch does not match to Int? However I was yet unable to figure out how I could detect is type

Where to put @Nullable on methods with nullable return types? [duplicate]

懵懂的女人 提交于 2019-12-01 04:23:22
This question already has an answer here: Is it legal to put annotation after access modifier in Java 7? Or Java 8? 2 answers When using javax.annotation.Nullable to mark methods as "potentially returning null value", where to put the @Nullable annotation? On the method, or return type? Is there any technical difference, or is this strictly a style issue? Style A: @Nullable public Object blah() { ... } Style B: public @Nullable Object blah() { ... } This is strictly a style issue. No matter where you write the annotation in the source code, the annotation is actually on the method. That's