|
Thanks Pete, I was aware of the where t: class .
The end game that I was trying to achieve as a learning experiment was to create my own version of Automapper to allow me to convert either EF tables or single rows from tables.
The second part of the learning was to create a single class that would act as a facade to the whole process and direct the conversion depending on weather it was a BindingList, List or class.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
modified 25-Mar-14 16:14pm.
|
|
|
|
|
Sweet. I look forward to seeing an article on this as it sounds absolutely fascinating.
|
|
|
|
|
The problem that I see in what you're doing is that you're checking for the passed in type at run-time. The whole point behind Generics is that you treat the T as a template at compile-time, preventing you from writing invalid code before you even compile it.
Pete's solution takes care of that little problem by limiting what types can be passed in as you're writing the code.
|
|
|
|
|
I was aware of suggestion that Pete made where X : class
I was experimenting with basically creating my own version of Automapper as a learning exercise that would allow me to convert EF tables or single rows form the tables into business objects to use outside of the data layer.
I was trying to use a single facade class to act as the start of the conversion process which would then direct the data depending on the type that X was i.e. BindingList, List or class.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
In the sample code below, how can i set varying column widths for each column individually? The DescriptionColumnName width is expected to be much wider than other columns and Col1Name is not expected to be equal to Col2Name in width?. Currently, all columns are being returned with the same column width, and the description column in most cases contains alot of free text, so i want to reduce the width of columns Col1Name & Col2Name and then increase DescriptionColumnName width.
Document document;
document.NewPage();
System.Collections.ArrayList columnWidth = new System.Collections.ArrayList();
for (int i = 0; i < this.dataTable.Columns.Count; i++)
{
if (i < 2)
{
columnWidth.Add(2f);
}
else
{
columnWidth.Add(1f);
}
}
float[] headerWidths = columnWidth.OfType<float>().Select(w => (float)w).ToArray();
PdfPTable tableHeader = new PdfPTable(3);
tableHeader.AddCell(GetCell(Col1Name));
tableHeader.AddCell(GetCell(Col2Name));
tableHeader.AddCell(GetCell(DescriptionColumnName));
tableHeader.SetWidths(headerWidths);
tableHeader.HeaderRows = 1;
PopulatePDFCell(tableHeader);
document.Add(tableHeader);
|
|
|
|
|
Guys,
Am struck up with a scenario below,
I have 50 "Subfolder" under my "MainFolder"
In my project, On selecting a "Add Applications" button am browsing to MainFolder and selecting the same.
Now all the subfolders under the MainFolder need to be populated in the DataGird View, in my Project.
I tried with few commands which i got by browsing in blog, but not successfull.
Please assist, how can i acheive this.
Cheers,
|
|
|
|
|
What code do you have right now? When you say you want all subfolders to be populated in the DataGrid view, what exactly do you mean by this? Do you just want the folder names or do you want the contents of those folders as well? Do you need to keep iterating so that you pick up the entire folder tree under the main folder (i.e. subfolders of subfolders)?
|
|
|
|
|
I want to show a file under the SubFolder, (*.SFT)
MainFolder(is what am selecting)---> SubFolders--> (*.SFT) files
for e.g. 10 subfolder = 10 (*.SFT) files in it, to be listed in the DataGrid.
i use the below code to get the FolderPath.
string FldrPath = "";
// Create a new instance of FolderBrowserDialog.
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
FldrPath = folderBrowserDialog1.SelectedPath;
}
MessageBox.Show(FldrPath);
Cheers,
|
|
|
|
|
Below is some simple code that will get you started. This isn't the most flexible code that you can use but it should allow you to get started on the problem.
Personally I would build up a collection (Array, List or DataTable) and assign that as a data source.
Also it will only show the folders in the directory which you have specified and not each folders sub directory's.
DataGridViewTextBoxColumn first = new DataGridViewTextBoxColumn();
first.Name = "Name";
first.HeaderText = "Name";
dataGridView1.Columns.Add(first);
DataGridViewTextBoxColumn second = new DataGridViewTextBoxColumn();
second.Name = "FullName";
second.HeaderText = "Full Path";
dataGridView1.Columns.Add(second);
DirectoryInfo dir = new DirectoryInfo(@"d:\documents");
foreach (DirectoryInfo subDir in dir.GetDirectories())
{
dataGridView1.Rows.Add(new string[] { subDir.Name, subDir.FullName });
}
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
According to the expert across the aisle, I can download and install a free version of C# from Microsoft's website.
I just looked, can't find it.
My friendly expert says that the one I want is Visual C# 2010.
Can someone point me to the right place ?
|
|
|
|
|
You're talking about the Express editions. If you want Visual C# Express 2010 you can find it here[^]. There are more up to date versions available (2012 and 2013).
|
|
|
|
|
Pete to the rescue ! Hooray, nice to know somebody who knows something.
I see the two other versions you mentioned also have "Express Editions" as well.
Can I install all three ?
|
|
|
|
|
They do, but I wouldn't advise trying to install all three. Basically, 2012 introduced .NET 4.5 which you could think of as a patch to .NET 4 (it introduced some new features and fixed some bugs in the .NET 4 assemblies), so while you could develop .NET 4 applications with it, they might not behave on a machine that just has .NET 4 installed on it.
Of course, if you want the features introduced in 4.5, then you need to go for 2012 as a minimum, but if you're doing that you are better off going straight to 2013.
|
|
|
|
|
Here's what's going on.
We have a small box that does magic.
We have an existing minimalist interface that sends commands to it, and tells us what it gets back.
Friday, I learned that we have access to the source code, and I can write my own stuff, and make the thing really smart; i.e.,
If I send X,then wait for him to respond with Y
If he responds with Z instead, then go do Blah, Blah, Blah
Anyway, that kind of smarts.
Should I stick with 2010, or go for the new kid on the block ?
|
|
|
|
|
If it were my project, I would stick with 2010 based on the fact that what you have currently works with this and you don't want to introduce any issues.
|
|
|
|
|
|
|
I didnt ask about the meaning of life, but I guess its not C#?
|
|
|
|
|
You had the answer, because you knew the right question to ask.
I asked the question, but I asked the wrong question.
Or, more probably, asked the right question in the wrong manner.
|
|
|
|
|
If you're into free IDEs then SharpDevelop (clicky[^]) is worth a look, it will read VS project files and it's pretty full featured.
|
|
|
|
|
Thanks, will examine it.
This is an interface to an external box on my desk.
We have a useful interface already. We send a command and the box responds; and we see the response on our screen; exactly as the spec told the guy to do a year or two ago; and he did his job quite well.
We now want to add our own smarts into this arrangement, and write an interface that lets us give the box a command, and then read the response; and make a decision on what to do as a result.
e.g., something like...
SendTheCommand("X Y Z")
Response = ReadTheResponse()
if (Response == 1)
{
DoTheFirstThing()
}
if (Response == 2)
{
DoTheSecondThing()
}
I think this is going to have to be C# by fiat more than logistics.
Anyway, I will certainly spend a few minutes looking at your open source suggestion.
|
|
|
|
|
I may not have been clear there, #Dev is an IDE for writing .Net (i.e. C#) programs.
|
|
|
|
|
How does it compare with VS Express?
|
|
|
|
|
I've never actually used VS Express because the only time I tried (back in the day) it wouldn't run on my low spec machine at the time. At work my employer pays for VS Pro. However I think a lot of the more useful features of VS (unit test execution, object model inspection, following references into libraries, probably the refactoring stuff) isn't in Express. And #Dev is still far kinder on memory and resources so it will generally run significantly faster.
|
|
|
|
|