referencesource | NET Reference Source that represent a subset of the .NET | Database library
kandi X-RAY | referencesource Summary
kandi X-RAY | referencesource Summary
Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of referencesource
referencesource Key Features
referencesource Examples and Code Snippets
Community Discussions
Trending Discussions on referencesource
QUESTION
I'm reading a book which says:
Task objects internally contain a collection of ContinueWith tasks. So you can actually call ContinueWith several times using a single Task object. When the task completes, all the ContinueWith tasks will be queued to the thread pool.
so I try to check the source code of Task https://referencesource.microsoft.com/#mscorlib/system/threading/Tasks/Task.cs,146
I didn't find any private field that looks like a collection of ContinueWith tasks.
So my question is , does Task objects internally contain a collection of ContinueWith tasks?
And if it does, let's say we have the following code:
...ANSWER
Answered 2021-May-14 at 22:47I guess you could say the answer is yes and no. The Task class utilizes Interlocked in order to keep up with continuations.
You can see the method for adding a continuation named AddTaskContinuationComplex(object tc, bool addBeforeOthers) at line 4727. Within this method the continuation is added to a list and then passed to Interlocked.
QUESTION
I was searching for the source code of .NET Core because I wanted to look at how the core classes are implemented. For example, I wanted to see how the string
class is written.
Can someone please point me to the source code of .NET Core?
There exists a great online browsing tool for .NET Framework at .NET Reference Resource. Does something similar exist for .NET Core?
PS: I tried looking on GitHub but could not find it.
This GitHub Link allows to download SDK source code but it has missing classes like String.cs
...ANSWER
Answered 2021-May-10 at 13:45Look in the dotnet/runtime repo on GitHub:
You'll find the implementation of the String
class there:
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/String.cs
QUESTION
I read the implementation for MoveNext() in List
:
ANSWER
Answered 2021-May-06 at 19:21Probably that is a performance issue. Access to local variables is slightly faster than access to instance variables. And - as List
is probably one of the most used classes in the CLR - having good performance matters.
Local variables can directly be read from stack or maybe a register, while instance variables read the address of the object, and then get the value relative to that.
QUESTION
I'm reading a book that talks about Runtime Serialization using BinaryFormatter
, steps below are from the book:
- The formatter calls FormatterServic upes's GetSerializableMembers method.
ANSWER
Answered 2021-May-05 at 06:03You're mixing up two things that are working together:
On one site, there is the Serializable
attribute and its methods. This contains also the two methods GetSerializableMembers()
to describe the structure and GetObjectData()
to get the concrete values of a living instance that should be serialized. Regardless of the used writer (aka formatter) you'll always need a tree of key value pairs holding the property name as key and its content as value (which could be another object of key value pairs).
The next one comes into play is (in your case) the binary formatter. It consumes this structure and picks whatever it likes to, to write the information into some kind of stream. This special implementation of a fomatter is tried for being optimized for needed size within stream. This will be achieved by omitting the keys and only writing the value and assuming the reader knows the exact structure and writes the values onto the correct properties.
That's the reason, why this formatter shouldn't be used. Instead use some kind of serialization that also contains the structure like XML or JSON. These add also the keys to the stream and making it easier to deserialize the data even if the destination structure doesn't fully match.
QUESTION
The source code of Enumerator is:
...ANSWER
Answered 2021-May-03 at 09:07For the first question I don't have any answer, maybe it just an relic from some previous implementation, maybe it somehow improves performance (though I would wonder how and why, so my bet is on the first guess). Also in the Core implementation list
field is marked as readonly.
As for the second one - it has nothing to do with Reset
, but with System.Collections.IEnumerator.Current
implementation:
QUESTION
I have written my own timer class, a wrapper for Windows Multimedia Timers.
I modelled my timer class on .NET's System.Timers.Timer
class.
I am struggling to understand why .NET's timer calls BeginInvoke
on the synchronizing object, rather than Invoke
:
ANSWER
Answered 2021-Apr-28 at 01:28The Invoke will block current thread and main thread.
And BeginInvoke only block main thread.
you can try in wpf
MainWindow.xaml
QUESTION
// Some interface method signature
public interface IList : ICollection {
...
bool Contains(Object value);
...
}
public interface IList : ICollection { ... }
public interface ICollection : IEnumerable {
...
bool Contains(T item);
...
}
...ANSWER
Answered 2021-Feb-20 at 04:39You can see that
List
uses explicit interface method implementation (explicitly specify the interface's name) to implement the non-genericContains
Indeed.
But that's because the IList
interface (not IList
) is decades-old - from the primitive, dark, times before .NET had support for generics (.NET 1.0 came out in 2001 - generics weren't added until the .NET Framework 2.0 in 2005). It was a truly godforsaken time.
List
(but not IList
) implements the IList
interface so that the new generic List
could be consumed by older code that accepted an IList
(in a way that allows preserving object identity and without requiring allocating a separate IList
instance).
Supposing it's 2005 and you're writing some wonderous C# 2.0 code that uses the fancy new reified generics and List
- but you need to interact with a library that was last updated in 2004:
QUESTION
The following program results in different outcomes when run on .NET 5 (or .NET Core) and .NET Framework.
Why is the behaviour different? I'm not after the solution to the deserialisation problem; my goal here is to understand what happens.
...ANSWER
Answered 2021-Jan-06 at 14:29It looks like Json.NET got a new VersionConverter
in .NET Core 2.2, which knows how to properly serialize and deserialize Version
instances. This automatically gets picked up and used when you're using .NET Core 2.2+.
Using VersionConverter
, Json.NET wants to serialize your Version
objects to strings like "1.0"
, rather than to JSON objects. If you create the json
string in your post by serializing a new instance of Versioned
on .NET Core 2.2+:
QUESTION
I have an application that consumes LayoutUpdated-events and need to register them weak. Here is the problem, I got stuck on, during implementation of the WeakEventManager
...ANSWER
Answered 2021-Feb-16 at 05:17As you have found yourself, null
sender breaks WeakEventManager
into thinking that this is a static event, which basically makes it incompatible with LayoutUpdated
. Since WeakEventManager.DeliverEvent
is non-virtual, you cannot really "fix" it.
So I think your option would be to use a third-party weak event manager, or write one yourself, which shouldn't be that difficult (unless you need a generic solution).
The idea is to break a hard reference between the event source (UIElement
) and the event subscriber (Delegate.Target
), which may be achieved by using a mediator class with weak references to the event handler and its target.
Here is a quick-and-dirty example that would work with events of type EventHandler
:
QUESTION
I am getting an AmbiguousMatchException
at set.Apply();
as soon as I move to this page, after I switched from MvvmCross 5 to 7, and I am not able to figure out what's the cause or how to solve it. The same code worked before, but it doesn't now.
I tried to remove the set.Bind
functions and that removes the crash exception but then the address fields were empty (same effect as just adding a try catch). I also tried to bind only one of the 4, but the exception still comes up.
Here's all the exception details:
...ANSWER
Answered 2021-Feb-14 at 22:22Alright, thanks to Darius I was able to figure out a work around! I cut down the Fragment to its basics and instead of the FrameLayout, used an MvxFrameControl and it worked. So this is what my Fragment looks like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install referencesource
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page