|
You create a custom comparer for the structure and use the overload for BinarySearch where you can specify a comparer.
---
b { font-weight: normal; }
|
|
|
|
|
I thought it might have something to do with a comparer. Comparers confuse the hell out of me, could someone provide an example of one along the lines of what I'm trying to do?
|
|
|
|
|
Something like:
public AllInfoComparer : IComparer<AllInfo> {
public int Compare(allInfo a, allInfo b) {
return a.movieId.CompareTo(b.movieId);
}
}
---
b { font-weight: normal; }
|
|
|
|
|
The compiler didn't like your example so I tired this:
class movieIdCompareValueClass:IComparer
{
public int Compare(allInfo a, allInfo b)
{
return a.movieId.CompareTo(b.movieId);
}
}
except I get this now:
test.Class1.movieIdCompareValueClass' does not implement interface member 'System.Collections.IComparer.Compare(object, object)'
I tried changing public int Compare(allInfo a, allInfo b) to public int Compare(object a, object b) but I got an error saying that movieId isn't part of object.
the compiler doesn't like adding <allInfo> after :IComparer.
Any idea why this isn't working?
|
|
|
|
|
kshet26 wrote: the compiler doesn't like adding <allinfo> after :IComparer.
Any idea why this isn't working?
Because you are not using C# 2.0, so generics is not available.
kshet26 wrote: I tried changing public int Compare(allInfo a, allInfo b) to public int Compare(object a, object b) but I got an error saying that movieId isn't part of object.
You have to cast the objects to allInfo before accessing the properties:
return ((allInfo)a).movieId.CompareTo(((allInfo)b).movieId);
---
b { font-weight: normal; }
|
|
|
|
|
Hi, In order to instantiate a HTMLDocument object, I need to load the URL or HTML to a web browser control. So, I have to place a web browser control on my form which really an inefficient way. Is there any way I can instantiate a HTMLDocument object just from HTML Stream ? like ,
IHTMLDocument2 doc = (IHTMLDocument2)SOME_CLASS.SOME_METHOD(string HTML_CODE) ;
Instead of
IHTMLDocument2 doc = (IHTMLDocument2) webBrowser1.Document;
Thanks
|
|
|
|
|
I have this method from an ocx that is expecting safearray object as arguments
ocx.GetData(ref object ySafeArray, ref object xSafeArray, ref int pts, ref double xbeg, ref double xend);
How do I create a SafeArray object in C# for the first two arguments? I did something like this...but that does not seem to work.
object yArray = new object();
object xArray = new object();
Thanks
|
|
|
|
|
|
Hi, is there any good tools available for cleaning up unnecessary codes and tuning up the codes for better performance ? (C#)
Example : Deleting all unused event handlers which was not automatically removed after deleting the control from the form.
Thanks.
|
|
|
|
|
Hi there,
I’m trying to implement a plug in API in a application and I’m having problems in getting the Custom Attribute from an Assembly.
First the custom attribute is something like this:
[global::System.AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]<br />
public class AssemblyPluginAttribute : Attribute<br />
{<br />
readonly string pluginName;<br />
<br />
public AssemblyPluginAttribute(string PluginName)<br />
{<br />
this.pluginName = PluginName;<br />
}<br />
<br />
public string PluginName<br />
{<br />
get<br />
{<br />
return this.pluginName;<br />
}<br />
}<br />
}
Than in order to find a reference to this custom attribute I added to the plug-in project the following line.
<br />
...<br />
using Enki.UI.ComponentModel;<br />
<br />
[assembly: AssemblyPluginAttribute("TestPlugin")]<br />
<br />
namespace TestPlugin<br />
{<br />
...<br />
Now ... to find if its a plug-in type assembly i look through the custom attributes of the assembly in order to find one matching with the one i defined (AssemblyPluginAttribute).
The following line returns null list.
<br />
Type AttType = typeof(Enki.UI.Plugins.AssemblyPluginAttribute);<br />
<br />
object[] obj = assembly.GetCustomAttributes(AttType, true);<br />
and the next one too...
Attribute[] attlist= Attribute.GetCustomAttributes(assembly,AttType);
but if instead of one of this two lines i use the following code
...<br />
foreach (Attribute att in Attribute.GetCustomAttributes(assembly))<br />
{<br />
if (att.GetType().FullName.CompareTo(AttType.FullName)==0)<br />
return true;<br />
}<br />
<br />
...<br />
it matches the full names!! I’ve tried many other ways to establish a possible comparison but none has the same result. I know, that if i found a way to get the result i desired i should stick to it an go on but I believe that this might lead me to a dead end in the future.
Please, can anyone help me... to "see the light in the end of the tunnel"!
Tanks
Pedro M.
|
|
|
|
|
Here is the factory method I use in a plug-in application I have. You do not appear to have a need for the "ICustomAttributeHandler" aspect of the logic so you should ignore that part.
public static object newInstanceFromCustomAttribute( Assembly assm, System.Type tAttribute, ICustomAttributeHandler handler)
{
object oret = null;
Module[] modules = assm.GetModules(false);
for(int nMod=0; null == oret && nMod<modules.Length; nMod++)
{
Type[] types = modules[nMod].GetTypes();
for(int nType=0; null == oret && nType<types.Length; nType++)
{
object[] attributes = types[nType].GetCustomAttributes(tAttribute, true);
for(int nAttr=0; null == oret && nAttr<attributes.Length; nAttr++)
{
if( handler.attributeQualifies( attributes[nAttr] as Attribute))
oret = assm.CreateInstance( types[nType].FullName);
}
}
}
return oret;
}
led mike
|
|
|
|
|
Hi mike,
i believe that i miss guided you. I dont want to find which types in an assembly have a custom attribute. I pretend to find which assembly has a specific custom Attribute.
So, want happens is I have an assembly that i know for sure that the custom attribute and i the only way that I get it saying that it has that attribute (return true) is comparing their FullName which,i think, is a rude solution to the problem.
Tanks for your help.
Best Regards
Pedro M.
|
|
|
|
|
hi
how to deploy my app with crystal report XI ? i am use VC# 2005.
and my another question is that how to access crystalreport objects (like text object) and change it's value ?
thanks.
|
|
|
|
|
Business Objects has several Windows Installer packages you can include with your installation. Be aware, however, they are huge.
The Crystal Reports XI Release 2 - .NET Merge Modules is around 150MB. Remember to set your Key in the MSM properties of whatever you use to build the installation package.
|
|
|
|
|
The environment is Visual Studio 2005 and my project was created via extensibility -> shared add-in.
How can I debug efficiently?
At present, I have to SETUP the add-in and start outlook manually each time I want to see the differences I have made to the program ...
|
|
|
|
|
Hi,
are there any roules for a dll written in C#, which can be called by a VBA Macro?
Private Declare Function foo Lib "foo.dll" (sfoo as string) as string
How does the C# code for such dll look like?
Ariadne
|
|
|
|
|
From C#, you would have to create a COM DLL to call from VB.
I do not think you can make native DLL's from c#, although you can in Visual C++.
|
|
|
|
|
How would I return the below in an array list object I started to stub it out but I confused myself. Any advice, help.
public void Execute() {
string strRoot = ConfigurationSettings.AppSettings["Root"];
DirectoryInfo dir = new DirectoryInfo(strRoot);
//Pass the Directory for displaying the contents
getDirsFiles(dir);
}
public void getDirsFiles(DirectoryInfo d)
{
//create my array of files using FileInfo object
FileInfo [] files;
//This will passed in or set to find zip files
//get all files for the current directory
string strFileType = ConfigurationSettings.AppSettings["FileType"];
files = d.GetFiles(strFileType);
//iterate through the directory and print the files
foreach (FileInfo file in files)
{
//get details of each file using file object
String fileName = file.FullName;
String fileSize = file.Length.ToString();
String fileExtension =file.Extension;
String fileCreated = file.LastWriteTime.ToString();
}
//get sub-folders for the current directory
DirectoryInfo [] dirs = d.GetDirectories("*.*");
foreach (DirectoryInfo dir in dirs)
if (dirs.Length > 0)
{
{
getDirsFiles(dir);
}
}
}
public ArrayList GetGrantFileInfo(NameValueCollection psRootDirs, string psFileType, string psIncludeFilter, string psExcludeFilter, ArrayList oFolder, CriteriaType oCriteriaType)
{
//Impliment GetGrantFileInfo()
// How do I take the code above and put it in here???? HELP.
ArrayList arrGrantInfo = new ArrayList();
GrantFileInfo oGrantFileInfo = new GrantFileInfo()
arrGrantInfo.Add(oGrantFileInfo);
return arrGrantInfo;
}
|
|
|
|
|
Hi all,
I am using a Microsoft Web Browser control in my C# application. I wish to disable right click context menu in it. Can anyone please tell me how do i achieve that.
I searched for a few article here, but they were not of much help.
Please help.
Thanks in advance.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
this article[^] seems to solve it. Also, have you looked at the .NET 2's System.Windows.Forms.WebBrowser control?
|
|
|
|
|
Excellent.. just what i was looking for.
Thanks a ton!!
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
webBrowser1.IsWebBrowserContextMenuEnabled = false;
|
|
|
|
|
I'm trying to do the equivalent of this in LINQ:
StringBuilder q = new StringBuilder("SELECT * FROM customer WHERE city = 'New York'");
if (westCoast)
q.Append(" OR city = 'Los Angeles'");
Here's what I have so far:
var q = dc.Customer.Where(c => c.City == "New York");
if (westCoast)
q.Where(c => c.City == "Los Angeles");
But I end up with "WHERE city = 'New York' AND city = 'Los Angeles'";
How do I tell it to use OR instead?
Thanks,
Alvaro
God existing isn't entirely impossible, but there's absolutely no evidence for it, so... the personal God as described by the Christian Bible existing is just as likely as a Pink Unicorn having created the universe, oh.. say... last Thursday. It's equally possible the moon has a core made of cheese. It's equally possible this sentence is in Spanish when you're not looking. - Someone on the Internet
|
|
|
|
|
Hi Alvaro. I haven't used LINQ too much, but I understand the Where method takes a Predicate<Customer>. All you're doing is writing a lambda expression, kind of shorthand for an anonymous method. Here's a more verbose version that should work, assuming Where takes a predicate:
var q = dc.Customer.Where(Criteria);
...
bool Criteria(Customer input)
{
return input.City == "New York" || (westCoast && input.City == "Los Angeles");
}
I'm not sure, but you may be able to do this right inside the lambda:
var q = dc.Customer.Where(c => c.City == "New York" || (westCoast && c.City == "Los Angeles"));
|
|
|
|
|
Thanks for your reply Judah.
I was more looking to do this in two steps, as an exercise. The first step sets up the base query, and then it would start growing based on different criteria. As I discovered, the default behavior is to AND the conditions together on multiple calls to Where . I was hoping someone would know how do change that to use OR instead.
Regards,
Alvaro
God existing isn't entirely impossible, but there's absolutely no evidence for it, so... the personal God as described by the Christian Bible existing is just as likely as a Pink Unicorn having created the universe, oh.. say... last Thursday. It's equally possible the moon has a core made of cheese. It's equally possible this sentence is in Spanish when you're not looking. - Someone on the Internet
|
|
|
|