|
Perhaps something like this will help. This implementation doesn't allow you to add items to the base list, I don't know if that is a requirement or not. This won't be particularly efficient but should work (untested!). You would need to add checks to make sure the lists aren't null too.
public class BaseList<TBase, TDerived1, TDerived2>
where TDerived1 : TBase
where TDerived2 : TBase
{
private List<TDerived1> derived1List;
private List<TDerived2> derived2List;
public List<TDerived1> Derived1List
{
get { return derived1List; }
set { derived1List = value; }
}
public List<TDerived2> Derived2List
{
get { return derived2List; }
set { derived2List = value; }
}
public ReadOnlyCollection<TBase> BaseCollection
{
get
{
List<TBase> baseList = DerivedConverter<TBase, TDerived1>(derived1List);
baseList.AddRange(DerivedConverter<TBase, TDerived2>(derived2List));
return baseList.AsReadOnly();
}
}
private static List<TBase> DerivedConverter<TBase, TDerived>(List<TDerived> derivedList)
where TDerived : TBase
{
return derivedList.ConvertAll<TBase>(
new Converter<TDerived, TBase>(delegate(TDerived derived)
{
return derived;
}));
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks Dave!
while not being the 'perfect' solution, you seem to have inadvertently solved another problem of mine, which I hadn't put to the forums yet!
I appreciate the help
|
|
|
|
|
You're welcome
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Would this help?
public static System.Collections.Generic.IEnumerable<T>
Enumerate<T>
(
params System.Collections.Generic.IEnumerable<T>[] Lists
)
{
foreach
(
System.Collections.Generic.IEnumerable<T> list
in
Lists
)
{
foreach
(
T t
in
list
)
{
yield return ( t ) ;
}
}
yield break ;
}
|
|
|
|
|
I wrote an application that outlook 2003 in C#, but I don't know how to deploy it? Who can help me?
|
|
|
|
|
Ok ill start by saying I am new to c# what i am trying to do is basicly access a ultralite db it has a table named Names(name,chan,freq,mpchan) I want to populate a combox with name field than have 3 text fields populate with the appropriate data for the name selection. Here is what i got so far
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using iAnywhere.Data.UltraLite;
using System.Collections;
namespace ChannMap
{
public partial class Form1 : Form
{
private string strChan;
private string strFreq;
private string strName;
private string strMapChan;
private string strTemp;
private string [] strArraylist=new string [1000];
static int i = 0;
private ULConnection ConnUL = new ULConnection();
private ULDataAdapter myDataAdapter = new ULDataAdapter();
private void Form1_Load(object sender, System.EventArgs e)
{
fnGetConnectedToDatabase();
}
public Form1()
{
InitializeComponent();
}
private void fnGetConnectedToDatabase()
{
try
{
String dbf = "\\Program Files\\ChannMap\\ChannMap.udb";
if (System.IO.File.Exists(dbf))
{
ConnUL.ConnectionString = "dbf=" + dbf + ";cache_size=1M";
if (ConnUL.State != ConnectionState.Open)
{
ConnUL.Open();
}
ConnUL.DatabaseID = 1000;
}
else
{
MessageBox.Show("Database is not available", "Error");
Application.Exit();
}
}
catch (System.Exception t)
{
MessageBox.Show(t.Message, "Connection failed");
return;
}
string sqlStr = "SELECT * FROM Names;";
myDataAdapter = new ULDataAdapter(sqlStr,ConnUL);
DataSet myDataset = new DataSet();
myDataset.Clear();
myDataAdapter.Fill(myDataset,"Names");
foreach (DataRow myRow in myDataset.Tables["Names"].Rows)
{
strChan =(string) myRow["chan"];
strFreq = (string)myRow["freq"];
strMapChan=(string) myRow["mpchan"];
strName=(string) myRow["name"];
strTemp=strChan+"*"+strFreq+"*"+strMapChan+"*"+strName;
strArraylist[i++]=strTemp;
comboChanName.Items.Add(strName);
}
ConnUL.Close();
}
private void comboChanName_SelectedIndexChanged(object sender, System.EventArgs e)
{
string delimstr = "*";
char [] delimeter = delimstr.ToCharArray();
string [] splitstr = null;
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
textBox1.Text = splitstr[0];
textBox2.Text = splitstr[1];
textBox3.Text = splitstr[2];
textBox4.Text = splitstr[3];
}
}
}
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
this piece when i try to deploy gives the error cannot convert char[] to char and cannot convert int to char. This a mobile app to. Am I going about this the hard way is there a better way or can this code be fixed?
Thank you for any help
Aaron
|
|
|
|
|
I did't read the whole code, but I can see a problem in the way you use the String.Split method.
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
This won't compile because it is not a valid overload. You should use delimeter instead of delimstr as the first parameter... See the complete list of String.Split overloads.
|
|
|
|
|
Didnt seem to have an effect when changed
|
|
|
|
|
Ok. I will try to ignore the fact that you provided way too much code that seems very cryptic and unreadable, while only about 10 lines are related to the error... I will ignore the fact that most of the infrotmation you provided with your code is absolutely useless and irrelevant. I will ignore the fact that the title of your first post is the second worst possible title (the first one being "PLZ HELP URGNT"). And I will also try to ignore the fact that your last post didn't contain that mysterious word starting with "tha" and ending with "nks"...
If my previous advice didn't help, there is not much more I can do for you. The best help I can give you is:
Read the compiler error carefully. Locate the problem in your code. Check everything on that line, see what parameters are required for each method... And then make sure that the parameters you are passing match the required type.
With intellisense and all the support provided by Visual Studio (or whatever tool you use) it should not take more than 23.7865039 seconds to locate and fix such a simple error like a type mismatch... even if you are a beginner!
|
|
|
|
|
I have been using Visual C++ Remote Debugger for debugging native code for some years, and it does not require Windows authentication. This is my first time doing C# things. I learned that remote debugging C# managed code requires Windows authentication.
The laptop with Visual Studio 2008 Pro (the host machine, Windows XP) is in my company domain, whereas the target machine (Windows 7) is of some WORKGROUP not in my company domain.
I have tried various configurations according to this MSDN doc[^] and this article[^], including the below:
- Setting up the identical account/password (of admins group) in both the host and the target machine,
- Turning off Windows Firewall,
- Turning on Windows Firewall with proper exceptions,
- Using "runas" to launch VS2008 with some specific user account,
- Enabling all ICMP responses,
- Adding my domain user account to the "Run as Service" in the Local Security Policy of the target machine,
etc.
Nothing makes it work. The symptom is as this screenshot[^]. Sometimes with certain configuration it said "Access is denied" in the end of the popup message.
Have anyone had the same experience? How did you resolve the issue?
Thanks in advance.
Maxwell Chen
|
|
|
|
|
Hi,
I'm not very good at RegEx , I want to use RegEx class to match values with desired string. My main string looks like this:
<%#String.Concat ..blah blah.. %>
in above string I want to get all the matches which between double quotes ( " ... " ) in blah blah part.
What is my expression should look like?
Thanks for your help
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
you should post in no more than one location (a single forum, or Q&A) so everything about this topic stays together.
|
|
|
|
|
What do you have so far?
Also see my RegEx tester[^] and Expresso.
Edit: I coulda sworn I replied in the RegEx forum!
modified on Sunday, September 5, 2010 11:41 PM
|
|
|
|
|
Hi all,
I am doing a very simple operation via c#.
1 I just copy an existing JPEG file in temp directory.
2 Then I open the copied Jpeg file from temp directory.
3 I try to delete the original Jpeg file and application crashes.
Please see below c# function for this:
using System.IO;
public void DeleteAfterCopyingOriginalImageFile(string strOriginalJpeg)
{
string strTempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "JpegTemp");
if (!Directory.Exists(strTempFolder))
{
DirectoryInfo directory = Directory.CreateDirectory(strTempFolder);
directory.Attributes = directory.Attributes | FileAttributes.Hidden;
}
string strTempJpeg = System.IO.Path.Combine(strTempFolder, "TempImage.jpg");
if (!File.Exists(strTempJpeg))
{
File.Copy(strOriginalJpeg, strTempJpeg);
}
Process.Start(strTempJpeg);
File.Delete(strOriginalJpeg);
}
I need to follow exactly these steps (cannot delete original file before opening TempImage.jpg). Can anybody help in knowing why copy and opening of temp file lock the original file. How can I prevent original jpeg file from being locked. I am new in .Net. Please help me.
More Info about the user case:
The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then open/edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory) one or he does not need original file any more, he can delete original file (and if required, can make temp file as the original one). So I strictly need to follow the same steps.
Regards
Aseem
Thanks in Advance
modified on Sunday, September 5, 2010 10:18 AM
|
|
|
|
|
Why not move[^] the file rather than copy it?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark. Thanks for the reply. Actually I cannot move the file. The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory), he can delete original file and make temp file as the original one. So I strictly need to follow the same steps.
Regards
Aseem
|
|
|
|
|
It seems you are making it much more difficult than it is. The user can edit the file all they want, when finished they save it, otherwise don't save it. No need for two file and all the copy/move activity. There are plenty of apps the come with undo features also, such as this A simple framework for adding undo/redo support[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes, you are right in that these steps can be minimized by as you said. But this is not possible in my case. Reasons for this:
1 This is DMS application.
2 User can edit (or simply open) the temporary copied file in some third party application like paint brush or something else. My application only helps in opening the temp file in third party application. Thereafter we don't keep the track with what the user does with the file. In case he simply view the file and find that he does not need it, he can delete the original file. So its the business case like this only which cannot be avoided.
|
|
|
|
|
I still see no need for a temp copy of the file. Once it is opened in the third party app the use can chose to save it or not. It's up to the third party app the provide functionality for undo/redo, overwriting, copying, etc., not your app.
Aseem Sharma wrote: So its the business case like this only which cannot be avoided.
Blindly attempting the implement everything the user wants in the manner in which they want is a sure failure. It's up to the architect or lead developer to present alternatives that can accomplish the same goal in a more reasonable fashion with better use/reuse and extensibility. From what I see you need to reevaluate your implementation and possibly requirements.
Good luck.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
One more requirement of my application is that I do not want to let the user know where the original file is present. User can just click a thumbnail from my application to open it. My application then makes a copy of original file in temp folder and open that temp copy of file.
And whatever the user case is, I think I am doing something wrong in my code that deleting original file generates exception and crashing my application. Just opening (and not even editing) the temp file should have no impact on the deletion of original file.
|
|
|
|
|
That depends entirely on how the app is using the file in the first place. If you're doing something like getting a thumbnail of an image file, your app is probably keeping the file open for the like of the thumbnail, in which case, you won't be able to delete it.
|
|
|
|
|
Yes, you are absolutely right. It was the Thumbnail who keep the original file locked. I myself started looking into some irrelevant way. Your reply made me check the Thumbnail part of code and I could fix my problem.
Thanks for this.
Best Regards
Aseem
|
|
|
|
|
A few suggestions:
1.
put all of it inside a try-catch and show the entire Exception.ToString().
2.
is the original file path a fully qualified path? is there any chance both paths get resolved to the same file?
|
|
|
|
|
1 Here is the Exception details
"System.IO.IOException: The process cannot access the file 'MyPhotograph.jpg' because it is being used by another process.\r\n at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)\r\n at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)\r\n at System.IO.Directory.Delete(String path, Boolean recursive)\r\n at NG.DataRep.CleanImage(String strFile) in E:\\Aseem Sharma\\KB\\My Software Development\\NG\\DataRep.cs:line 153"
2 Yes, I have confirmed, original file path is a fully qualified path and both temp file and original file are different file path.
|
|
|
|