Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Instantiating an struct defined as DNVSRISKMDECORE!STRUCT1

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marek - 05 Mar 2008 12:12 GMT
Hi
I am trying to call a method in a FORTRAN.NET assembly that requires a
structure parameter.  Intellisense tells me that the structure name is
DNVSRISKMDECORE!STRUCT1 and this is confirmed by reflector.  However in the
C#, declaring an object of type DNVSRISKMDECORE!STRUCT1 is rejected because
of the ! mark.

Please could anyone help?

Best regards

Marek
Ben Voigt [C++ MVP] - 05 Mar 2008 19:39 GMT
> Hi
> I am trying to call a method in a FORTRAN.NET assembly that requires a
[quoted text clipped - 6 lines]
>
> Please could anyone help?

From the C# specification: "Unicode escape sequences are permitted in
identifiers".

So use the following name:

DNVSRISKMDECORE\u0021STRUCT1

> Best regards
>
> Marek
Marek - 06 Mar 2008 07:42 GMT
Hi Ben
Not sure if I understood or not, but using the name you suggested the
compiler complains:

error CS1056: Unexpected character '\u0021'

Best regards

Marek

> > Hi
> > I am trying to call a method in a FORTRAN.NET assembly that requires a
[quoted text clipped - 17 lines]
> >
> > Marek
Willy Denoyette [MVP] - 06 Mar 2008 09:01 GMT
Punctuator characters are not allowed in identifiers (see ECMA-335 ch
8.5.1), so, ! is not allowed and as \U0021 is exactly the same a s !, the
compiler complains in both cases with the same error.
AFAIK, punctuations are not allowed in Fortran, so I doubt this is the real
class name you are referring to.
If Fortran.net does allow such names on public interfaces, then is violates
the above mentioned CLS rules.

Willy.

> Hi Ben
> Not sure if I understood or not, but using the name you suggested the
[quoted text clipped - 27 lines]
>> >
>> > Marek
Jon Skeet [C# MVP] - 06 Mar 2008 08:22 GMT
> I am trying to call a method in a FORTRAN.NET assembly that requires a
> structure parameter.  Intellisense tells me that the structure name is
[quoted text clipped - 3 lines]
>
> Please could anyone help?

Unfortunately that name violates CLS rule 4. I'd expect quite a few
languages to have issues consuming it.

You may be forced to use reflection in order to access it from just C#.
If you have to use it a lot, you may be able to create your own
structure (probably using ILDASM/ILASM) which mirrors the existing
structure, and has conversion methods to/from the Fortran one. With
that in place, you'd never need to actually specify the name in C#
code. It's a really ugly solution though.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Marek - 06 Mar 2008 09:13 GMT
Hi Ben, Willy and Jon
Thanks for all your replies.  I was worried that you were going to say that.
Our requirement is to call a method that uses this object so I can get away
with creating and using the object as follows:

           Type struct1Type = assembly.GetType("DNVSRISKMDECORE!STRUCT1");
           object struct1Instance = Activator.CreateInstance(struct1Type);

           struct1Type.InvokeMember("iint1", BindingFlags.SetField, null,
struct1Instance, new object[] { -1 });
           struct1Type.InvokeMember("iint2", BindingFlags.SetField, null,
struct1Instance, new object[] { -2 });
           struct1Type.InvokeMember("ddouble1", BindingFlags.SetField,
null, struct1Instance, new object[] { -10.0 });
           struct1Type.InvokeMember("ddouble2", BindingFlags.SetField,
null, struct1Instance, new object[] { -20.0 });

Thanks for your responses.

Best regards

Marek

> > I am trying to call a method in a FORTRAN.NET assembly that requires a
> > structure parameter.  Intellisense tells me that the structure name is
[quoted text clipped - 13 lines]
> that in place, you'd never need to actually specify the name in C#
> code. It's a really ugly solution though.
Jon Skeet [C# MVP] - 06 Mar 2008 09:20 GMT
> Thanks for all your replies.  I was worried that you were going to say that.
>  Our requirement is to call a method that uses this object so I can get away
[quoted text clipped - 13 lines]
>
> Thanks for your responses.

Do you only have to do this once? If so, that's a reasonable workaround
(horrible as it is that you have to do it). If you need to use it more
often, I'm happy to help you with the alternative idea about a
surrogate structure.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Marek - 06 Mar 2008 09:32 GMT
Hi Jon
Thanks for the offer.  I did dabble with Reflector yesterday, which did show
how to create the object using:

[StructLayout(LayoutKind.Explicit, Size=0x18, Pack=8), DebugInfo(new byte[] {
   0x69, 0x69, 110, 0x74, 0x31, 0, 0x20, 0, 0, 0, 4, 0, 0, 0, 0x10, 0,
   0, 0, 4, 0, 0, 0, 0x69, 0x69, 110, 0x74, 50, 0, 0x20, 0, 0, 0,
   4, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 100, 100, 0x6f, 0x75,
   0x62, 0x6c, 0x65, 0x31, 0, 0x20, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0,
   0, 8, 0, 0, 0, 100, 100, 0x6f, 0x75, 0x62, 0x6c, 0x65, 50, 0, 0x20, 0,
   0, 0, 11, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 0, 0
})]
public struct DNVSRISKMDECORE!STRUCT1
{
   // Fields
   [FieldOffset(0)]
   public double ddouble1;
   [FieldOffset(8)]
   public double ddouble2;
   [FieldOffset(0x10)]
   public int iint1;
   [FieldOffset(20)]
   public int iint2;
}

The good news for me is that because of our application design, all the
methods and objects (lots of) are stored on a data dictionary and they are
built using the late invocation approach anyway.

Thanks again.

Best regards

Marek

> > Thanks for all your replies.  I was worried that you were going to say that.
> >  Our requirement is to call a method that uses this object so I can get away
[quoted text clipped - 18 lines]
> often, I'm happy to help you with the alternative idea about a
> surrogate structure.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.