Tag: portable class library

SQLite net PCL – 简单选择

我在Windows应用程序中使用SQLite,现在我在Xamarin开发一个便携式应用程序,所以我使用插件sqlite net pcl,我很难理解它是如何工作的。 我有一个由以下te创建的表: public class Config { public string IP { get; set; } [SQLite.Net.Attributes.Default(true, “Client 2”)] public string ID { get; set; } } 并创建表: db.CreateTable(); 问题:现在我想在ID列中选择值,然后执行以下操作: List hhid = db.Query(“select ID from Config”,null); 我得到这个例外: “Object reference not set to an instance of an object” 如何进行简单的选择以找到此字段? 谢谢你的提示

C#编译器如何决定发出可重定向的程序集引用?

.NET Compact Framework引入了可重定向的程序集引用,现在用于支持可移植类库。 基本上,编译器会发出以下MSIL: .assembly extern retargetable mscorlib { .publickeytoken = (7C EC 85 D7 BE A7 79 8E ) .ver 2:0:5:0 } C#编译器如何理解它必须发出一个可重定向的引用,以及如何强制C#编译器甚至在可移植类库之外发出这样的引用?

可移植类库中的Thread.Sleep()

MSDN文档说Thread.Sleep()可以在可移植类库中使用。 编译器另有说法。 除旋转循环外,我还有什么选择? Thread.CurrentThread.Join()也不存在。 项目文件: Debug AnyCPU {C46B138E-CC30-4397-B326-8DD019E3874B} Library Properties x0xtest.AVR x0xtest.AVR v4.0 Profile3 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} true full false bin\Debug\ DEBUG;TRACE prompt 4 pdbonly true bin\Release\ TRACE prompt 4 {F78547AC-1CA1-4ADB-9FA8-3E7DEB682240} x0xtest.Comm <!– To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see […]

HttpUtility.ParseQueryString的可移植类库(PCL)版本

是否有System.Web中包含的HttpUtility.ParseQueryString的可移植类库(PCL)版本或我可以使用的一些代码? 我想读一个非常复杂的URL。

在可移植类库中实现自定义exception

在为.NET设计自定义exception时,MSDN提供了这些指南 。 特别是,指南声明了一个自定义exception: 应该是可序列化的,即实现ISerializable并使用[Serializable]属性进行修饰,并且 应该实现(de)序列化构造函数,即protected CustomException(SerializationInfo info, StreamingContext context) 。 但是,在可移植类库中,不支持SerializableAttribute , ISerializable和SerializationInfo 。 我应该如何在同时针对.NET Framework和一个或多个平台的可移植类库中充分设计自定义exception?

便携式类库(PCL)贡献 – 密码学

我想在codeplex上的Portable Class Library Contrib项目中使用加密,但是没有找到关于如何使用它的任何文档。 我想在其中创建一个包含Encrypt和Decrypt方法的包装类,我希望这个包装类存在于一个可移植的类库中。 我在这个项目中引用了Portable.Runtime和Portable.Security.Cryptography 。 它是否正确? 然后我想在.NET,Windows Phone和Metro项目中使用我的包装器。 在这些项目中,我引用了我的包装器项目, Portable.Runtime , Portable.Security.Cryptography和相应的Portable项目,即Portable.Desktop , Portable.Phone或Portable.WindowsStore 。 它是否正确? 但是当我尝试使用我的包装器类时,我遇到了冲突的命名空间错误。 这是错误和我的包装类: System.Security.Cryptography.AesManaged类型存在于C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll和C:\Downloads\PclContrib\bin\Debug\Portable.Security.Cryptography.dll public sealed class SymmetricCryptography where T : SymmetricAlgorithm, new() { private readonly T provider = new T(); private readonly UTF8Encoding utf8 = new UTF8Encoding(); private byte[] key; private byte[] iv; public […]

如何使用HttpClient将带有JSON的DELETE发送到REST API

我必须使用HttpClient类向具有JSON内容的REST API服务发送删除命令,并且无法使其正常工作。 API调用: DELETE /xxx/current { “authentication_token”: “” } 因为我无法在下面的语句中添加任何内容: HttpResponseMessage response = client.DeleteAsync(requestUri).Result; 我知道如何使用RestSharp来完成这项工作: var request = new RestRequest { Resource = “/xxx/current”, Method = Method.DELETE, RequestFormat = DataFormat.Json }; var jsonPayload = JsonConvert.SerializeObject(cancelDto, Formatting.Indented); request.Parameters.Clear(); request.AddHeader(“Content-type”, “application/json”); request.AddHeader (“Accept”, “application/json”); request.AddParameter (“application/json”, jsonPayload, ParameterType.RequestBody); var response = await client.ExecuteTaskAsync (request); 但我没有RestSharp就完成了。

使用xamarin进行移动跨平台本地化,仅限iOS使用

我在Xamarin有一个针对Android,iOS和Windows手机的项目。 我用核心(PCL库)在不同平台之间共享公共代码。 我在我的核心库中添加了资源文件(.net资源).Resx,并在我的一个ViewModel中读取了我在代码片段后面使用的特定于文化的字符串: public string GetString() { // CommonResources is the name of my resource file ResourceManager resManager = new ResourceManager(typeof(CommonResources)); return resManager.GetString(“LoginLabel”,CultureInfo.CurrentCulture); } “LoginLabel”是我的资源键,其值为“登录”(英文)和荷兰语中的“inloggen”。 我在我的PCL项目中为英语和荷兰语创建了两个资源文件CommonResources。 CommonResources.resx CommonResources.nl-NL.resx 在android,iOS和windows手机中,我将文化设置如下: Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(“nl-NL”); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(“nl-NL”); 这适用于Android和Windows手机。 但对iOS来说它不起作用。 它总是从英文文件返回资源字符串。 文化已正确设置,并以调试模式显示。 但不知何故,它无法从荷兰资源加载资源字符串。 所以问题是,可以使用PCL为所有平台本地化字符串(.Net方式)吗? 有谁有任何想法? 提前致谢。

Xamarin表单:带圆角的StackLayout

我正在使用xamarin表单pcl开发一个应用程序。 我需要一个带圆角的stacklayout。 我也尝试了圆角容器的框架,但没有可用的角半径属性。 我找不到ios,android,uwp,windows 8.1的渲染器。 任何人都可以建议我如何实现所有平台的圆角以及角半径属性的stacklayout。

便携式项目上是否有AppDomain.GetAssemblies的替代方案?

我试图获得程序集列表。 但我在portable UWP项目中面临例外。 以下代码适用于 .netframework Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); Xamarin portable var currentdomain = typeof(string).GetTypeInfo().Assembly.GetType(“System.AppDomain”).GetRuntimeProperty(“CurrentDomain”).GetMethod.Invoke(null, new object[] { }); var getassemblies = currentdomain.GetType().GetRuntimeMethod(“GetAssemblies”, new Type[] { }); var assemblies = getassemblies.Invoke(currentdomain, new object[] { }) as Assembly[]; 但是相同的上述代码在UWP portable不起作用。 (我认为便携式设备也在UWP中工作) 我在点击第一行时遇到以下问题 ‘typeof(string).GetTypeInfo()。Assembly.GetType(“System.AppDomain”)。GetRuntimeProperty(“CurrentDomain”)。GetMethod.Invoke(null,new object [] {})’引发了类型’System’的exception。出现InvalidOperationException” 数据:{System.Collections.ListDictionaryInternal} HResult:-2146233079 HelpLink:null InnerException:null消息:“API’System.AppDomain.get_CurrentDomain()’不能在当前平台上使用。请参阅http://go.microsoft。 com / fwlink /?LinkId = 248273获取更多信息。“ […]