<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>core Archive - Robert Skibbe</title>
	<atom:link href="https://robbelroot.de/blog/tag/core/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>alias RobbelRoot – Freelance Full Stack Developer .NET</description>
	<lastBuildDate>Thu, 28 Sep 2023 08:13:36 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://robbelroot.de/wp-content/uploads/2020/12/cropped-favicon-32x32.png</url>
	<title>core Archive - Robert Skibbe</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>rskibbe.Core.Composition – Building better and more flexible objects</title>
		<link>https://robbelroot.de/blog/rskibbe-core-composition-building-better-and-more-flexible-objects/</link>
					<comments>https://robbelroot.de/blog/rskibbe-core-composition-building-better-and-more-flexible-objects/#comments</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Mon, 11 Sep 2023 22:01:31 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[NuGet Packages]]></category>
		<category><![CDATA[rskibbe]]></category>
		<category><![CDATA[rskibbe.Core]]></category>
		<category><![CDATA[rskibbe.Core.Composition]]></category>
		<category><![CDATA[aggregate]]></category>
		<category><![CDATA[combine]]></category>
		<category><![CDATA[composite]]></category>
		<category><![CDATA[composition]]></category>
		<category><![CDATA[core]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[netstandard]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[vbnet]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=16075</guid>

					<description><![CDATA[<p>What is rskibbe.Core.Composition? My NuGet package called &#8222;rskibbe.Core.Composition&#8220; is about helping you build more complex objects easier. It provides a common infrastructure for you to design your classes upon. It was private at first, but I&#8217;m using it in a lot of my projects, so I thought, why wouldn&#8217;t I &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/rskibbe-core-composition-building-better-and-more-flexible-objects/">rskibbe.Core.Composition – Building better and more flexible objects</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/rskibbe.Core_.Composition-Building-better-and-more-flexible-objects.png"><img fetchpriority="high" decoding="async" width="640" height="360" src="https://robbelroot.de/wp-content/uploads/2023/09/rskibbe.Core_.Composition-Building-better-and-more-flexible-objects.png" alt="rskibbe.Core.Composition - Building better and more flexible objects" class="wp-image-16078" title="rskibbe.Core.Composition - Building better and more flexible objects"/></a><figcaption class="wp-element-caption">rskibbe.Core.Composition &#8211; Building better and more flexible objects</figcaption></figure>






<h2 class="wp-block-heading">What is rskibbe.Core.Composition?</h2>



<p>My NuGet package called &#8222;rskibbe.Core.Composition&#8220; is about helping you build more complex objects easier. It provides a common infrastructure for you to design your classes upon. It was private at first, but I&#8217;m using it in a lot of my projects, so I thought, why wouldn&#8217;t I publish it.</p>



<p>If you need more info on how it&#8217;s done behind the scenes, feel free to scroll further down. In a section at the bottom, I&#8217;ve provided more detailed explanation on this package. This way you can comprehend the idea behind everything a bit more and maybe even extend on it.</p>



<p>I&#8217;ve also added some small class diagram to have everything visually summarized and in one simple spot.</p>



<style>
.info-banner {
    background: #03a9f4;
    padding: 2em;
    border-radius: 0.5em;
    color: whitesmoke;
}
.info-banner a {
    color: #FED766;
}
</style>



<h2 class="wp-block-heading">Quick example</h2>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/Quick-example-rskibbe.Core_.Composition.png"><img decoding="async" width="640" height="360" src="https://robbelroot.de/wp-content/uploads/2023/09/Quick-example-rskibbe.Core_.Composition.png" alt="Quick example - rskibbe.Core.Composition" class="wp-image-16097" title="Quick example - rskibbe.Core.Composition"/></a><figcaption class="wp-element-caption">Quick example &#8211; rskibbe.Core.Composition</figcaption></figure>



<h3 class="wp-block-heading">Step 1 – Install the package</h3>



<p>Open the NuGet Package Manager and execute the following commands (or install it by GUI). This command will install the package to enable you using its interfaces and classes.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Install-Package rskibbe.Core.Composition</pre>



<h3 class="wp-block-heading">Step 2 – Start composing components</h3>



<p>Now you are already ready to go and start composing your own components / classes. Please move to <strong><a href="#detailed-explanation">the detailed explanation further down</a></strong> to get a better hang of the package.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="C#" data-enlighter-group="quickstart-object">public class MyComponent : Component
{

   // add different sub-components to your class
   // extend it e. g. with interfaces delegating their actions to
   // the corresponding sub-components

}</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="VB.NET" data-enlighter-group="quickstart-object">Public Class MyComponent
        Inherits Component

   ' add different sub-components to your class
   ' extend it e. g. with interfaces delegating their actions to
   ' the corresponding sub-components

End Class</pre>



<h2 class="wp-block-heading">Using composition over inheritance is the deal, right?</h2>



<p>When creating your classes there can be different scenarios where you sometimes need different approaches to solve designing them. Fore sure, we could like mostly use typical inheritance like &#8222;a robot is a machine&#8220; &#8211; but what if those machines are so damn (pardon me) complex, that you can&#8217;t fit them the right way by inheriting? This is where a typical composition scenario could fit for you!</p>



<p><strong>To get to know more about the &#8222;composition over inheritance pattern&#8220;, I will write a separate blog post, but for now this post here is about my corresponding NuGet package &#8222;rskibbe.Core.Composition&#8220;.</strong> This way, you will have a common denominator where you can build upon and you don&#8217;t have to start from scratch as well.</p>



<h2 class="wp-block-heading" id="detailed-explanation">Detailed explanation</h2>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/Detailed-explanation-rskibbe.Core_.Composition.png"><img decoding="async" width="640" height="360" src="https://robbelroot.de/wp-content/uploads/2023/09/Detailed-explanation-rskibbe.Core_.Composition.png" alt="Detailed explanation - rskibbe.Core.Composition" class="wp-image-16110" title="Detailed explanation - rskibbe.Core.Composition"/></a><figcaption class="wp-element-caption">Detailed explanation &#8211; rskibbe.Core.Composition</figcaption></figure>



<h3 class="wp-block-heading">The core conception</h3>



<p>When designing or &#8211; in other words &#8211; composing your object of desire, I found it pretty matching, to call the absolute &#8222;base&#8220; actually &#8222;<strong>IComposable</strong>&#8222;. It&#8217;s something you can almost magically compose out of different objects which then builds a new object – what I&#8217;m calling an &#8222;<strong>IComponent</strong>&#8222;. So basically the &#8222;IComponent&#8220; interface inherits from the &#8222;IComspoable&#8220; interface.</p>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/A-component-is-a-composable-being-composed-of-different-sub-components.png"><img loading="lazy" decoding="async" width="571" height="194" src="https://robbelroot.de/wp-content/uploads/2023/09/A-component-is-a-composable-being-composed-of-different-sub-components.png" alt="A component is a composable being composed of different sub-components" class="wp-image-16114" title="A component is a composable being composed of different sub-components"/></a><figcaption class="wp-element-caption">A component is a composable being composed of different sub-components</figcaption></figure>



<p>To actually do / execute this kind of composition, you will need to be able to <strong>dynamically add sub-components</strong> to your composable(s). Maybe you want to even <strong>dynamically remove the components</strong> again? This is why the following methods have been implement in the class &#8222;Composable&#8220;.</p>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/Component-class-inheriting-from-the-Composable-class-1.png"><img loading="lazy" decoding="async" width="728" height="337" src="https://robbelroot.de/wp-content/uploads/2023/09/Component-class-inheriting-from-the-Composable-class-1.png" alt="Component class inheriting from the Composable class" class="wp-image-16123" title="Component class inheriting from the Composable class"/></a><figcaption class="wp-element-caption">Component class inheriting from the Composable class</figcaption></figure>



<p>Adding and removing components won&#8217;t help much, if you can&#8217;t access and use them. So &#8211; for sure &#8211; and as visually mentioned inside the image above, there are methods to get your sub-components from a &#8222;parent&#8220;.</p>



<h3 class="wp-block-heading">Concrete example – A machine</h3>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2023/09/A-composed-robot-out-of-machine-parts-being-a-composable-object.png"><img loading="lazy" decoding="async" width="640" height="427" src="https://robbelroot.de/wp-content/uploads/2023/09/A-composed-robot-out-of-machine-parts-being-a-composable-object.png" alt="A composed robot out of machine parts being a composable object" class="wp-image-16200" title="A composed robot out of machine parts being a composable object"/></a><figcaption class="wp-element-caption">A composed robot out of machine parts being a composable object</figcaption></figure>



<p>Let&#8217;s now start a complete example of our first designed component being composed of composables – what a language-play. Keep in mind, that this actually – just an example, feel free to change it in any way fitting your needs&#8230; For this example, we&#8217;re taking a machine which could possibly connect many things to itself to use them.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="C#" data-enlighter-group="convrete-example">// a base class for some sort of common contextual denominator
class Machine : Composable
{

  public Machine()
  {
    // instantiated automatically - needs an empty constructor
    AddComponent&lt;LightComponent>();
    // manual instantiation, maybe with DI whatever
    var giantPowerBattery = new GiantPowerBattery();
    var laserBeamComponent = new LaserBeamComponent(giantPowerBattery);
    AddComponent(laserBeamComponent);
  }

}

// component 1
class LightComponent : Component
{

    public void Toggle() { /* some code.. */ }
    public void TurnOn() { /* some code.. */ }
    public void TurnOff() { /* some code */ }

}

// component 2
class LaserBeamComponent: Component
{

    IEnergySource _energySource;

    // having a ctor with dependency
    public LaserBeamComponent(IEnergySource energySource)
    {
        _energySource = energySource;
    }

    public void Shoot() { // some code.. }

}

// just some helper stuff..
interface IEnergySource { /* .. */ }

class GiantPowerBattery : IEnergySource { /* .. */ }</pre>



<h3 class="wp-block-heading">Using the sub-components</h3>



<p>Above, we just provided the composition side of things while composing our machine, but we didn&#8217;t actually use anything. If a machine wants to &#8222;shoot&#8220; with our &#8222;LaserBeamComponent&#8220; or if it wants to toggle the lights, it has to resolve the corresponding thing and use it. So we could just write something like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="C#" data-enlighter-group="using-sub-components">class Machine : Composable
{

  // rest of the machine code from above

  public void ToggleLight()
  {
    var light = GetComponent&lt;LightComponent>();
    light.Toggle();
  }

  // or shorter
  public void ToggleLight2()
    => GetComponent&lt;LightComponent>().Toggle();

  // rest of the machine code from above

}

// somewhere executable
Machine machine = new Machine();
machine.ToggleLight();

// maybe add more things?
// and call them dynamically?</pre>



<h3 class="wp-block-heading">A word on component types</h3>



<p>As you&#8217;ve probably seen in the example from above here, concrete types were used (in the constructors), like:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="C#" data-enlighter-group="word-on-component-types">AddComponent&lt;LightComponent>();</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="VB.NET" data-enlighter-group="word-on-component-types">AddComponent(Of LightComponent)()</pre>



<p>The problem is now, that we would have a more strict dependency on the &#8222;LightComponent&#8220;. I would prefer to rely on abstractions (interfaces) instead. And this is no probem, as you can just use other overloads of the &#8222;AddComponent&#8220; method:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Machine : Composable
{

  public Machine()
  {
    // using an interface alias when calling add
    AddComponent&lt;LightComponent, ILight>

    // or with an instance
    // remember to actually implement the interface here...
    LightComponent light = new LightComponent();
    AddComponent&lt;ILight>(light);
  }

  public void ToggleLight()
    => GetComponent&lt;ILight>().Toggle();

}

interface ILight : IComponent
{
  void Toggle();
  void TurnOn();
  void TurnOff();
}</pre>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h3 class="wp-block-heading">More reusable functionality with interface traits</h3>



<p>Imagine you&#8217;re having two objects being able to do pretty much the same. A &#8222;light-aware-machine&#8220; &#8211; like the one above &#8211; could toggle their light, a car could do so and your gaming console as well. Maybe we don&#8217;t want to create stuff like &#8222;TurnOn&#8220;, &#8222;TurnOff&#8220;, etc. again and again. As we can&#8217;t inherit from a base class implementing it, we can just use the &#8211; sort of &#8211; &#8222;Trait&#8220; feature from C#.</p>



<p>I&#8217;m talking about default implementations which interfaces can provide since C# version 8. Sadly you can&#8217;t have states in interfaces, so properties still need to be implemented. You could potentially define your interface trait like this: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    interface ILightTrait : IComponent
    {

        public void ToggleLight()
            => GetComponent&lt;ILight>().Toggle();

        public void TurnOnLight()
            => GetComponent&lt;ILight>().TurnOn();

        public void TurnOffLight()
            => GetComponent&lt;ILight>().TurnOff();

    }</pre>
</div></div>



<p>After defining that interface, every component – which should have a &#8222;Light functionality&#8220; could now just inherit from that interface. That means a machine, a gaming console, whatever could just inherit the functionality from that interface having the possibility to call the defined methods. When having like those 1 liners of methods, it&#8217;s no big deal, but as soon as it starts growing, it can make a big difference.</p>


<p class="rr-alert warning" style="background:#fff8c4;"><img decoding="async" alt="Warning notice" src="https://robbelroot.de/wp-content/themes/pinboard-child/imgs/warning.png"><span style="color:black;align-self: center;">Keep in mind that default implementation style used interfaces require you to use them as interface casted type, not the actual type. Take a look at the following two examples.</span></p>



<p>Let&#8217;s now define two classes which are able to toggle their lights and then use them. Our trait helps us not having to redefine everything from scratch.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    class GamingConsole : Composable, ILightTrait
    {

        public GamingConsole()
        {
            AddComponent&lt;LightComponent, ILightComponent>();
        }

    }

    class Car : Composable, ILightTrait
    {

        public Car()
        {
            AddComponent&lt;LightComponent, ILightComponent>();
        }

    }

    // more...</pre>



<p>Now let&#8217;s actually use these, care for the warning inside the yellow box from above. You have to cast the object to the interface type to actually use the trait-defined methods.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">GamingConsole gamingConsole

// won't work due to how default implementations are usable
gamingConsole.TurnOnLight();

// need's to look like this instead
((ILightTrait)this).TurnOnLight();</pre>



<h3 class="wp-block-heading">Publishing property notifications</h3>



<p>When building your complex objects, it could be useful to be able to publish &#8222;INotifyPropertyChanged&#8220; notifications. As both classes (Composable and Component) directly or indirectly inherit from &#8222;PropertyChangedBase&#8220;, you can do so pretty easily by just calling &#8222;NotifyOfPropertyChange&#8220;. Just provide the changed property name or let it figure it out itself by using the &#8222;CallerMemberNameAttribute&#8220;.</p>



<p>This could look like the following property implementation:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        bool _isOn;

        public bool IsOn
        {
            get => _isOn;
            set
            {
                if (_isOn == value)
                    return;
                // will automatically use "IsOn" as property name
                NotifyOfPropertyChange();
                // provide a name manually - but in favor with nameof()
                // NotifyOfPropertyChange(nameof(IsOn));
                // or completely manual
                // NotifyOfPropertyChange("IsOn");
            }
        }</pre>
<p>Der Beitrag <a href="https://robbelroot.de/blog/rskibbe-core-composition-building-better-and-more-flexible-objects/">rskibbe.Core.Composition – Building better and more flexible objects</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/rskibbe-core-composition-building-better-and-more-flexible-objects/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>VB.NET Webseite öffnen</title>
		<link>https://robbelroot.de/blog/vbnet-webseite-oeffnen/</link>
					<comments>https://robbelroot.de/blog/vbnet-webseite-oeffnen/#comments</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Sun, 04 Jul 2021 02:12:33 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic .NET]]></category>
		<category><![CDATA[Visual Basic .NET Problemlösungen]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[core]]></category>
		<category><![CDATA[fehler]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[globe]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[netcore]]></category>
		<category><![CDATA[öffnen]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[vbnet]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webseite]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[wide]]></category>
		<category><![CDATA[world]]></category>
		<category><![CDATA[www]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=2904</guid>

					<description><![CDATA[<p>VB.NET Webseite öffnen In VB.NET eine Webseite öffnen muss nicht schwer sein, obwohl es dafür verschiedene Wege gibt. Dieser Beitrag hier dient als eine Art Übersicht mit zusätzlichem Content und verschiedenen Ansätzen. Ebenso weise ich nochmal auf einen blöden Fehler hin, Welchen man natürlich vermeiden möchte! Awendungsbeispiele Man kennt es &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbnet-webseite-oeffnen/">VB.NET Webseite öffnen</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen.png"><img loading="lazy" decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-1024x536.png" alt="VB.NET Webseite öffnen" class="wp-image-2908" title="VB.NET Webseite öffnen" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen.png 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption>VB.NET Webseite öffnen</figcaption></figure>






<h2 class="wp-block-heading">VB.NET Webseite öffnen</h2>



<p>In <strong>VB.NET eine Webseite öffnen</strong> muss nicht schwer sein, <strong>obwohl </strong>es dafür <strong>verschiedene Wege </strong>gibt.</p>



<p>Dieser <strong>Beitrag </strong>hier <strong>dient als </strong>eine Art <strong>Übersicht mit </strong>zusätzlichem <strong>Content und </strong>verschiedenen <strong>Ansätzen</strong>.</p>



<p><strong>Ebenso weise </strong>ich nochmal <strong>auf </strong>einen <strong>blöden Fehler </strong>hin, Welchen man natürlich <strong>vermeiden </strong>möchte! </p>



<h2 class="wp-block-heading">Awendungsbeispiele</h2>



<p>Man <strong>kennt </strong>es ggf. <strong>aus </strong>einigen <strong>Anwendungen</strong>, <strong>dass </strong>das <strong>Web</strong>, <strong>bzw</strong>. der jeweilig installierter <strong>Browser mit </strong>einer <strong>Seite geöffnet </strong>wird.</p>



<p>Das <strong>erste</strong> mir einfallende <strong>Beispiel</strong>, wäre ein <strong>PayPal-Link</strong>, Welcher den <strong>Nutzer auf </strong>eine Spenden-, bzw. Überweisungsseite <strong>leiten </strong>könnte.</p>



<p>Man <strong>kennt diese Vorgehensweise </strong>durchaus von bekannten Programmen, Welche damit dann z. B. <strong>auf Paypal verweisen</strong>.</p>



<p><strong>Dazu </strong>klickt man dann <strong>wie im </strong>folgenden <strong>Bild auf </strong>einen programminternen <strong>Link </strong>und im nächsten Schritt <strong>öffnet </strong>sich der <strong>Browser</strong>:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-mit-linklabel.gif"><img loading="lazy" decoding="async" width="421" height="318" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-Webseite-oeffnen-mit-linklabel.gif" alt="VB.NET Webseite öffnen mit linklabel" class="wp-image-2913" title="VB.NET Webseite öffnen mit linklabel"/></a><figcaption>VB.NET Webseite öffnen mit linklabel</figcaption></figure>



<h2 class="wp-block-heading">Code – VB.NET Webseite öffnen</h2>



<p><strong>Um </strong>in <strong>VB.NET eine Webseite zu öffnen</strong>, <strong>können </strong>wir natürlich <strong>auf verschiedene Steuerelemente</strong>, <strong>oder</strong>/und <strong>Ereignisse zurückgreifen</strong>.</p>



<p>Sei es ein <strong>PayPal-Spendenbutton</strong>, oder wie <strong>oben </strong>gezeigt ein <strong><a href="https://docs.microsoft.com/de-de/dotnet/api/system.windows.forms.linklabel?view=net-5.0" target="_blank" rel="noreferrer noopener">LinkLabel</a></strong>, oder z. B. beim <strong>Öffnen </strong>eines <strong>Dialoges</strong>.</p>



<p>Es <strong>gehört </strong>meiner Meinung nach <strong>zur guten Manier</strong>, dem Nutzer zu erklären, <strong>dass </strong>sich dort jetzt sein <strong>Browser öffnet</strong>.</p>



<p>Ansonsten wäre das meiner Meinung nach eine schlechte <strong>User-Experience</strong>, wenn sich halt plötzlich der Browser öffnet.</p>



<p><strong>Damit </strong>wir final eine <strong>Seite öffnen </strong>können, <strong>brauchen </strong>wir für unser Beispiel die <strong><a href="https://docs.microsoft.com/de-de/dotnet/api/system.diagnostics.process.start?view=net-5.0" target="_blank" rel="noreferrer noopener">Start-Methode</a></strong> aus der <strong><a href="https://docs.microsoft.com/de-de/dotnet/api/system.diagnostics.process?view=net-5.0" target="_blank" rel="noreferrer noopener">Process-Klasse</a></strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="VB.NET" data-enlighter-group="process-start">Process.Start("https://google.de")</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="C#" data-enlighter-group="process-start">Process.Start("https://google.de")</pre>



<p>Das <strong>delegiert </strong>die <strong>Ausführung </strong>praktisch <strong>ans System </strong>und das <strong>System schaut</strong>: &#8222;Okay, <strong>wie </strong>kann ich das <strong>öffnen</strong>?&#8220;.</p>



<p>Da <strong>für dieses Schema </strong>im Hintergrund zu aller <strong>Wahrscheinlichkeit </strong>ein <strong>Browser hinterlegt </strong>ist, <strong>meldet sich </strong>der <strong>Standardbrowser</strong>.</p>



<p><strong>Anschließend </strong>wird der <strong>Browser </strong>die Anfrage nach seinem Ermessen und mit eventuellen <strong>Parametern </strong>verarbeiten.</p>



<p>Ein <strong>analog </strong>angelehnten <strong>Beispiel </strong>sehen wir im nächsten Abschnitt, wo wir den <strong>Browser </strong>dann gesondert <strong>angeben</strong>.</p>



<h3 class="wp-block-heading">Browser explizit angeben</h3>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2021/12/VB.NET-Webseite-oeffnen-Browser-waehlen.png"><img loading="lazy" decoding="async" width="640" height="335" src="https://robbelroot.de/wp-content/uploads/2021/12/VB.NET-Webseite-oeffnen-Browser-waehlen.png" alt="VB.NET Webseite öffnen - Browser wählen" class="wp-image-7066" title="VB.NET Webseite öffnen - Browser wählen"/></a><figcaption>VB.NET Webseite öffnen &#8211; Browser wählen</figcaption></figure>



<p>Wer einen <strong>konkreten Browser übergeben </strong>möchte, <strong>statt </strong>den <strong>Standardbrowser </strong>zu nutzen, kann dies häufig einfach tun.</p>



<p><strong>Viele </strong>gängige <strong>Programme können mit </strong>&#8222;Dingern&#8220; namens <strong>Parametern gestartet/ausgeführt </strong>werden.</p>



<p><strong>Eventuell </strong>ist Dir der <strong>Begriff Parameter </strong>ja bereits aus der Programmierung <strong>bekannt </strong>(ich denke mal :P).</p>



<p>Es sind <strong>letztendlich zusätzliche </strong>– ja wie sag ich lol – gewisse <strong>Werte </strong>in Form von Wörtern, oder auch Buchstaben, etc.</p>



<p><strong>Diese Werte </strong>werden dann als zusätzliche &#8222;Argumente&#8220;, also Zusatzinformationen <strong>an </strong>das zu <strong>startende Programm </strong>übergeben.</p>



<p><strong>Damit </strong>kann das <strong>Programm </strong>diese Parameter/Argumente bei Bedarf <strong>auswerten und </strong>nach eigener Logik <strong>verarbeiten</strong>.</p>



<p>Ein <strong>Beispiel für </strong>den <strong>Microsoft Edge Browser</strong> sieht z. B. wie folgt aus:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Process.Start("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", "https://google.de")</pre>



<p>Es <strong>reicht also</strong>, der &#8222;<strong>Process.Start</strong>&#8222;-Methode den jeweiligen <strong>Pfad zum Browser </strong>als <strong>erstes Argument und </strong>die gewünschte <strong>Adresse als</strong> <strong>zweiten Parameter</strong>, sprich als Start-Argument zu übergeben.</p>



<h3 class="wp-block-heading">Fehler abfangen</h3>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2021/12/VB.NET-Webseite-oeffnen-Fehler-abfangen.png"><img loading="lazy" decoding="async" width="640" height="335" src="https://robbelroot.de/wp-content/uploads/2021/12/VB.NET-Webseite-oeffnen-Fehler-abfangen.png" alt="VB.NET Webseite öffnen - Fehler abfangen" class="wp-image-7068" title="VB.NET Webseite öffnen - Fehler abfangen"/></a><figcaption>VB.NET Webseite öffnen &#8211; Fehler abfangen</figcaption></figure>



<p><strong>Natürlich </strong>kann es <strong>auch hier </strong>vorkommen, dass <strong>Fehler </strong>auftauchen, daher sollte man auch hier ggf. auf eine mögliche Fehlerbehandlung zurückgreifen.</p>



<p><strong>Dafür </strong>verwenden wir wie gewohnt die <strong>&#8222;Try-Catch&#8220;-Anweisung</strong> und <strong>fangen </strong>den Fehler in diesem Fall <strong>global </strong>ab.</p>



<p>In <strong>diesem Fall reicht </strong>dies <strong>denke ich </strong>so aus, obwohl man vermutlich noch <strong>tiefer graben </strong>könnte, <strong>Welche </strong>exakten <strong>Fehler </strong>auftreten können.</p>



<p><strong>Dazu kann </strong>man natürlich einen <strong>Blick auf </strong>die jeweilige Seite der Microsoft-<strong>Dokumentation </strong>zur <strong><a href="https://docs.microsoft.com/de-de/dotnet/api/system.diagnostics.process.start?view=net-6.0" target="_blank" rel="noreferrer noopener">&#8222;Process.Start&#8220;-Methode</a></strong> werfen.</p>



<p><strong>Dann </strong>würde man <strong>ggf</strong>. eine <strong>saubere Trennung </strong>zwischen den einzelnen Fehlern erarbeiten können, um separat reagieren zu können. </p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Private Sub btnCatchPathError_Click(sender As Object, e As EventArgs) Handles btnCatchPathError.Click
    Dim path = "C:\Program Files\Google\Chrome\Applicatissson\chrome.exe"
    Try
        Process.Start(path, "https://paypal.de")
    Catch ex As Exception
        MessageBox.Show($"Error opening the target path: {path}")
    End Try
End Sub</pre>



<h3 class="wp-block-heading">.NET Core Problem lösen</h3>



<p><strong>Wenn man </strong>den gezeigten <strong>Code auf </strong>einer <strong>.NET Core Plattform-App</strong> verwendet, wird man <strong>eventuell </strong>auf einen <strong>Fehler </strong>stoßen.</p>



<p><strong>Ich </strong>selbst bin natürlich <strong>auch </strong>beim Schreiben dieses Beitrags prompt <strong>auf </strong>diesen <strong>Fehler gestoßen </strong>– seufz.</p>



<p><strong>Daher dachte </strong>ich mir: &#8222;Eeyup, das <strong>nimmst </strong>du direkt mit <strong>in </strong>den <strong>Beitrag </strong>rein ;)&#8220;.</p>



<p><strong>Um </strong>diesen <strong>Fehler</strong>, bzw. dieses Problem <strong>zu vermeiden </strong>muss man eine <strong>neue Instanz </strong>der <strong><a href="https://docs.microsoft.com/de-de/dotnet/api/system.diagnostics.processstartinfo?view=net-5.0" target="_blank" rel="noreferrer noopener">ProcessStartInfo</a></strong>-Klasse erstellen und konfigurieren.</p>



<p>Die <strong>UseShellExecute</strong>-Eigenschaft muss hierbei <strong>explizit auf True </strong>gestellt werden, damit man den Fehler vermeidet.</p>



<p><strong>Hier </strong>drunter findest Du einmal das <strong>Beispiel mit </strong>einer <strong>URL und </strong>noch ein Beispiel mit der <strong>Angabe </strong>eines <strong>Browsers </strong>und URL.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    Private Sub btnOpenCoreSafe_Click(sender As Object, e As EventArgs) Handles btnOpenCoreSafe.Click
        'Dim processStartInfo = New ProcessStartInfo()
        'With processStartInfo
        '    .FileName = "https://paypal.de"
        '    .UseShellExecute = True
        'End With
        'Process.Start(processStartInfo)

        Dim processStartInfo = New ProcessStartInfo()
        With processStartInfo
            .FileName = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            .Arguments = "https://paypal.de"
            .UseShellExecute = True
        End With
        Process.Start(processStartInfo)
    End Sub</pre>



<h2 class="wp-block-heading">Kompletter Code – VB.NET Webseite öffnen</h2>



<p><strong>Obwohl </strong>sich der <strong>Code in </strong>diesem <strong>Beispiel </strong>wohl <strong>bescheiden </strong>hält, <strong>werde </strong>ich <strong>mich trotzdem </strong>mal <strong>an </strong>meine <strong>Routine halten</strong>.</p>



<p>Daher findest Du wie in fast jedem Beitrag, den Code hier am Ende in <strong>kompletter Form</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Public Class Form1

    Private Sub llblOpenPayPalWithChrome_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles llblOpenPayPalWithChrome.LinkClicked
        Process.Start("C:\Program Files\Google\Chrome\Application\chrome.exe", "https://paypal.de")
    End Sub

    Private Sub btnOpenGoogleWithEdge_Click(sender As Object, e As EventArgs) Handles btnOpenGoogleWithEdge.Click
        Process.Start("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", "https://paypal.de")
    End Sub

    Private Sub btnOpenYouTubeWithDefaultBrowser_Click(sender As Object, e As EventArgs) Handles btnOpenYouTubeWithDefaultBrowser.Click
        Process.Start("https://youtube.de")
    End Sub

    Private Sub btnCatchPathError_Click(sender As Object, e As EventArgs) Handles btnCatchPathError.Click
        Dim path = "C:\Program Files\Google\Chrome\Applicatissson\chrome.exe"
        Try
            Process.Start(path, "https://paypal.de")
        Catch ex As Exception
            MessageBox.Show($"Error opening the target path: {path}")
        End Try
    End Sub

    Private Sub btnOpenCoreSafe_Click(sender As Object, e As EventArgs) Handles btnOpenCoreSafe.Click
        'Dim processStartInfo = New ProcessStartInfo()
        'With processStartInfo
        '    .FileName = "https://paypal.de"
        '    .UseShellExecute = True
        'End With
        'Process.Start(processStartInfo)

        Dim processStartInfo = New ProcessStartInfo()
        With processStartInfo
            .FileName = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            .Arguments = "https://paypal.de"
            .UseShellExecute = True
        End With
        Process.Start(processStartInfo)
    End Sub
End Class</pre>



<h2 class="wp-block-heading">Downloads</h2>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link" href="/downloads/vbnet/OpenWebsiteExample.zip" target="_blank" rel="noreferrer noopener">OpenWebsiteExample.zip</a></div>
</div>



<h2 class="wp-block-heading">Weiterführende Links</h2>



<ul class="wp-block-list"><li><strong><a href="https://robbelroot.de/blog/vbnet-webbrowser-control" target="_blank" rel="noreferrer noopener">VB.NET Webbrowser Control</a></strong></li><li><strong><a href="https://robbelroot.de/blog/vbnet-webbrowser-get-element-by-class/" target="_blank" rel="noreferrer noopener">VB.NET Get Element by Class</a></strong></li><li><strong><a href="https://robbelroot.de/blog/vbnet-formular-automatisch-ausfuellen-winforms/" target="_blank" rel="noreferrer noopener">VB NET Formular automatisch ausfüllen (Winforms)</a></strong></li></ul>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbnet-webseite-oeffnen/">VB.NET Webseite öffnen</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/vbnet-webseite-oeffnen/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
