Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2020-04-17 10:59:59
Size: 546
Editor: Burathar
Comment:
Revision 3 as of 2020-04-17 11:04:38
Size: 1493
Editor: Burathar
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
=== Standard import === == Custom Events & Handling ==
CustomEventArgs.cs
Line 28: Line 29:

Instance.cs
{{{#!highlight c#
public delegate void NotifyCustomEvent(object sender, CustomEventArgs e);
public event NotifyCustomEvent CustomEvent;

private void RaiseCustomEvent(obj sender, obj item)
{
    CustomEvent?.Invoke(sender, new CustomEventArgs(item));
}
}}}


InstanceOwner.cs
{{{#!highlight c#
public InsanceOwner()
{
  Instance instance = new instance();
  instance.CustomEvent += new Instance.NotifyCustomEvent(CustomEventHandler);
}

public void CustomEventHandler(obj sender, CustomEventArgs e)
{
    //Handle that custom shit
}
}}}

== Number Remap Class ==
{{{#!highlight c#
public static class Remap
    {
        private static double Map(double value, double fromSource, double toSource, double fromTarget, double toTarget)
        {
            return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
        }
    }
}}}

Description

The snippets on this wikipage are written for the .NET Framework v4.0 and higher, but most probably work in older versions. Most will, however not work for .NET Core and .NET Standard.

Snippets

Custom Events & Handling

CustomEventArgs.cs

   1 public class CustomEventArgs : EventArgs
   2 {
   3     private readonly object item;
   4 
   5     public object Item
   6     {
   7         get { return item; }
   8     }
   9 
  10     public CustomEventArgs(object item)
  11     {
  12         this.item = item;
  13     }
  14 }

Instance.cs

   1 public delegate void NotifyCustomEvent(object sender, CustomEventArgs e);
   2 public event NotifyCustomEvent CustomEvent;
   3 
   4 private void RaiseCustomEvent(obj sender,  obj item)
   5 {
   6     CustomEvent?.Invoke(sender, new CustomEventArgs(item));
   7 }

InstanceOwner.cs

   1 public InsanceOwner()
   2 {
   3   Instance instance = new instance();
   4   instance.CustomEvent += new Instance.NotifyCustomEvent(CustomEventHandler);
   5 }
   6 
   7 public void CustomEventHandler(obj sender, CustomEventArgs e)
   8 {
   9     //Handle that custom shit
  10 }

Number Remap Class

   1 public static class Remap
   2     {
   3         private static double Map(double value, double fromSource, double toSource, double fromTarget, double toTarget)
   4         {
   5             return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
   6         }
   7     }

Howto/CSharp (last edited 2020-04-20 11:02:18 by Burathar)