Có gì sai với mã sau? Tôi không thể thấy lý do cho lỗi được đề cập bên dưới. Tôi đang sử dụng Mono, đây có phải là một lỗi trong Mono, và nó sẽ biên dịch mà không có lỗi trong VStudio?Không chuyển đổi thông số quyền anh hoặc loại cho tham số Kiểu chung với Mono
public static class ClientFactory {
public static T CreateClient<T, I>()
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(null, null);
}
public static T CreateClient<T, I>(string endpointConfigurationName)
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(endpointConfigurationName, null);
}
public static T CreateClient<T, I>(string endpointConfigurationName, string remoteAddress)
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password);
}
public static T CreateClient<T, I>(string endpointConfigurationName, string remoteAddress, string userName, string password)
/* NO error here, this method compiles fine */
where T : ClientBase<I>, I
where I : class {
T client;
/* get client instance */
/* do stuff with it */
return client;
}
}
Tôi nhận được lỗi biên dịch:
…/ClientFactory.cs(14,14): Error CS0314: The type `T' cannot be used as type parameter `T' in the generic type or method `….ClientFactory.CreateClient(string, string)'. There is no boxing or type parameter conversion from `T' to `System.ServiceModel.ClientBase' (CS0314)
tôi sao chép mã của bạn để một dự án mới VC# 2010, thay đổi '/ * làm công cụ * /' với 'client = mặc định (T); 'và thay thế hai thiết lập bằng' "" '. Biên dịch tốt, không có lỗi trình biên dịch. – dtb
Đây có phải là lỗi trong Mono không? – knittl
Bạn đang sử dụng phiên bản 'dmcs' nào? – dtb