Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# collection to Classic ASP

I am having trouble exposing a C# collection to Classic ASP. I've tried to use IEnumerable and Array. but I get the "object not a collection" error.

my method looks like:

public IEnumerable<MyObj> GetMyObj() { ... }

and on the Classic ASP side:

Dim obj, x 
Set obj = Server.CreateObject("Namespace.class")

For Each x in obj.GetMyObj
...

So how can I pass a collection to Classic ASP?

UPDATE:

may be this is a progress, the solution I found was to use a new class that inherits IEnumerable instead of using IEnumerable<MyObj>:

public class MyEnumerable : IEnumerable
{
   private IEnumerable<MyObj> _myObj;

   .
   .
   .

    [DispId(-4)]
    public IEnumerator GetEnumerator()
    {
      _myObj.GetEnumerator();
    }
}

But now when I try to access a property of MyObj I get an error: Object required.

Any idea?

like image 709
CD.. Avatar asked Oct 19 '10 14:10

CD..


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

I think you found the answer; Classic ASP with VB does not have generics built into it. So, you try to pass an IEnumerable<MyObj> to ASP and it comes out as a nightmarish mashup name which classic ASP has no clue how to work with.

The solution is to pass a non-generic IEnumerable. The problem then is that the sequence is treated as containing basic Object instances. You must revert to the pre-2.0 methods of casting objects you get out of a list. In VB this isn't difficult; just explicitly specify the element type and VB will implicitly cast for you while iterating through the For Each:

Dim obj, x 
Set obj = Server.CreateObject("Namespace.class")

For Each x As MyObj in obj.GetMyObj //casts each element in turn
   ...
like image 96
KeithS Avatar answered Sep 22 '22 23:09

KeithS