在我们的应用程序中,我们使用具有Guid值的属性创建Xml文件.该值必须在文件升级之间保持一致.因此,即使文件中的其他内容发生更改,该属性的guid值也应保持不变.
一个显而易见的解决方案是创建一个静态字典,其中包含文件名和用于它们的Guids.然后每当我们生成文件时,我们都会在字典中查找文件名并使用相应的guid.但这不可行,因为我们可能会扩展到100个文件并且不想保留大量的guid.
所以另一种方法是根据文件的路径使Guid相同.由于我们的文件路径和应用程序目录结构是唯一的,因此Guid对于该路径应该是唯一的.因此,每次我们运行升级时,文件都会根据其路径获得相同的guid.我找到了一种很酷的方法来产生这样的' 确定性指导 '(感谢Elton Stoneman).它基本上是这样的:
private Guid GetDeterministicGuid(string input)
{
//use MD5 hash to get a 16-byte hash of the string:
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] inputBytes = Encoding.Default.GetBytes(input);
byte[] hashBytes = provider.ComputeHash(inputBytes);
//generate a guid from the hash:
Guid hashGuid = new Guid(hashBytes);
return hashGuid;
}
Run Code Online (Sandbox Code Playgroud)
所以给定一个字符串,Guid将始终是相同的.
有没有其他方法或建议的方法来做到这一点?该方法的优点或缺点是什么?
我想知道我是否可以定义自定义程序集属性.现有属性按以下方式定义:
[assembly: AssemblyTitle("MyApplication")]
[assembly: AssemblyDescription("This application is a sample application.")]
[assembly: AssemblyCopyright("Copyright © MyCompany 2009")]
Run Code Online (Sandbox Code Playgroud)
有没有办法可以做到以下几点:
[assembly: MyCustomAssemblyAttribute("Hello World! This is a custom attribute.")]
Run Code Online (Sandbox Code Playgroud) 这是我的csproj文件的片段:
<ProjectReference Include="..\program_data\program_data.csproj" Condition="'$(Configuration)'=='Debug'">
<Project>{4F9034E0-B8E3-448E-8794-CF9B9A5E7D46}</Project>
<Name>program_data</Name>
</ProjectReference>
Run Code Online (Sandbox Code Playgroud)
我想要做的是包括program_data.dll用于多个生成配置,例如发布和调试.
我尝试过以下操作
Condition="'$(Configuration)'=='Debug' || '$(Configuration)'=='Release'"
Run Code Online (Sandbox Code Playgroud)
但Visual Studio对此嗤之以鼻.
有没有办法可以做到这一点,或者我必须<ProjectReference>为每个构建配置分别?
当我想获得Android源代码时,我知道我必须使用"repo".回购是什么?为什么他们使用repo而不只是使用GIT?,并且有一个repo的GUI,使我能够暂停/恢复同步,因为每次我偶尔断开连接似乎repo从一开始就开始同步!
程序和应用程序之间有什么区别?
我试图理解这一点,在本体中形成一个概念.谁能解释一下?
语境
我们正在移植最初使用 8 位 C 编译器为 PIC 微控制器编译的 C 代码。用于防止无符号全局变量(例如,错误计数器)回滚回零的常用习惯用法如下:
if(~counter) counter++;
Run Code Online (Sandbox Code Playgroud)
这里的按位运算符将所有位取反,并且该语句仅在counter小于最大值时才为真。重要的是,无论大小如何,这都有效。
问题
我们现在的目标是使用 GCC 的 32 位 ARM 处理器。我们注意到相同的代码会产生不同的结果。据我们所知,按位补码操作返回的值与我们预期的大小不同。为了重现这一点,我们在 GCC 中编译:
uint8_t i = 0;
int sz;
sz = sizeof(i);
printf("Size of variable: %d\n", sz); // Size of variable: 1
sz = sizeof(~i);
printf("Size of result: %d\n", sz); // Size of result: 4
Run Code Online (Sandbox Code Playgroud)
在第一行输出中,我们得到了我们所期望的:i是 1 个字节。然而,按位补码i实际上是四个字节,这会导致问题,因为现在与此比较不会给出预期的结果。例如,如果在做 (wherei是一个正确初始化的uint8_t):
if(~i) i++;
Run Code Online (Sandbox Code Playgroud)
我们会看到 i“环绕”从 0xFF 回到 0x00。与以前的编译器和 8 …
我有一个MSBuild脚本编译我现有的解决方案,但我想改变的项目之一的一些性质中在编译时的解决方案,包括但不限于AssemblyProduct和AssemblyTitle.
这是我的构建脚本的片段:
<Target Name="Compile" >
<MSBuild Projects="..\MySolution.sln"
Properties="Configuration=MyReleaseConfig;Platform=x86" />
</Target>
Run Code Online (Sandbox Code Playgroud)
我有一个主要的可执行文件和几个编译的DLL.我知道MSBuild扩展包,我怀疑它可能帮助我到达我需要的地方,虽然我不知道如何继续.
我可以在构建时有选择地更改AssemblyInfo属性吗?
有没有特定的方法来初始化IList<T>?这似乎不起作用:
IList<ListItem> allFaqs = new IList<ListItem>();
// Error I get here: Cannot create an instance of the interface 'IList<ListItem>'
Run Code Online (Sandbox Code Playgroud)
ReSharper建议像这样初始化它:
IList<ListItem> allFaqs = null;
Run Code Online (Sandbox Code Playgroud)
但是当我去向此列表添加项目时,这不会导致Null引用异常吗?
或者我应该使用List<ListItem>?
谢谢!
全面披露:有一个类似的问题在这里.
有什么方法可以测试特定端口是否使用PHP打开并正确转发?具体来说,如何使用套接字连接给定端口的给定用户?
这方面的一个例子是WhatsMyIP.org/ports的"自定义端口测试"部分.
c# ×4
.net ×2
algorithm ×1
android ×1
assemblies ×1
assemblyinfo ×1
attributes ×1
c ×1
conditional ×1
csproj ×1
generics ×1
git ×1
guid ×1
include ×1
msbuild ×1
php ×1
random ×1
repository ×1
sizeof ×1
terminology ×1
uuid ×1