|
Hi!
That's exactly what I needed!
Thanks!!
Lea Hayes
|
|
|
|
|
Hey all... I am working with .NET 1.1 (!) and I am trying to find a method that canonicalizes a filesystem path. Basically the .NET equivilent of the Win32 Shell API function PathCanonicalize(...) .
What I need to do is convert a path like:
C:\Program Files\Company\App\User1\Data\Res<code>\..\..\..\</code>User2\Data\Media To:
C:\Program Files\Company\App\User2\Data\Media I am sure I can write code to do it (I had to in C++ before to get around the shell functions' MAX_PATH limit), but want to know if a method exists.
Searching for "Canonicalize" in the MSDN help and in this forum does not yield anything useful.
Adva[Thanks ]nce!
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi.
Long time since 1.1.
Have you tried the DirectoryInfo object ?
DirectoryInfo di = new DirectoryInfo(@"C:\Program Files\Company\App\User1\Data\Res\..\..\..\User2\Data\Media");
Then the di.FullName would give C:\Program Files\Company\App\User2\Data\Media
Kjetil
|
|
|
|
|
I think that will do it!
Thanks!
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
This is what Path.GetPath() is there for (System.IO namespace).
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
No such method. Perhaps you meant Path.GetFullPath (...)?
I am realizing that the documentation is lacking simple terms like "Canonicalize" unless it is talking about a URL...
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Apologies, I meant GetFullPath.
Still, I don't think that deserved a 1 (not from you, obviously, but some random guy)
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
That was me... I hit the "not helpful" button thinking it was separate from the normal rating/voting buttons on the bottom right of the message.
Sorry.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Never mind
As you've probably found out, you can change your votes now with the .net version of CP.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Dear all,
I want to create a mp3 player use Windows Media Player control,but I cann't find any reference assembly in my Visual Studio 2008 ,What should I do?
Thanks very much.
|
|
|
|
|
Dear developers,
my managed C#-Code calls an unmanaged C++-Class-Method which allocates an array of integers (int *pInt = new int [5])and returns a reference to this array.
How can I use this reference in my C#-Code without copying the values in the array.
So far I didn't find any solution.
Kind regards
|
|
|
|
|
Hi,
AFAIK you can't. The only way I am aware of that avoids copying is by allocating the array
on the managed side, pass it to the unmanaged side, and let it fill it there.
The rationale is the managed metadata needs to be added to the raw data, and .NET is unable
to do that for existing data.
|
|
|
|
|
seems reasonable what you say
Thanks ! !
|
|
|
|
|
I have a generic method which looks for a specific attribute and returns value of "Text" property. My attribute is named "DetailsAttribute". Here is my generic method
public static string GetDescription<EnumType>(EnumType enumType) {
string description = string.Empty;
Type type = enumType.GetType();
if (type != null) {
FieldInfo info = type.GetField(enumType.ToString());
if (info != null) {
DetailsAttribute[] attributes = info.GetCustomAttributes(typeof(DetailsAttribute), false) as DetailsAttribute[];
if (attributes != null && attributes.Length > 0)
description = attributes[0].Text;
}
}
return description;
} This works fine. But I am looking for applying a constraint to the generic parameter "enumType" which should allow only enum types. I am not able to write something like
public static string GetDescription<EnumType>(EnumType enumType) : where enumType : enum
How can I set such kind of restriction ? Also is there any better method than what I provided to retrieve attribute values from fields ?
any help would be appreciated.
|
|
|
|
|
N a v a n e e t h wrote: How can I set such kind of restriction ?
You cant. Best will be to have where EnumType : struct and have a check inside the method.
|
|
|
|
|
Yeah, I guessed it. Thanks leppie. Do you think there is any better method to take the attribute value other than what I did ?
|
|
|
|
|
Maybe you should check it by yourself.
Just like this:
public static string GetDescription<enumtype>(EnumType enumType) {
string description = string.Empty;
Type type = enumType.GetType();
Type typParent=type.BaseType;
bool blIsEnum=false;
while(typParent!=null)
{
if(typParent==typeof(System.Enum))
{
blIsEnum=true;
break;
}
typParent=typParent.BaseType;
}
if(blIsEnum==false)
{
throw new Exception("Haha,game over!^_^");
}
......
|
|
|
|
|
Thanks.
xibeifeijian wrote: Type type = enumType.GetType();
Type typParent=type.BaseType;
bool blIsEnum=false;
while(typParent!=null)
Why not make it simple like
if (enumType.GetType() != typeof(System.Enum))
throw new InvalidOperationException("An enum is expected"); or am I missing something ?
|
|
|
|
|
Ha,Sorry,my error.
As the enum type cann't inherit,so you can judge it in this way:
if (enumType.GetType().BaseType != typeof(System.Enum))
You must use basetype to judge them,because the son type won't equals the parent type.System.Enum is a root type for all the enum types.
|
|
|
|
|
Ya.. BaseType is required. Thanks
|
|
|
|
|
How about:
enumType is Enum ...
You guys certainly like to do things the hard way!
|
|
|
|
|
leppie wrote: enumType is Enum
Looks simple, but I cannot make it working. AFAIK, BaseType checking is required. When you use is , it throws exception for enum types too.
|
|
|
|
|
N a v a n e e t h wrote: Looks simple, but I cannot make it working. AFAIK, BaseType checking is required. When you use is, it throws exception for enum types too.
Then you are doing something wrong!
The following prints 'Friday':
object f = DayOfWeek.Friday;
if (f is Enum)
{
Console.WriteLine(f);
}
else
{
Console.WriteLine("Not enum");
}
|
|
|
|
|
Does no one read my articles?
I use:
System.Type basetype = typeof(T) ;
if ( !basetype.IsEnum )
{
throw ( new System.ArgumentException ( "T must be an Enum" ) ) ;
}
I suspect that all that checking for null in your example is needless.
And please read this[^].
|
|
|
|
|
Haha ,this is the best way !
|
|
|
|