tags:

views:

123

answers:

1

Hi all, i created a Wrapper for a C++ dll. While reading the documentation i reached to a point using this function strcpy(StructName.strPropGetter, "A STRING"); I'm not kinda C++ guy, i can't figure how to transfer this code in C#. My wrapper gave me this property without a setter.

Any light would be nice. Thank you

A: 

It's simply StructName.strPropGetter = "A STRING";

edit If you mean how should you implement strPropGetter, then this is difficult wihout any information on what strPropGetter is. But it may be something like:

class StructName
{
    string strPropGetter { get; set; }
}

StructName.strPropGetter = "A STRING";

(This is a literal copy of the names to make it easier to see how it relates to the original snippet of code, but obviously "strPropGetter" etc should be named something more sensible. The "Getter" in the original name possibly refers to a "get" mehod for a property, in which case, this is generated automatically by C# for the "get;" part of the property in the code above.

I can't really help much more without a better idea of what code you're looking at wrapping/converting.

Jason Williams
How its so simply for setting a property without a setter?
I've only translated what you supplied: strcpy() is the "string copy" function, and it copies the second parameter ("A STRING") into the string pointed to by StructName.strPropGetter. You haven't supplied any information on what StructName.strPropGetter is, so I am unable to tell you how to convert it (if that is what you're asking). I'll update my answer with some guesswork...
Jason Williams
*@gtas:* I think that your understanding of "property" may differ from what they are generally thought of. C++ does not support the syntax for .NET-like properties; thus, properties are usually approximated using a _pair of functions_ (e.g. `get_X()` and `set_X()`). `strPropGetter` in your code is not a property at all, but most likely a plain **member variable** of type `char*`. You can read it or assign a value to it, but no special code-behind will be executed. If you want that to happen, you must write (public) getter and setter functions that access the (usually private) member variable.
stakx