ienumerable

How to validate yield return default in IEnumerable?

帅比萌擦擦* 提交于 2021-01-28 22:47:37
问题 I am trying to check whether IEnumerable<> is null or empty but somehow my if check always fails whenever it is empty. private bool Update() { IEnumerable<RecordHolder> recordHolders = GetData(); // below check doesn't work if (recordHolders == null || !recordHolders.Any()) return false; // .. some other code } public IEnumerable<RecordHolder> GetData() { var isSuccess = PullRemote(url); if (!isSuccess.Result) { yield return default; } // .. some other code } Whenever my GetData() method

Get AdministratorsMembers SIDs in .NET CORE 2

谁说我不能喝 提交于 2021-01-27 14:14:28
问题 I wrote this function to retrieve all Administrators Members SIDs: private IList<byte[]> GetAdministratorsMembersSIDs() { IList<byte[]> adminMembers = new List<byte[]>(); SecurityIdentifier id = new SecurityIdentifier(administratorsSid); string name = id.Translate(typeof(NTAccount)).Value.Split('\\')[1]; using (DirectoryEntry adminGroupEntry = new DirectoryEntry(string.Format("WinNT://./{0},group", name))) { foreach (object member in (IEnumerable)adminGroupEntry.Invoke("Members")) { using

Get AdministratorsMembers SIDs in .NET CORE 2

≡放荡痞女 提交于 2021-01-27 14:00:51
问题 I wrote this function to retrieve all Administrators Members SIDs: private IList<byte[]> GetAdministratorsMembersSIDs() { IList<byte[]> adminMembers = new List<byte[]>(); SecurityIdentifier id = new SecurityIdentifier(administratorsSid); string name = id.Translate(typeof(NTAccount)).Value.Split('\\')[1]; using (DirectoryEntry adminGroupEntry = new DirectoryEntry(string.Format("WinNT://./{0},group", name))) { foreach (object member in (IEnumerable)adminGroupEntry.Invoke("Members")) { using

IEnumerable.GetEnumerator() and IEnumerable<T>.GetEnumerator()

社会主义新天地 提交于 2021-01-27 05:44:52
问题 In the .net framework, there's a generic IEnumerable<T> interface which inherits from the not-generic IEnumerable , and they both have a GetEnumerator() method. The only differents between these two GetEnumerator() is the return type. Now I have a similar design, but when I compile the code, the compiler said: MyInterface<T>.GetItem() ' hides inherited member ' MyInterface.GetItem() '. Use the new keyword if hiding was intended. The MyInterface<T>.GetItem() returns a concrete type T, while

IEnumerable.GetEnumerator() and IEnumerable<T>.GetEnumerator()

爱⌒轻易说出口 提交于 2021-01-27 05:43:00
问题 In the .net framework, there's a generic IEnumerable<T> interface which inherits from the not-generic IEnumerable , and they both have a GetEnumerator() method. The only differents between these two GetEnumerator() is the return type. Now I have a similar design, but when I compile the code, the compiler said: MyInterface<T>.GetItem() ' hides inherited member ' MyInterface.GetItem() '. Use the new keyword if hiding was intended. The MyInterface<T>.GetItem() returns a concrete type T, while

IEnumerable and IEnumerator in the same class, bad idea?

房东的猫 提交于 2021-01-27 04:44:11
问题 Is this a bad idea? Private Class GH_DataStructureEnumerator(Of Q As Types.IGH_Goo) Implements IEnumerable(Of Q) Implements IEnumerator(Of Q) .... .... 'Current, MoveNext, Reset etc.' .... .... Public Function GetEnumerator_Generic() As IEnumerator(Of Q) _ Implements IEnumerable(Of Q).GetEnumerator Return Me End Function End Class This class is only visible as an IEnumerable(Of T) readonly property, and it saves me an additional class that wraps IEnumerator(Of T). But somehow it just seems

How to invoke System.Linq.Enumerable.Count<> on IEnumerable<T> using Reflection?

泪湿孤枕 提交于 2021-01-27 04:22:16
问题 I have a bunch of IEnumerable Collections which exact number and types is subject of frequent changes (due to automatic code generation). It looks something like this: public class MyCollections { public System.Collections.Generic.IEnumerable<SomeType> SomeTypeCollection; public System.Collections.Generic.IEnumerable<OtherType> OtherTypeCollection; ... At runtime i want to determine each Type and it's count without having to rewrite the code after every code generation. So i am looking for a

Derived List to Base IEnumerable

最后都变了- 提交于 2020-12-27 05:22:27
问题 I have the following code that compiles in .NET Framework version 4.0 and above: public abstract class MyBase { } public class MyDerived : MyBase { } public abstract class MyBaseCollection<T> : IList<T> where T : MyBase { protected readonly IList<T> deriveds = new List<T>(); public void Test() { // This line works in .NET versions 4.0 and above, but not in versions below. IEnumerable<MyBase> bases = deriveds; } #region IList members with NotImplementedException // ... #endregion } public

Derived List to Base IEnumerable

为君一笑 提交于 2020-12-27 05:21:07
问题 I have the following code that compiles in .NET Framework version 4.0 and above: public abstract class MyBase { } public class MyDerived : MyBase { } public abstract class MyBaseCollection<T> : IList<T> where T : MyBase { protected readonly IList<T> deriveds = new List<T>(); public void Test() { // This line works in .NET versions 4.0 and above, but not in versions below. IEnumerable<MyBase> bases = deriveds; } #region IList members with NotImplementedException // ... #endregion } public