Solved

PHP to C#

Posted on 2013-01-26
7
274 Views
Last Modified: 2013-02-04
Hi,

How can I convert the attahed PHP code to C#?

ayha
stlvolume.php
0
Comment
Question by:ayha1999
  • 3
  • 3
7 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 38822306
First of all, remove all the $ !!!

The code snippet basically reads a binary file, so you will need to use BinaryReader. So, instead of the following

$fp = fopen($filepath, "rb");
$section = file_get_contents($filepath, NULL, NULL, 0, 79);
fseek($fp, 80);
$data = fread($fp, 4);
$numOfFacets = unpack("I", $data);
for ($i = 0; $i < $numOfFacets[1]; $i++){
	//Start Normal Vector
	$data = fread($fp, 4);
	$hold = unpack("f", $data);

Open in new window

you do:

using (BinaryReader fp = new BinaryReader(File.Open(filepath, FileMode.Open)))
{
    fp.BaseStream.Position = 80;
    var numOfFacets = fp.ReadInt32();
    for (int i = 0; i< numOfFacets; i++) {
         var hold = fp.ReadSingle();
// etcetera

Open in new window

0
 
LVL 7

Author Comment

by:ayha1999
ID: 38822329
could u please convert the complete code?

Thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38822338
Hello ayha1999,
This is not a do-my-job-for-me site, but a collaboration site where volunteers try to solve your questions.
I already answered your question: "How can I convert the attahed PHP code to C#?"

From now on, you should try to do it by yourself and come back with any other question in order to acomplish your task.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Author Comment

by:ayha1999
ID: 38823422
Is there by php to c# conversion utility or php to asp.net project migration tool?

Thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38823432
There is not such thing, as far as I know.
The problem is that you don't want to convert the language itself but the framework library. Even worst, the standard PHP library is not object oriented but just a collection of functions, while the .net framework library is fully OO.
So, there is not other solution than translating it manually, which is quiet easy for something that knows about it.
0
 

Assisted Solution

by:kottamgari
kottamgari earned 250 total points
ID: 38825738
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 38851681
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question