Question

How to convert this JavaScript code to C#? / Constants (Type) var TYPE_EUI64 = 'EUI-64'; var...

How to convert this JavaScript code to C#?

/ Constants (Type)
var TYPE_EUI64 = 'EUI-64';
var TYPE_RA28 = 'RA-28';
var TYPE_ADVA48 = 'ADVA-48';
var TYPE_RADIO_PAYLOAD = 'RadioPayload';
var TYPE_UNDEFINED = 'Undefined';
// Constants
var REELYACTIVE_OUI36 = '001bc5094';
/**
* Identifier Class
* Represents an identifier
* @param {string} type Type of identifier.
* @param {Object} value The value of the given identifier.
* @constructor
*/
function Identifier(type, value) {
var isValue = (value != null);
// Constructor for EUI-64
if((type == TYPE_EUI64) && isValue) {
this.type = TYPE_EUI64;
this.value = value;
}
// Constructor for RA-28
else if((type == TYPE_RA28) && isValue) {
this.type = TYPE_RA28;
this.value = value.substr(value.length - 7, 7);
}
// Constructor for ADVA-48
else if((type == TYPE_ADVA48) && isValue) {
this.type = TYPE_ADVA48;
this.value = value;
}
// Constructor for RadioPayload
else if((type = TYPE_RADIO_PAYLOAD) && isValue) {
this.type = TYPE_RADIO_PAYLOAD;
this.value = value.payload;
this.lengthBytes = value.payloadLengthBytes;
}
// Constructor for Undefined
else {
this.type = TYPE_UNDEFINED;
}
};
/**
* Convert this identifier to a new one of the given type, if possible.
* @param {string} newType New identifier type.
*/
Identifier.prototype.toType = function(newType) {
var isEUI64Target = (newType === TYPE_EUI64);
var isRA28Source = (this.type === TYPE_RA28);
if(isEUI64Target && isRA28Source) {
return new Identifier(TYPE_EUI64, REELYACTIVE_OUI36 + this.value);
}
return null;
}
module.exports = Identifier;
module.exports.EUI64 = TYPE_EUI64;
module.exports.RA28 = TYPE_RA28;
module.exports.ADVA48 = TYPE_ADVA48;
module.exports.RADIO_PAYLOAD = TYPE_RADIO_PAYLOAD;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.

using UnityEngine;
using System.Collections;

public class MYCLASSNAME : MonoBehaviour {
FIXME_VAR_TYPE TYPE_EUI64= 'EUI-64';
FIXME_VAR_TYPE TYPE_RA28= 'RA-28';
FIXME_VAR_TYPE TYPE_ADVA48= 'ADVA-48';
FIXME_VAR_TYPE TYPE_RADIO_PAYLOAD= 'RadioPayload';
FIXME_VAR_TYPE TYPE_UNDEFINED= 'Undefined';
// Constants
FIXME_VAR_TYPE REELYACTIVE_OUI36= '001bc5094';
/**
* Identifier Class
* Represents an identifier
* @param {string} type Type of identifier.
* @param {Object} value The value of the given identifier.
* @constructor
*/
void Identifier (type, value){
FIXME_VAR_TYPE isValue= (value != null);
// Constructor for EUI-64
if((type == TYPE_EUI64) && isValue) {
this.type = TYPE_EUI64;
this.value = value;
}
// Constructor for RA-28
else if((type == TYPE_RA28) && isValue) {
this.type = TYPE_RA28;
this.value = value.substr(value.length - 7, 7);
}
// Constructor for ADVA-48
else if((type == TYPE_ADVA48) && isValue) {
this.type = TYPE_ADVA48;
this.value = value;
}
// Constructor for RadioPayload
else if((type = TYPE_RADIO_PAYLOAD) && isValue) {
this.type = TYPE_RADIO_PAYLOAD;
this.value = value.payload;
this.lengthBytes = value.payloadLengthBytes;
}
// Constructor for Undefined
else {
this.type = TYPE_UNDEFINED;
}
};
/**
* Convert this identifier to a new one of the given type, if possible.
* @param {string} newType New identifier type.
*/
Identifier.prototype.toType = function(newType) {
FIXME_VAR_TYPE isEUI64Target= (newType === TYPE_EUI64);
FIXME_VAR_TYPE isRA28Source= (this.type === TYPE_RA28);
if(isEUI64Target && isRA28Source) {
return new Identifier(TYPE_EUI64, REELYACTIVE_OUI36 + this.value);
}
return null;
}
module.exports = Identifier;
module.exports.EUI64 = TYPE_EUI64;
module.exports.RA28 = TYPE_RA28;
module.exports.ADVA48 = TYPE_ADVA48;
module.exports.RADIO_PAYLOAD = TYPE_RADIO_PAYLOAD;
[RPC]
void Test (){}
}

Add a comment
Know the answer?
Add Answer to:
How to convert this JavaScript code to C#? / Constants (Type) var TYPE_EUI64 = 'EUI-64'; var...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following code is given for the class Student: class Student{ var choice1, choice2, name; var...

    The following code is given for the class Student: class Student{ var choice1, choice2, name; var numberOfChoices = 0; constructor(studentName){ this.choice1 = null; this.choice2 = null; this.choice3 = null; this.name = studentName; } getName = function(){ return this.name; }; setChoice = function(c){ if(numberOfChoices ==0){ this.choice1 = c; numberOfChoices++; } else{this.choice2 =c; }; getChoice1 = function(){ return this.choice1(); };} Write a section of code that creates a new StudentChoice object with name "Tom". Then set choice1 to "Algebra Review";

  • Hi! Can someone can convert this java code to c++. ASAP thanks I will thumbs up Here's the code: ...

    Hi! Can someone can convert this java code to c++. ASAP thanks I will thumbs up Here's the code: package lists; import bookdata.*; public class DoublyLinkedList { int size; //Variable que define el tamano de la lista. Node head, tail; //Nodos que definen el Head y Tail en la lista. //Constructor public DoublyLinkedList(){ this.head = null; this.tail = null; this.size = 0; } //Insert a new book in alphabetic order. public void insert(Book nb){ //Creamos uno nuevo nodo con el...

  • JavaScript (Please debug this code) When a user enters a string in the input box, the...

    JavaScript (Please debug this code) When a user enters a string in the input box, the program is designed to add the string to an array. When the array reaches a certain length, the program displays all the users' entries in a list on the page. When you finish debugging, the user's entry in the input box should be cleared each time the submit button is clicked. Additionally, after five strings are submitted, the entire list of submitted strings should...

  • Below is the given code of implementation: #include <string> #include <iostream> #include <list> #include <cassert> using...

    Below is the given code of implementation: #include <string> #include <iostream> #include <list> #include <cassert> using namespace std; class List; class Iterator; class Node { public: /* Constructs a node with a given data value. @param s the data to store in this node */ Node(string s); /* Destructor */ ~Node() {} private: string data; Node* previous; Node* next; friend class List; friend class Iterator; }; class List { public: /** Constructs an empty list. */ List(); /* Destructor. Deletes...

  • Since we do not want to have to rewrite this code when the element type changes,...

    Since we do not want to have to rewrite this code when the element type changes, this classes uses a Comparator to assist in ordering the elements. You will need to complete the siftUpComparator() and siftDownComparator() methods in the LinkedHeap Class. siftUp §Added element may violate heap-order property §siftUp() restores order starting at added node §Processing will continue working up the tree until: úFinds properly ordered node & parent úReaches the root (reaches node without parent) siftDown §Restores heap’s order...

  • This is the code I have written for a BingoBall program, I'd appreciate it if someone...

    This is the code I have written for a BingoBall program, I'd appreciate it if someone could help me fix this public class BingoBall { private char letter; private int number; // NOTE TO STUDENT // We challenge you to use this constant array as a lookup table to convert a number // value to its appropriate letter. // HINT: It can be done with with a single expression that converts the number // to an index position in the...

  • Can Anyone help me to convert Below code to C++! Thanks For example, in C++, the...

    Can Anyone help me to convert Below code to C++! Thanks For example, in C++, the function headers would be the following: class MaxHeap { vector<int> data; public: MaxHeap() { // ... } int size() { // ... } int maxLookup() { // ... } void extractMax() { // ... } void insert(int data) { // ... } void remove(int index) { // ... } }; ======================== import java.util.Arrays; import java.util.Scanner; public class MaxHeap { Integer[] a; int size; //...

  • Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])...

    Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])    {        Scanner s=new Scanner(System.in);        ScoresCircularDoubleLL score=new ScoresCircularDoubleLL();        while(true)        {            System.out.println("1--->Enter a number\n-1--->exit");            System.out.print("Enter your choice:");            int choice=s.nextInt();            if(choice!=-1)            {                System.out.print("Enter the score:");                int number=s.nextInt();                GameEntry entry=new GameEntry(number);   ...

  • This is my code that i need to finish. In BoxRegion.java I have no idea how...

    This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...

  • Need Help correcting last function runHanoi(A,C,B) so this program correctly calculates number of...

    Need Help correcting last function runHanoi(A,C,B) so this program correctly calculates number of moves made. Solving the Hanoi tower. Please post correct Javascript. This is used in jsfiddle. HTML: html> <schript src="TowerOfHanoi.js"</script> </script> <h1> Tower of Hanoi </h1> Enter the number of disks (Disk amount must be < 7): <br> <br> <input id = 'uInput' type = 'textbox' size = 10 > <button id = 'setup' onClick = 'insertDisks()'> Set up Tower of Hanoi </button> <button id=calc onClick = 'runHanoi(stackA,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT