Hi, I know that the XML Serializer does not support serializing private field. So I use a public field to get/set the private field like this: namespace TestObjectToXML.CarComponent { [XmlRootAttribute("Wheel", Namespace="", IsNullable=false)] public class Wheel : IWheel { public string wheelSize; private string _wheelType; public Wheel() { } public string wheelType { get{return this._wheelType;} set{this._wheelType = value;} } public string GetWheelType() { return this._wheelType; } public void SetWheelType(string type) { this._wheelType = type; } } }
However, if the wheel class needs to implement methods from a IWheel interface which has already some get and set method for the wheelType, is there any way to simplify this? Sometimes the interface cannot be modified and has a lot of such get and set methods. namespace TestObjectToXML.CarComponent { /// /// Summary description for IWheel. /// public interface IWheel { string GetWheelType(); void SetWheelType(string type); } }
Thanks
scchan1984
Posts
-
XML Serialization private field problem -
Strange behaviour of an C# Excel pluginHi, I have developed a Excel plugin using .NET 2003 two months ago. The plugin simply adds some buttons on the toolbar. Everything worked fine before. The plugin is installed by MSI. And now I open Excel again and the buttons disappear! Then I uninstall the plugin and reinstall it with the MSI I build two months ago. And the buttons do not appear, too. So, I open the plugin solution and decide to rebuild the MSI. When I open the solution, a error message "80004002" prompted and ask me for yes/no. No matter I chose yes/no I can still enter the solution and rebuild the plugin MSI. The error message didn't prompt next time. And the result is that the MSI successfully installed the plugin and I can see the buttons again. What's happened? Will the same thing happen again after two months from now? Thanks
-
Hashing in license key / serial key managementThanks, Then what is the algorithm of checking whether serial keys are valid or not. Simply compare with the hardcoded one inside the program? Is there any way that I can do to encrypt information inside serial keys?
-
Hashing in license key / serial key managementHi, I have a string (a mainkey + a salt). I want to hash it and get the hashed value. Is it possible to get back the string from the hased value with the same algorithm and given the mainkey? For example, I have 3 strings: mainkeySalt1 mainkeySalt2 mainkeySalt3 and their hashed values are: a for mainkeySalt1 b for mainkeySalt2, mainkeySalt3 (unfortunately, mainkeySalt2 and mainkeySalt3 have the same hashed values b) Any ideas? I do this kind of hashing and unhashing jobs for license key / serial key management (for user input during installation). What I want to do is do have a mainkey plus some parameters and then get a hashed value, i.e. the serial key. The serial key will then passed to a unhashing function, e.g. f(key, mainkey) returning yes and no (yes means mainkey is valid and no means mainkey is invalid) Any other ways can archieve the license key / serial key management that I want to do? Thanks
-
Converting char* to unicode big-endianMy improved version: WCHAR* UnicodeCharToBigEndianConverter(char* message) { // get the number of WCHAR from the message int nInputLen = MultiByteToWideChar( CP_ACP, // code page 0, // character-type options message, // string to map -1, // number of bytes in string NULL, // wide-character buffer NULL // size of buffer ); WCHAR* input = new WCHAR[nInputLen+1]; WCHAR* output = new WCHAR[nInputLen+1]; MultiByteToWideChar( CP_ACP, // code page MB_COMPOSITE, // character-type options message, // string to map -1, // number of bytes in string input, // wide-character buffer nInputLen+1 // size of buffer ); // escape character for unicode output[0]='\xFE\xFF'; for(int i=1;i<=nInputLen;i++) { output[i] = ((input[i-1] & 0xFF) << 8) | ((input[i-1] & 0xFF00) >> 8); //output[i] = input[i-1]; } output[nInputLen+1] = 0; return output; }
-
Converting char* to unicode big-endianReally really thank you so much. I have to improve and test my code now :D
-
Converting char* to unicode big-endianI got the answer!!! The reason is that when I change the ASCII character to big-endian, take 'B', with unicode \x42\x00, it become \x00\x42. And I used strlen to check the string length of (char* UnicodeCharToBigEndianConverter(char* message)), which finds the terminating character \x00, and gives me the wrong string length!! My code in the above post should be ok. Anyone interested in have a look in it and test it.
-
Converting char* to unicode big-endianThanks for everybody. I have constructed a method: char* UnicodeCharToBigEndianConverter(char* message) { wchar_t input[2000]; wchar_t output[2000]; MultiByteToWideChar( CP_ACP, // code page MB_COMPOSITE, // character-type options message, // string to map -1, // number of bytes in string input, // wide-character buffer strlen(message)+2 // size of buffer ); // escape character for unicode output[0]='\xFE\xFF'; MessageBoxW(NULL,input,L"Input",0); for(int i=1;i<=wcslen(input);i++) { output[i] = ((input[i-1] & 0xFF) << 8) | ((input[i-1] & 0xFF00) >> 8); } wcscat(output, (wchar_t*)"\x00\x00"); return (char*) output; } It works fine if the char* that I got from my application is a string with all unicode characters, e.g. all chinese characters. However, what if a user input a string with some chinese characters and some ASCII characters, e.g. A-Z, a-z? Is that whole string can be converted to big-endian using: output[i] = ((input[i-1] & 0xFF) << 8) | ((input[i-1] & 0xFF00) >> 8); Or we need to handle those ASCII characters?
-
Converting char* to unicode big-endianActually I want to convert the string pointed by a char* to big-endian encoding, nothing deal with TCP/IP. Like the following managed C++ code but work in unmanaged C++: #include "stdafx.h" #using using namespace System; using namespace System::Text; int main() { String* unicodeString = S"This string contains the unicode character Pi(中)"; // Create two different encodings. Encoding * unicode = Encoding::Unicode; Encoding * bigendian = Encoding::BigEndianUnicode; // Convert the string into a Byte->Item[]. Byte unicodeBytes[] = unicode -> GetBytes(unicodeString); // Perform the conversion from one encoding to the other. Byte bigendianBytes[] = Encoding::Convert(unicode, bigendian, unicodeBytes); // Convert the new Byte into[] a char and[] then into a string. // This is a slightly different approach to converting to illustrate // the use of GetCharCount/GetChars. Char bigendianChars[] = new Char[bigendian ->GetCharCount(bigendianBytes, 0, bigendianBytes -> Length)]; bigendian -> GetChars(bigendianBytes, 0, bigendianBytes->Length, bigendianChars, 0); String* bigendianString = new String(bigendianChars); // Display the strings created before and after the conversion. Console::WriteLine(S"Original String*: {0}", unicodeString); Console::WriteLine(S"bigendian converted String*: {0}", bigendianString); }
-
Converting char* to unicode big-endianHi, I have a char*. How to convert it to unicode big-endian in unmanagerd C++? Thanks
-
Call a running C# application from a C++ applicationHi, I have a C# windows application which is already running. I have another C++ application. I want to use the C++ application to send parameters or call functions in that running C# windows application. What should I do? I am new in COM. I guess the C++ application uses something like getObject to get the running C# windows application object. Am I correct? But how can I expose the COM interface in that running C# windows application, as it is not a componenet. Thanks
-
Using CVS to manage Visual Studio.NET solutionUsing CVS to manage Visual Studio.NET solution Hi, Recently I have several .NET solutions and I want to manage them by CVS (Concurrent Versions System). I am using WinCVS and I have a few questions: 1.Is there any special linkage of the CVS to the Visual Studio .NET? 2.Is the above way recommanded? 3.How can I know about the version of the .NET solution in the Visual Studio? Thanks
-
Using CVS to manage Visual Studio.NET solutionHi, Recently I have several .NET solutions and I want to manage them by CVS (Concurrent Versions System). I am using WinCVS and I have a few questions: 1.Is there any special linkage of the CVS to the Visual Studio .NET? 2.Is the above way recommanded? 3.How can I know about the version of the .NET solution in the Visual Studio? Thanks
-
Embedding a word document in C#Hi, Is it possible to to embed a word document in a C# form view? Like the internet explorer, when we visit a URL of a word document, the document will be opened in the browser instead of launching a stand alone MS Word. If yes, how to do so? Thanks
-
SQL queries with adapterHi, I found that there are two practices for writing queries for adapter. 1. one adapter queries for one table in the database e.g. select * from customer 2. one adapter queries for joinned table in the database e.g. select * from customer c1, country c2 where c1.country = c2.country Are the update/insert/delete command of an adapter work only for one table only? Which practice is encouraged? If the two tables are filled into the dataset, are there any SQL queries method to do the "join" operation to the two tables? anymore operations can be done? Thanks
-
Registry problemHi, I am writing a C# component to make files associate with .exe and applications. The first part, with .exe is done by adding "shell\open\command" with the path of the .exe. But how about with applications? I want to know what has an application(e.g.winrar, winamp) with installer done to the registry. What information about the application is need to write a C# component to register a file extension associating with the application? Thanks
-
Register Application in registryHi, I am writing a C# component to make files associate with .exe and applications. The first part, with .exe is done by adding "shell\open\command" with the path of the .exe. But how about with applications? I want to know what has an application(e.g.winrar, winamp) with installer done to the registry. What information about the application is need to write a C# component to register a file extension associating with the application? Thanks
-
System32 problemHi, Is that when I put an executable file in the system32 folder, I can run it in anywhere? without any more registration? How is it compatible with? WINXP, WIN2000, WINME, WIN98, WIN95? all ok?? Thanks
-
Register dll onto the OSHi, I created a DLL by VC++ and want to register and install it onto WinXP. I would like to know what choices are available for achieving it ? 1. Can I get it done by programming with C# ? If yes, how ? 2. Can I get it done by .msi or .cab ? If yes, how ? And I want to know that the general practice for creating the CLSID for the dll for deploying a software dll. Is the clsID generated at the developer machine ? or generated at the target machine ? Thanks
-
Memory mapfile problemhi, I want to ask if a DLL is unloaded, will the memory mapfile its referring to loses? Thanks