创建Guid - >从VB转换为C#

时间:2018-02-13 11:42:54

标签: c# vb.net guid act

我在VB.Net中有以下代码,我试图将其转换为C#。

 listContacts = ACT_FRAMEWORK.Contacts.GetContactsByID(Nothing, New Guid() {New Guid(ContactID)})

以下是我的尝试:

 Guid[] test = new Guid[1];
 test[0] = Guid.NewGuid(ContactID);   
 contactList = actApp.Contacts.GetContactsByID(null, test);

abover错误,因为NewGuid()不带参数。我也试过了。

test[0] = contactID1;

但是,您无法将字符串转换为Guid。任何人都可以帮忙吗?

2 个答案:

答案 0 :(得分:11)

@Bean是一种方法,并且您没有从VB代码中调用该方法 - 您正在调用接受字符串的构造函数。您可以在C#中调用相同的构造函数:

@Configuration
public static class AppConfig {
    @Bean
    public SystemPropertiesFactoryBean systemProperties(DataSource dataSource) {
      return new SystemPropertiesFactoryBean(dataSource);
    }

    @Bean
    public DataSource dataSource() {
      //  return new data source
    }
}

或者,如果您想根据VB代码在一行中进行调用:

//Check array.length less than 3 (4 items only in array, pops last item)
if(context.global.array.length < 4){
    context.global.array.push(msg.payload);
}else{
    context.global.array.push(msg.payload);
    context.global.array.shift();
}

msg.payload = context.global.array.toString();
msg.payload1 = context.global.array[3];
msg.payload2 = context.global.array[2];
msg.payload3 = context.global.array[1];
msg.payload4 = context.global.array[0];
return msg;

我认为Guid.NewGuid具有该名称而不是// Using an array initializer for simplicity Guid[] test = { new Guid(ContactID) }; 是一种耻辱,但这就是生命:(

使用contactList = actApp.Contacts.GetContactsByID(null, new[] { new Guid(ContactID) }); 当然也会起作用 - 根据.NET Core source code判断他们的行为非常相似;构造函数只是略微区别地处理溢出异常。

答案 1 :(得分:1)

尝试private static void IncreaseCommentFormatTypesPrioirity(IClassificationTypeRegistryService registry, IClassificationFormatMapService formatMapService, IClassificationType myType) { IClassificationFormatMap formatMap = formatMapService.GetClassificationFormatMap(category: "text"); IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.ExcludedCode, myType); IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.Comment, myType); } private static void IncreaseServiceFormatPriority(IClassificationFormatMap formatMap, IClassificationTypeRegistryService registry, string formatName, IClassificationType myType) { IClassificationType predefinedClassificationType = registry.GetClassificationType(formatName); IClassificationType artificialClassType = registry.CreateTransientClassificationType(predefinedClassificationType); TextFormattingRunProperties properties = formatMap.GetExplicitTextProperties(predefinedClassificationType); formatMap.AddExplicitTextProperties(artificialClassType, properties, myType); formatMap.SwapPriorities(artificialClassType, predefinedClassificationType); formatMap.SwapPriorities(myType, predefinedClassificationType); }

如果ContactID实际上是一个字符串,则简单写Guid.Parse(ContactID.ToString());