|
Amar Chaudhary wrote: When i pass System.windows.forms.dll instead of MScorlib.dll
it throws a file not found exception
It is located at %SystemRoot%\Microsoft.net\Framework\v2.0.50727\System.Windows.Forms.dll
|
|
|
|
|
Amar Chaudhary wrote: When i pass System.windows.forms.dll instead of MScorlib.dll
it throws a file not found exception
GAC assemblies require more than just the DLL file name, like version, maybe culture. Try doing some research on MSDN to get the details.
|
|
|
|
|
Assembly a = Assembly.LoadWithPartialName("System.Windows.Forms");
Type[] types = a.GetTypes();
foreach (Type t in types)
{
listBox1.Items.Add(t.ToString());
}
MessageBox.Show(listBox1.Items.Count.ToString());
this is giving result but with warning
Warning 1 'System.Reflection.Assembly.LoadWithPartialName(string)' is obsolete: 'This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202' E:\important\Articles for code project\Theme Applier for windows forms\EasyUI\UIApplier\UIMaker\ControlBrowser.cs 31 26 UIMaker
I am looking more into it Thanks for your help
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later.
Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET?
Thanks.
|
|
|
|
|
www.expresso.com, or search for Expresso on this site. It's a program that helps you build and test regex. Also, the regex book from O'Reiley is pretty awesome.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
But there is RegEx in general and then there is .NET's flavor of RegEx. Are you recommending the O'Reilly book for .NET?
|
|
|
|
|
The O'Reilly book covers the different flavours in depth.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
+1 for http://regexlib.com[^]
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
If I understand you correctly, it would be a simple case of creating a regex string of something like "^(?<mymatch>.*)"+ sMyTerminatorString. Then check the matches for mymatch (or whatever you name it).
|
|
|
|
|
Look into RegexOptions.MultiLine to change whether "." matches newlines as well...
myRegex = new Regex("^.*?(?=myStringThatDelimitsTheEndOfTheMatch)");
Match m = myRegex.Match(sampleString);
if (m.Success) {
m.Value; // this returns only the part of the match
// that occured prior to your delimiting string
}
|
|
|
|
|
I have the following function:
public bool getOperatorResult<T>(string operatorType, T operandA, T operandB)
{
if (typeof(T) == typeof(bool))
{
System.Object obj = operandA;
bool a = (bool) obj;
obj = operandB;
bool b = (bool) obj;
switch (operatorType)
{
case "or":
return (a || b);
case "and":
return (a && b);
case "equal":
return (a == b);
case "notequal":
return (a != b);
default:
return false;
}
}
else if ((typeof(T) == typeof(int)) || (typeof(T) == typeof(double)))
{
}
}
This code works but just does not look right to me. Also in the second part where I look for numbers, I don't know how I can cast to either int or double. Any ideas
If I try to directly put in:
switch (operatorType)
{
case "lessthan":
return (operandA < operandB);
case "morethan":
return (operandA > operandB);
case "lessthanequalto":
return (operandA <= operandB);
case "morethanequalto":
return (operandA >= operandB);
case "equal":
return (operandA == operandB);
case "notequal":
return (operandA != operandB);
default:
return false;
}
I get compiler errors:
Operator '<' cannot be applied to operands of type 'T' and 'T'
.....
.....
|
|
|
|
|
Can you constrain your accepted types in order to enforce that they are comparable ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I need to accept bool, string, and numbers (int's and doubles).
|
|
|
|
|
They all implement IComparable , don't they? Just use the where T:IComparable constrain in your generic method. Or perhaps use IComparable<T> .
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Why do you use generics at all?
Wouldn't it just be simpler to do something like that:
public bool GetOperatorResult(string operator, bool a, bool b)
{
}
public bool GetOperatorResult(string operator, int a, int b)
{
}
and let the runtime decide which overload should be called?
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
I did think about this but I would have to create a function that does the same thing for every different type of number (int, double, long, etc....). Is there a way to get around this?
Also, I want to be able to pass in operands of type Object.
Thanks in advance.
-- modified at 11:42 Tuesday 4th September, 2007
|
|
|
|
|
How about if I created a function which takes operands of type Object and then calls other overloaded functions:
public bool getOperatorResult(string operatorType, System.Object operandA, System.Object operandB)
{
if (operandA is bool)
{
return getOperatorResult(operatorType, (bool)operandA, (bool)operandB);
}
else if (operandA is double)
{
return getOperatorResult(operatorType, (double)operandA, (double)operandB);
}
else if (operandA is int)
{
return getOperatorResult(operatorType, (int)operandA, (int)operandB);
}
else if (operandA is long)
{
return getOperatorResult(operatorType, (long)operandA, (long)operandB);
}
else if (operandA is string)
{
return getOperatorResult(operatorType, (string)operandA, (string)operandB);
}
else
{
return false;
}
}
public bool getOperatorResult(string operatorType, bool operandA, bool operandB)
{
switch (operatorType)
{
case "or":
return (operandA || operandB);
case "and":
return (operandA && operandB);
case "equal":
return (operandA == operandB);
case "notequal":
return (operandA != operandB);
default:
return false;
}
}
|
|
|
|
|
This is, at a minimum, not performant, as all your types are not objects, and would have to be boxed and unboxed.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
for boolean operators such as ^, &, |, &&, and ||, just use a simple switch. Then, if either the type of object is not bool OR if the operator is not one of the preceding, then see if the object implements icomparable. If so (which int and double both do), then return one of the following (you could even check first to see if the comparison is EQUAL or NOTEQUAL, then use .Equals which all objects expose)
public bool compare(object A, object B, comparison comp) {
IComparable ic = A as IComparable;
object other = B;
if (ic == null) {
ic = B as IComparable;
other = A;
comp = SwitchComparison(comp); // simple function that changes
// <= to >=, < to >, and vice versa
}
// check if ic is null... if so, do whatever you think is appropriate
switch (comp) {
case EQUALS:
return ic.CompareTo(other) == 0;
case NOTEQUALS:
return ic.CompareTo(other) != 0;
case GT:
return ic.CompareTo(other) > 0;
...
}
|
|
|
|
|
Anyone know how to deserialize a file, but not load the whole thing in to memory?
Sort of like using a Hashtable, jumping to a point within the file, modifying the data and then closing. Rather than, opening the whole thing up, then rewriting the whole file over and over again.
Thanks
Jeremy )
-- modified at 11:45 Tuesday 4th September, 2007
I think I may have found what I been looking for, it appears Memorystream might be what im looking for, anyone have any experience with this?
|
|
|
|
|
jblouir wrote: jumping to a point within the file, modifying the data and then closing. Rather than, opening the whole thing up, then rewriting the whole file over and over again.
Your talking about something like ISAM which is completely different than serialization.
|
|
|
|
|
Awesome, thanks for that. Looking in to it now. )
|
|
|
|
|
Hi,
I have a DLL written in C.
I would like to import it in C#(Visual Studio 2005).
How can I do that?
Thanks in advance,
|
|
|
|
|