Posts

Showing posts with the label c#

Exception member class OOP

Exception member class OOP I have met the following concept in the production code: class A { public: class Exception : public std::exception {/* ... */}; //... }; Nobody can give me a clear answer why it is like this. My question is whether this approach is in line with SOLID rules? I think that would be better if this exception class is located outside the class A and is injected while creating the instance of A. Design principles are important, but they aren't followed "because they are design principles". They are followed because they accomplish something. What would injecting the exception object upon construction accomplish? Now the class should manage this objects lifetime. What if an error state is never encountered, and it's never thrown? – StoryTeller Jul 2 at 6:16 ...

Why vsnwprintf missing

Why vsnwprintf missing I using vsnprintf for ansi string and it works well, returns -1 only on error and returns count of needen size if it does not fit into buffer. I need same function for wide strings, vsnwprintf just not exists. I also tried _vsnwprintf , but it acts really different, it returns -1 even if buffer too small, while I need to know how much to expand a buffer, but only when it's necessary, I don't want to make dummy calls just to determine needen size and only then expand a buffer. vsnprintf -1 vsnwprintf _vsnwprintf If look at vsnprintf code: vsnprintf int const _Result = __stdio_common_vsprintf( _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, _Buffer, _BufferCount, _Format, NULL, _ArgList); return _Result < 0 ? -1 : _Result; While _vsnwprintf approximately has: int const _Result = __stdio_common_vswprintf( _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _B...

Floating point equality

Floating point equality It is common knowledge that one has to be careful when comparing floating point values. Usually, instead of using == , we use some epsilon or ULP based equality testing. == However, I wonder, are there any cases, when using == is perfectly fine? == Look at this simple snippet, which cases are guaranteed to succeed? void fn(float a, float b) { float l1 = a/b; float l2 = a/b; if (l1==l1) { } // case a) if (l1==l2) { } // case b) if (l1==a/b) { } // case c) if (l1==5.0f/3.0f) { } // case d) } int main() { fn(5.0f, 3.0f); } Note: I've checked this and this, but they don't cover (all of) my cases. Note2: It seems that I have to add some plus information, so answers can be useful in practice: I'd like to know: This is the only relevant statement I found in the current draft standard: The value representation of floating-point types is implementation-defined. [ Note: This document imposes no requirements on t...

windows application that overlapes other application all time with close and minimise buttons

windows application that overlapes other application all time with close and minimise buttons Hi i wanted to create a windows app that holds any other application in the side of the screen and no other app should be overlapped it, and the controls should be given to that app any time. and it can be moved around the screen but it should overlap all other apps screen By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

C# webclient cannot download text from web

C# webclient cannot download text from web I am working on a project to get text from this website. But when I tested it in Visual Studio, I've got some error: Value cannot be null. Parameter name: solutionDirectory Here is my code: using System; using System.Net; public class Program { public static void Main() { WebClient client = new WebClient(); String temp = client.DownloadString("http://www.hkex.com.hk/eng/stat/dmstat/dayrpt/hsio180629.htm"); Console.Write(temp); } } This is not a problem with the code you presented, which other than a missing using works fine. – spender Jul 2 at 10:22 using Works for me... – TheGeneral Jul 2 at 10:22 ...

C - print args without stdlibs

C - print args without stdlibs I just wrote a C program that prints its command line argument without using the standard library or a main() function. My motivation is simply curiosity and to understand how to play with inline assembly. I am using Ubuntu 17.10 x86_64 with the 4.13.0-39-generic kernel and GCC 7.2.0. main() Below is my code which I have tried to comment as much as I understood. The functions print , print_1 , my_exit , and _start() are required by the system to run the executable. Actually, without _start() the linker will emit a warning and the program will segfault. print print_1 my_exit _start() _start() Functions print and print_1 are different. The first one prints out a string to the console, measuring the length of the string internally. The second function needs the string length passed as an argument. The my_exit() function just exits the program, returning the required value, which in my case is the string length or the number of command line arguments. ...

SFML, Google Test and Visual Studio

SFML, Google Test and Visual Studio I'm new on this site, so be gentle with me. I've made a project using visual studio 2017 and SFML. I need to add a google test project and I don't know how to set up correctly both SFML and gtest. When I try it using some tutorial online I get the error LINK2019, but this problem occurs only when I create a test.cpp that uses SFML elements that come from my main project. Also, my project needs to be an exe and cannot be converted to lib (I've also tried that option). If someone can help or link to a good tutorial for this I really appreciated. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

C# EPPLUS: Autosizing columns to the max autosize not working

C# EPPLUS: Autosizing columns to the max autosize not working I'm generating a number of excel documents with EPPlus and I'm running into some difficulties with the formatting. I have used xlWorkSheet.Cells.AutoFitColumns(); and this seems to work for the data, but does not autosize for the column names. For instance I will open up the file and I can see the column names bunched up. I can also click on the border of a column and it will expand the column more. In fact I can do this about 5 times before it seems to reach its maximum for autosizing. Essentially I want to programmatically set each column so that it's at this maximum (I've even tried applying AutoFitColumns multiple times, however this made no difference). Is there a way to do this? Note that I can't just hardcode the column widths as I'm trying to reuse the same code for multiple files. EDIT: Here's my code generalised private void GeneralTest() { var ReportName = "myReport" i...

WCF - Store and restore UTC DateTime

WCF - Store and restore UTC DateTime We expose to our customer a WCF webservice allowing them to store DateTime in SQL Server databases. Extract of the WSDL : <xs:complexType name="TimePeriod"> <xs:sequence> <xs:element minOccurs="0" name="endDateTime" nillable="true" type="xs:dateTime"/> <xs:element minOccurs="0" name="startDateTime" nillable="true" type="xs:dateTime"/> </xs:sequence> For exemple, my customer send me UTC Datetime : <af:effectivePeriod> <af:startDateTime>2018-01-16T10:32:28Z</af:startDateTime> </af:effectivePeriod> This is stored in a SQL Server database in a datetime field. datetime But in the output of the read service, I don't have the UTC indicator : <af:effectivePeriod> <af:startDateTime>2018-01-16T10:32:28</af:startDateTime> </af:effectivePeriod> "Z" is kind of a unique...

Showing the data of the right side of the TimeLine

Image
Showing the data of the right side of the TimeLine How can I show the description Data on the left or the right side of the timeline acording of it Candidate.Saving result? If it's Candidate.Saving == true it should be on the left, if it's Candidate.Saving==false it should be on the right side of the time line. I will shou here my candidate Model And my View. Candidate.Saving == true Candidate.Saving==false public class Candidate : BaseEntity { public int Id { get; set; } public string Name { get; set; } public int Number { get; set; } public string ProfileText { get; set; } public Byte CV { get; set; } public string CVNAME { get; set; } public List<Profile> ProfileList { get; set; } public String Description { get; set; } public Boolean Saving { get; set; } public string Title { get; set; } public DateTime DateOfDescription { get; set; } } Here is my view: @model HCCBPOHR.Data.Candidate @{ ViewData["Title"] = ...