Small Basic is built for version 3.5 SP1 of the .NET Framework, and won't be compatible with extensions in any other versions of it. You will want to create a class library (as outside of Small Basic "extensions" are generally referred to as libraries, or libs for short). You'll have to select ".NET Framework 3.5" from a dropdown at the top of the "New Project" window, and you'll have to select "Class Library", as shown below.
01.
using
System;
02.
System.Collections.Generic;
03.
System.Linq;
04.
System.Text;
05.
Microsoft.SmallBasic.Library;
06.
07.
namespace
Small_Basic_Extension_Tutorial
08.
{
09.
public
class
Class1
10.
11.
}
12.
1.
[SmallBasicType]
2.
static
ExampleExtension
/// <summary>
/// This is the class we will be using for our example extension.
3.
/// </summary>
4.
5.
6.
7.
Primitive ToPower(Primitive _base, Primitive index)
double
_base_ =
.Parse(_base.ToString());
int
_index =
.Parse(index.ToString());
_base_copy = _base_;
for
(
i = 0; i < _index; i++)
_base_copy *= _base;
return
(Primitive)_base_copy;
/// Raises a number to the specified power.
/// <param name="_base">The number to be raised.</param>
/// <param name="index">The power to raise the number to.</param>
/// <returns>The specified number raised to the specified power.</returns>
/// <example>ExampleExtension.ToPower(2, 2)</example>
8.
/// The username of the current logged-on user. This is a read-only property.
Primitive CurrentUsername
get
(Primitive)Environment.UserName;
private
Primitive _UserEditableValue = (Primitive)
null
;
13.
14.
/// A user-editable property.
15.
16.
Primitive UserEditableValue
17.
18.
set
{ _UserEditableValue = value; }
19.
_UserEditableValue; }
20.
21.
22.
23.
/// A user-editable property that has been implemented differently.
24.
25.
Primitive ShorterUserEditableValue
26.
27.
28.
29.
Testing Your Extension
Liam McSherry edited Revision 7. Comment: Fixed an image that didn't load due to an SSL error from the host.
Ed Price - MSFT edited Revision 6. Comment: Added missing white space after a code block. Great article!
gungan37 edited Revision 5. Comment: Changed ".Net 3.5" to ".Net 3.5 SP1" (didn't change the Menu dropdown though since you still should compile for 3.5)
Ed Price - MSFT edited Revision 3. Comment: Clarified the title
Congratulations on winning the contest here: blogs.msdn.com/.../small-basic-contest-winners-technet-wiki-content.aspx
Very clearly written and instructive. Thank you.
Thanks man
Dear,
I'm new with Small Basic and I think that is a fantastic way to start to programming :)
I'm trying to make a extensión with a external DLL, like this:
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.SmallBasic.Library;
namespace PoKeys56U
public static class PoKeys56
PoKeysDevice_DLL.PoKeysDevice device = new PoKeysDevice_DLL.PoKeysDevice();
public static void OnOut1()
But when I make the compilation appear this:
Error 1 'PoKeys56U.PoKeys56.PoKeys56()': no se permiten modificadores de acceso en constructores estáticos
Do you know how I can use this DLL?
Thanks