English 中文(简体)
将物体移至系统指南
原标题:Convert an object to System Guid
  • 时间:2010-09-27 16:52:13
  •  标签:
  • c#
Guid mainfolderid = (main.GetValue(""));

<代码>main是一个动态实体。

如何将上述<代码>main.GetValue (")改为System.Guid?

错误说:

不得含蓄地将物体转换为系统。 准则。

最佳回答

。 缩略语 如果是的话,那么你就迫切需要做这样的明确表述:

Guid mainfolderid = (Guid)main.GetValue("");

如果没有,<代码>GetValue,可向其中一名施工人(即<代码>byte[>或string)发送的物品? 在这种情况下,你可以这样做:

Guid mainfolderid = new Guid(main.GetValue(""));

如果上述两种情况都不适用,那么你就重新需要做一些手工工作,以转换由<代码>GetValue退回到<>>。

问题回答

如果您重新使用4.0.Net,则在指南中添加了包装方法:

Guid Guid.Parse(string input)

以及

bool Guid.TryParse(string input, out Guid result)

你们想要做的事情。

Guid mainfolderid = new Guid(main.GetValue("").ToString());

一种办法是使用GUID建筑商,并通过该建筑工程师协会的严格代表。 如果该物体确实是古董会的有力代表,这将发挥作用。 例:

Guid mainfolderid = new Guid(main.GetValue("").ToString());
Guid mainfolderid = (Guid)(main.GetValue(""));

采用喷气式喷气式喷气机的方法:

GuidAttribute   guidAttr;
object[]        arrAttrs;
Type            type;
string          strGuid;

type = main.GetType();
arrAttrs = type.Assembly.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
guidAttr = (arrAttrs != null && arrAttrs.Length > 0) ? arrAttrs[0] as GuidAttribute: null;
if (guidAttr != null) {
    strGuid = "{" + guidAttr.Value.ToUpper() + "}";
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...