|
Griff's answer is excellent, I'm just surprised that the 7 keystrokes you'd need to do that right now (slash, star, ctrl+right 3 times, star, slash) annoyed you enough to want to find a shortcut.
|
|
|
|
|
You mean 10 keystrokes. A "star" is Shift + 8 which is 2 keystrokes, and you forgot to count the CTRL keystroke, though I only counted it once since I could hold it down.
And that's just to comment out a simple Math.Truncate phrase. If I were doing a much bigger section of a line or even multiple lines, the keystrokes could exponentially grow.
Thanks for the Ctrl+right tip though, I didn't know that either and I like it.
|
|
|
|
|
Consider the following example..
public class Student
{
public string Name { get; set; }
public IList<Course> Courses { get; set; }
}
public class Course
{
public string Name { get; set; }
public IList<Student> Students { get; set; }
}
In this example a circular dependency exists between Student class and Course class. The scenario arises when we are dealing with entity framework - wherein db tables are created as classes for a Student database management system.
In case of C++ we use the concept of forward declaration for telling a class 'A' that another class called 'B' exists even before defining the class 'B'.
Can anybody explain how C# compiler solves this problem of circular dependency between classes?
PS: Please avoid telling me that the classes sould be redesigned to avoid circular dependency. The question is not related to designing since the below mentioned classes are very much from day-to-day programming scenarios.
If asking a question is bad; then not knowing the answer is worse!
|
|
|
|
|
With Interfaces.
public interface IStudent { String Name ... } ;
public class Student : IStudent
{
public string Name { get; set; }
public IList<ICourse> Courses { get; set; }
}
public interface ICourse { String Name ... } ;
public class Course : ICourse
{
public string Name { get; set; }
public IList<IStudent> Students { get; set; }
}
Or something like that.
|
|
|
|
|
I am by no means an expert, so don't take this answer as gospel. I am posting more to see if the gurus out there will correct any bad assumptions I have.
As I believe: C++ is based on C. When C was created there was a need to keep compilers efficient - CPU time = $$$$. Therefore, the C language was designed with the idea that its compilers should not need to make multiple passes of the code. In a single-pass compiling strategy, you have to know what something is before you can use it. Hence procedures and variables had to be declared before they could be used. That led to the need for header files and forward declarations.
I don't know if C++ compilers really need forward declarations, or whether it was just a carry over from C. But either way, this why I believe C++ has header files too.
C# simply broke the tradition. If you allow your compiler to go over the code once and categorize the classes/methods/properties/fields and then go over it again to compile it, then there is no need for forward declaration, nor for header files.
Am I way off base, Gurus?
Clive Pottinger
Victoria, BC
|
|
|
|
|
That's right; Eric Lippert explained it in more detail on his blog[^]
|
|
|
|
|
Ah!! Multiple parsing is the secret!!
Thank you very much Clive for answering my question and thank you Harold for sharing that wonderful link.
|
|
|
|
|
In C++ the compiler only needed a function's prototype or a class declaration, both usually found in headers. The compiler left it to the linker to locate the implementations and resolve those dependencies. When working with C++, this is a common error. The compiler compiles all sources without problems, but the linker stops with an error because you forgot to tell it where to locate a library which belongs to one of the headers you have included.
So you may very well see the linker as a second pass after compiling.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Hello Gurus.
Yes, I've painted myself into yet another corner. It seems to be what I do best, so I guess I should stick with it.
This time I am trying use reflection to find an event that I have attached to a class, but reflection is not showing the event. I don't know why.
I have created a simple class called ListPicker that is based on the DomainUpDown control. It is supposed to act just like a DomainUpDown control, but it supports the Modified property and the ModifiedChanged events that DomainUpDown does not. Here is the code:
using System;
using System.Windows.Forms;
namespace WindowsFormsControlLibrary
{
public partial class ListPicker : DomainUpDown
{
public EventHandler ModifiedChanged;
public ListPicker()
{
InitializeComponent();
TextChanged += new EventHandler(ListPicker_TextChanged);
Modified = false;
}
public bool Modified { get; set; }
public void ListPicker_TextChanged(object sender, EventArgs args)
{
Modified = true;
OnModifiedChanged();
}
protected void OnModifiedChanged()
{
if (ModifiedChanged != null)
{
ModifiedChanged(this, null);
}
}
}
}
The Modified property works just as I wanted it to, and the ModifiedChanged event fires when it is supposed to, but when I use this code (where ctl is a reference to the ListPicker control)
var x = ctl.GetType().GetEvents();
var modifiedChangedEventInfo = ctl.GetType().GetEvent("ModifiedChanged");
to look for the events on the ListPicker, it does not show the ModifiedChanged event. All the other DomainUpDown event show up in x, but not the ModifiedChanged event and modifiedChangedEventInfo is null
Any ideas? ... and many thanks
Clive Pottinger
Victoria, BC
|
|
|
|
|
Of what type is ctl? Is it of the class DomainUpDown or of ListPicker? If it is of DomainUpDown, you probably only see the events of this class and not of any derived classes.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
that must be because it isn't an event, it is just a delegate. Add the event keyword to your declaration and it should show up.
|
|
|
|
|
Good eyes! I just saw what I expected to see.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Whoa! I feel like I've just gone to the hospital to ask a surgeon why I keep getting headaches whenever I hit my head with a hammer. There should be a facepalm emoticon.
Thanks guys. I'll apply your suggestion to the code tonight and see what happens.
Clive Pottinger
Victoria, BC
modified 15-Nov-11 12:38pm.
|
|
|
|
|
Yup - that was it.
embarassing... that's all I have to say... embarassing
oh, and thanks.
BTW: I find it interesting that the question from one C.D.P was answered by another C.D.P.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Don't worry.
And you're welcome.
BTW: you shouldn't reply to self, as nobody gets mail notification when you do.
|
|
|
|
|
Clive D. Pottinger wrote: BTW: I find it interesting that the question from one C.D.P was answered by
another C.D.P
In my case the 'CDP' has nothing to do with my name or initials. A CDP1802 or RCA1802[^] was the CPU in my first computer. Look closely at the assembly code sample. One of the instructions, the one to designate the stack pointer, still does not fail to bring a wide grin to programming.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
An instruction any man would love to comply with I think
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Yes, who does not like to set the stack pointer
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Good catch. I read right over that.
|
|
|
|
|
Hi,
I have an Web Application developed in .NET Framework 4.0 and created an deployment setup for the same. The client requirement is to create an custom Apppool and assign it to the virtual directory which is currently installing. To address this issue i created an custom actions project as described in following article.
http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx[^]
I wrote the following code to create an apppool and assign it to the virtual directory.
private void CreateAppPoolIIS7()
{
using (ServerManager serverManager = new ServerManager())
{
string appPoolName = this.Context.Parameters["APPPOOL"];
ApplicationPool newPool;
newPool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == appPoolName);
if (newPool == null)
newPool = serverManager.ApplicationPools.Add(appPoolName);
newPool.ManagedRuntimeVersion = "v4.0";
newPool.ManagedPipelineMode = ManagedPipelineMode.Classic;
serverManager.CommitChanges();
}
}
private void AssignIIS7AppPoolToVirDir()
{
using (ServerManager serverManager = new ServerManager())
{
Microsoft.Web.Administration.Application newApp = null;
string appPoolName = this.Context.Parameters["APPPOOL"];
Site site = serverManager.Sites.First(s => s.Id == 1);
string installpath = this.Context.Parameters["INSTALLDIR"];
installpath = installpath.TrimEnd('\\');
string virdirname = "/" + installpath.Substring(installpath.LastIndexOf('\\') + 1);
newApp = site.Applications.FirstOrDefault(x => x.Path == virdirname);
if (newApp != null)
{
newApp.ApplicationPoolName = appPoolName;
serverManager.CommitChanges();
}
else
{
MessageBox.Show("Website not found");
}
}
}
I call these methods in the Install event of the installer as follows..
public override void Install(IDictionary stateSaver)
{
.......
CreateAppPoolIIS7();
AssignIIS7AppPoolToVirDir();
The assigned app pool is reflected in the IIS as long as the control is in the custom action project. The apppool resets back to the default selected at the start of the installer once the setup exits the custom action project.
It would be grateful if some one could help.
When you fail to plan, you are planning to fail.
|
|
|
|
|
Hi All,
I am using the WPF ribbon Library in my application for getting a ribbon control attached in my application.
I need the functionality where I can trap the minimize event in ribbon and do some additional stuff of code in there.
But, to my surprise I could not find any property named Minimized in ribbon .. I could found out collapsed and Expanded but they were of no use.
Can some body tell me what does IsMinimize property correspond to. As,if I know for which property the minimize functionality is attached,I can then easily solve my problem statement.
-Kushagra
I believe in Me !!!
|
|
|
|
|
|
I have an XNA application which runs in several threads. One thread takes care of the 3D rendering, the other one is a GUI with the application logic. The controls of the GUI are also drawn by the rendering thread, therefore some thread synchronization between the UI thread and the rendering thread exists. Basically this is neeeded only when a control's properties are changed so that the control must be redrawn. Locks are only needed while those properties are changed, so that a control is not accidentally drawn with only half of the changes, causing ugly rendering glitches. This synchronization is only brief and does not cause any visible delay in rendering or in the performance of the UI thread.
The UI thread makes use of a webservice to fetch or write data from and to the server. With synchronous webservice calls I would expect the UI thread to freeze up while waiting for the response. This should have no bearing on the rendering thread, as the UI thread is waiting and not making any changes to controls. Against this expectation, the rendering thread also briefly freezes when a web method is called.
Using asynchronous webservice calls solves the problem and will be the way to go, but I also would like to understand what is going on. I use a quad I7 proceesor at 4 GHz, so calling a web method in a multithreaded application should (and does not) generate a CPU load of 100%. Also it cannot be because of thread synchronization.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
modified 15-Nov-11 7:58am.
|
|
|
|
|
How are you determining that the rendering thread freezes? Obviously anything it tries to display will get delayed, and if you have any event handlers which call Invoke onto the UI thread, those will also cause a synchronisation point. The debugger is primarily attached to the UI thread and so if you're looking at it in there it might also show a freeze, which could be an artifact of the debugging environment.
|
|
|
|
|
Thank you. The program at the moment uses a simple animated scene (a continuously rotating model) in the background and the current frame rate is displayed. When web methods are called, the rotation of the model stops for the duration of the call and the frame rate is not updated. Then it resumes and the frame rate briefly is displayed as 0, indicating that the rendering thread indeed stood still during that time. No such delays happen when the webservice calls are commented out.
Edit: Just to be precise: I had started it in debug mode, but there were no breakpoints. It was the mere presence of the debugger which caused this behavior. When I come home I will take a look how well the current version fares.
I have an older version of the project here and just compiled it with 'Release' settings and started the program from Windows Explorer, so that the debugger was not present in any way. It worked as expected: The UI thread waited when calling the webservice, briefly freezing the UI. Meanwhile the animated 3D rendering in the background continued without any visible delay or drop in the frame rate, even when slower web methods were called.
I'm glad that the debugger was the culprit and that there is no hidden bug which may come back and cause even more trouble.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
modified 15-Nov-11 11:01am.
|
|
|
|