473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use CompareString() method

I added reference to Microsoft.Visua lBasic.dll to project.

Line

var r = Microsoft.Visua lBasic.Compiler Services.Compar eString("a", "b",
true)<1;

causes compile error:

The type or namespace name 'CompareString' does not exist in the namespace
'Microsoft.Visu alBasic.Compile rServices' (are you missing an assembly
reference?)

According to MSDN doc this method must exist in this assembly.

How to use this method from C# ?
I need to create linq expression tree which calls this method.

Andrus.

Jun 30 '08 #1
5 2581
Andrus wrote:
I added reference to Microsoft.Visua lBasic.dll to project.

Line

var r = Microsoft.Visua lBasic.Compiler Services.Compar eString("a", "b",
true)<1;

causes compile error:

The type or namespace name 'CompareString' does not exist in the namespace
'Microsoft.Visu alBasic.Compile rServices' (are you missing an assembly
reference?)

According to MSDN doc this method must exist in this assembly.
A method belongs to a class, not an assembly. It's a member of the Operators
class (which does reside in that assembly).
How to use this method from C# ?
You don't.
I need to create linq expression tree which calls this method.
I sincerely doubt that. There's a reason this method is flagged as "this API
supports the .NET Framework infrastructure and is not intended to be used
directly from your code."

I hesitate to ask why you think you need to create an expression tree that
uses Visual Basic internals in C#.

--
J.
Jun 30 '08 #2
Andrus <ko********@hot .eewrote:
I added reference to Microsoft.Visua lBasic.dll to project.

Line

var r = Microsoft.Visua lBasic.Compiler Services.Compar eString("a", "b",
true)<1;

causes compile error:

The type or namespace name 'CompareString' does not exist in the namespace
'Microsoft.Visu alBasic.Compile rServices' (are you missing an assembly
reference?)

According to MSDN doc this method must exist in this assembly.

How to use this method from C# ?
I need to create linq expression tree which calls this method.
CompilerService s is a namespace - methods don't exist directly in
namespaces. CompareString is a method in the Operators class.

Why do you think you need to call it though? What's wrong with
String.CompareT o?

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 30 '08 #3
I sincerely doubt that. There's a reason this method is flagged as "this
API supports the .NET Framework infrastructure and is not intended to be
used directly from your code."
That statement appears in many places in the docs but it's not always
trustworthy. It's part of a deeper problem with the .NET docs however which
are fundamentally very weak.
Jul 1 '08 #4
Jona and Jeroen,
Why do you think you need to call it though? What's wrong with
String.CompareT o?
I need to generate dynamically sql select statement which compares strings:

SELECT COUNT(*)
FROM Customer
WHERE CustomerId < 'AIRBU';

I expect that

Db.Customers.Wh ere( c =>
Microsoft.Visua lBasic.Compiler Services.Operat ors.CompareStri ng(
c.CustomerId, "AIRBU", false ) < 1 ).Count()

generates correct sql .

I'm not sure that String.CompareT o generates correct statement.

So I created following extension method based on Marc code samples:

public static IQueryable<TLes sThanOrEqual<T> (this IQueryable<T>
source, string property, object value)
{
ParameterExpres sion obj = Expression.Para meter(typeof(T) , "x");
Expression val = Expression.Cons tant(value, typeof(string)) ;
Expression prop = Expression.Prop erty(obj, property);
Expression call = Expression.Call (
typeof(Microsof t.VisualBasic.C ompilerServices .Operators).Get Method("Compare String",
new[] { typeof(string), typeof(string), typeof(bool) }), prop,
val,
Expression.Cons tant(false, typeof(bool)));
BinaryExpressio n testExp = LambdaExpressio n.LessThan(call ,
Expression.Cons tant(1, typeof(int))
);
return source.Where(Ex pression.Lambda <Func<T, bool>>(testExp,
obj));
}

Is this best solution ?

Andrus.

Jul 1 '08 #5
String.Compare should work just fine (assuming you get the sign the
right way, which always makes me have to stop and think...); example
using NWind:

int cnt = (from cust in ctx.Customers
where string.Compare( cust.CompanyNam e,"abc") < 0
select cust).Count();
/*
SELECT COUNT(*) AS [value]
FROM [dbo].[Customers] AS [t0]
WHERE [t0].[CompanyName] < @p0
*/

Marc
Jul 1 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3601
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected: virtual void do_bar() {} };
5
15346
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain,...
4
2891
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)> myFunctor = SampleFunction; string result = myFunctor(7, true); Works great thanks to the help from this group. Here's the guts so far for two-arity:
7
1736
by: greenflame | last post by:
I am trying to make a matrix object. I have given it some properites. I am trying to add a method. When I call the method by Test.showDims(...) I want to only enter one input, that is the method by which to do it. As you can see from the object definition that it corresponds to a function that takes two inputs. When I try to run the script it...
5
3399
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to...
18
4715
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
10
3355
by: Mihai Osian | last post by:
Hi everyone, Given the code below, can anyone tell me: a) Is this normal behaviour ? b) If it is, what is the reason behind it ? I would expect the A::method(int) to be inherited by B. Compiler: gcc 4.1, Linux Thanks,
9
5833
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to the static Parse method of the conversion class. if (InValue is string) return T.Parse((string)InValue); else return base.ConvertFrom(context,...
3
1343
by: allendowney | last post by:
Hi All. In a complex inheritance hierarchy, it is sometimes difficult to find where a method is defined. I thought it might be possible to get this info from the method object itself, but it looks like maybe not. Here is the test case I tried: class A(object):
0
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.