Tag: portable class library

是否可以在ASP.NET MVC项目中利用ICommand?

基本上,我正在创建一个可移植的类库,并创建一堆ViewModel: public class CustomerViewModel : ViewModelBase { public string FirstName { … } // INPC public string LastName { … } // INPC public string FullName { get { return FirstName + ” ” + LastName; } } public ICommand DoFooCommand { get; private set; } // DelegateCommand private bool CanDoFoo(object parameter) { … } […]

没有BinaryFormatter 的C#对象到byte ?

BinaryFormatter工作得很好,但在.NET 4.5的Portable类库中不存在。 我已经读过它在.NET 4.6 Portable中。 我还没有确认这一点,因为当我在项目设置中更改为4.6时,我收到一条警告消息“4.5将自动定位”,除非我取消选择Silverlight,WindowsPhone,Windows Universal,Xamarin等),所以我只能目标.NET 4.6便携式,如果我不是针对其他平台,从而打败了目的。 这是我原来的BinarySerializer(Works但不是PCL因为使用了BinaryFormatter ) private string BinarySerialize(object Source) { byte[] serializedObject; using (MemoryStream stream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, Source); serializedObject = stream.ToArray(); } return Convert.ToBase64String(serializedObject); } 那就是说,我开始尝试重新编写我的BinarySerializer以使用PCL中可用的BinaryReader和BinaryWriter ,并遇到以下问题: BinaryWriter ,只能处理简单类型(如string , bool , byte , long , int等)和Streams ,所以我认为我需要找到一种方法将匿名对象转换为Stream 。 我在正确的道路上吗? 你如何转换直到运行时才知道的类型(如System.Delegate – […]

在可移植类库中包含XPathSelectElement

如何在可移植类库中使用XPathSelectElement ? 当我尝试在项目中包含System.Xml.XPath程序集时,我收到以下错误: “System.Xml.Linq.XElement”类型在未引用的程序集中定义。 您必须添加对程序集’System.Xml.Linq,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35’的引用。 我的可移植类库已经引用了System.Xml.Linq 。

Xamarin Forms和EntityFramework属性兼容性

我有一个使用C# , WPF , ASP.NET WebAPI和Entity Framework的客户端/服务器解决方案 。 客户和服务器分支在他的项目中共享模型 。 现在我正在尝试创建一个新客户端,使用Xamarin Forms并共享模型,但entity framework属性 ( MaxLength , Index , NotMapped等) 在PCL中不兼容 。 所以这就是我尝试过的东西: 将Microsoft.EntityFrameworkCore导入PCL模型 如此处所述,您应该能够将entity framework与Xamarin表单一起使用,因此我将PCL转换为NetStandard 1.3,并且它可以工作,允许每个EntityFramework属性。 但是现在服务器项目与该标准不兼容,我无法在模型项目中添加prism和Newtonsoft.Json等软件包。 使用诱饵和开关技巧模拟Xamarin表单的属性 我已经尝试了这里描述的方法,基于在模型PCL中创建自定义属性,并在类库中重新定义它们。 MyClient.Droid和MyClient.UWP重新定义属性,将它们留空,MyServer将使用Entity Frameworkfunction重新定义它们。 自定义IndexAttribute – 模型PCL: namespace Model.Compatibility { public class IndexAttribute : Attribute { public IndexAttribute() { } } } 自定义IndexAttribute – 服务器端: [assembly: TypeForwardedToAttribute(typeof(Model.Compatibility.IndexAttribute))] namespace […]

Xamarin Studio Targeting netstandard

我正在尝试升级我的pcl库,以便在Mac上的Xamarin Studio中定位netstandard。 但我没有看到这个选择。 我发现的所有信息都只讨论使用Visual Studio。 Xamarin博客 Oren的博客 当我寻找他们在Xamarin Studio中讨论的选项时,我找不到它。

HttpClient PCL Cookie未应用于请求

我正在使用.NET HttpClient for PCL(2.2.15)来跨Windows Phone 8,Windows 8和.NET 4.5的公共库。 但是,我没有看到cookie被应用于请求。 我正在使用以下代码设置HttpClient和HttpClientHandler。 HttpClient是包装类的属性。 CookieContainer = new CookieContainer(); var handler = new HttpClientHandler { AllowAutoRedirect = true, CookieContainer = CookieContainer, Credentials = client.CredentialCache, UseCookies = true, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip }; HttpClient = new HttpClient(handler, false); 使用以下内容发送请求。 var response = await HttpClient.SendAsync(httpRequestMessage); 当我在Debug中单步执行时,我能够查看处理程序上的CookieContainer,并且能够看到我正在使用预期cookie进行反对的域的CookieContainer。 Cookie具有以下值: 路径=’/’ Domain =’。staging3.api.com’ […]

.NET可移植类库属性

我有一个公共类库,包含我的服务器和客户端的许多模型。 由于客户端在Xamarin下运行,因此公共库必须是可移植类库(PCL)。 在我的服务器中,这些对象是通过AppDomain Remoting / Marshaling传递的,所以根据我的理解,对象需要标记为[Serializable]或从MarshalByRefObjectinheritance 在PCL中,我不能对我的任何模型做任何这些事情。 我的问题是:如何使这些对象与AppDomain Remoting / Marshaling一起使用并让它们驻留在可移植类库中?

Async CTP是否可以与便携式库一起使用

我正在寻找带有便携式类库的Async CTP?

相当于PCL库中的System.Diagnostics.Trace

我很惊讶地发现System.Diagnostics.Trace未包含在可移植类库配置文件中。 虽然可以使用System.Diagnostics.Debug。 我正在将库移植到PCL,并且通常使用Trace语句为消费者提供额外的故障排除。 出于性能原因,我希望对程序集进行优化,因此我只在NuGet包中发布程序集的Release版本。 我的理解是System.Diagnostics.Debug的方法是有条件编译的,因此仅在程序集包含DEBUG指令时才有用。 如果我更改我的代码以使用System.Diagnostics.Debug然后在Release中编译该方法是没用的 – 在PCL中是否有System.Diagnostics.Trace的替代方法,或者我是否必须在我的发布版本中包含DEBUG指令? 或者我应该考虑另一种方法吗?

便携式类库reflection

我目前正在尝试将Xamarin.iOS应用程序库转换为PCL(配置文件78)。 我有这个不能编译的代码: public static void RegisterAllCommandHandlers(IEnumerable assemblies) { // Get all types that are concrete classes which implement ICommandHandler var commandHandlerOpenGenericType = typeof(ICommandHandler); var types = new List(); foreach (var assembly in assemblies) { types.AddRange(assembly.GetTypes() .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == commandHandlerOpenGenericType))); } } 这是编译器错误的图像: 如何使用新的reflectionAPI执行相同的操作?