我知道你能做到
this.GetType().FullName
Run Code Online (Sandbox Code Playgroud)
要得到
My.Current.Class
Run Code Online (Sandbox Code Playgroud)
但是我能得到什么呢
My.Current.Class.CurrentMethod
Run Code Online (Sandbox Code Playgroud) 我目前正在编写一个系统,用于存储存储在传统图像库中的大约140,000个图像的元数据,这些图像正被移动到云存储中.我使用以下内容获取jpg数据...
System.Drawing.Image image = System.Drawing.Image.FromFile("filePath");
Run Code Online (Sandbox Code Playgroud)
我对图像处理很新,但这对于获取宽度,高度,宽高比等简单值很好,但我无法解决的是如何检索以字节为单位表示的jpg的物理文件大小.任何帮助将非常感激.
谢谢
最终解决方案包括图像的MD5哈希以供稍后比较
System.Drawing.Image image = System.Drawing.Image.FromFile(filePath);
if (image != null)
{
int width = image.Width;
int height = image.Height;
decimal aspectRatio = width > height ? decimal.divide(width, height) : decimal.divide(height, width);
int fileSize = (int)new System.IO.FileInfo(filePath).Length;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(fileSize))
{
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] imageBytes = stream.GetBuffer();
System.Security.Cryptography.MD5CryptoServiceProvider provider = new System.Security.Cryptography.MD5CryptoServiceProvider();
Byte[] hash = provider.ComputeHash(imageBytes);
System.Text.StringBuilder hashBuilder = new System.Text.StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
hashBuilder.Append(hash[i].ToString("X2")); …Run Code Online (Sandbox Code Playgroud) 我已经使用LINQPad刚刚开始,到目前为止,我喜欢它,但我所遇到的最LINQ教程SQL使用全由Visual Studio生成的持续更新等我还相当新的LINQ到SQL一个DataContext类的所以我的问题是LINQPad中的以下等价物(如果有的话)......
MyDbDataContext db = new MyDbDataContext();
...
db.SubmitChanges();
Run Code Online (Sandbox Code Playgroud) 我知道其他问题已经被问到,但到目前为止还没有提供解决方案,或者正是我的问题.
下面的类处理字符串的加密和解密,传入的密钥和向量总是相同的.
加密和解密的字符串总是数字,大多数工作但偶尔会在解密时失败(但仅在生产服务器上).我应该提到本地和生产环境都在Windows Server 2003上的IIS6中,使用该类的代码位于.ashx处理程序中.生产服务器上失败的示例是"0000232668"
错误消息是
System.Security.Cryptography.CryptographicException:填充无效,无法删除.在System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte [] inputBuffer,Int32 inputOffset,Int32 inputCount,Byte []&outputBuffer,Int32 outputOffset,PaddingMode paddingMode,Boolean fLast)
并为代码
public class Aes
{
private byte[] Key;
private byte[] Vector;
private ICryptoTransform EncryptorTransform, DecryptorTransform;
private System.Text.UTF8Encoding UTFEncoder;
public Aes(byte[] key, byte[] vector)
{
this.Key = key;
this.Vector = vector;
// our encyption method
RijndaelManaged rm = new RijndaelManaged();
rm.Padding = PaddingMode.PKCS7;
// create an encryptor and decyptor using encryption method. key and vector
EncryptorTransform = rm.CreateEncryptor(this.Key, this.Vector);
DecryptorTransform = rm.CreateDecryptor(this.Key, this.Vector);
// used to …Run Code Online (Sandbox Code Playgroud) 鉴于变量
string ids = Request.QueryString["ids"]; // "1,2,3,4,5";
Run Code Online (Sandbox Code Playgroud)
有没有办法将它转换为List而不做类似的事情
List<int> myList = new List<int>();
foreach (string id in ids.Split(','))
{
if (int.TryParse(id))
{
myList.Add(Convert.ToInt32(id));
}
}
Run Code Online (Sandbox Code Playgroud) 在使用SQL语句时,我应该始终使用完全限定的列名(tablename.columnname),即使只使用一个表,例如
SELECT table.column1, table.column2 FROM table
Run Code Online (Sandbox Code Playgroud) 我正在一个Parameters类中传递一组查询字符串参数,用于查询图像数据库.每次调用时,一些参数可以为null.所以在sql中我会建立像这样的查询
if (parameters.Value1 != null)
{
sql.Append("sql_where_clause");
}
if (parameters.Value2 != null)
{
sql.Append("sql_where_clause");
}
Run Code Online (Sandbox Code Playgroud)
我如何使用Linq做同样的事情?
我使用wcf webservice将xml输出返回给浏览器,如果DataContract的属性为null,它仍然在响应中出现
<Id i:nil="true" />
Run Code Online (Sandbox Code Playgroud)
有没有办法让它根本没有回复?
我个人对以下代码没有任何问题
if (Object foo != null && !String.IsNullOrEmpty(foo["bar"]))
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
因为我认为以下内容过于冗长
if (Object foo != null)
{
if (!String.IsNullOrEmpty(foo["bar"]))
{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果说有5个谓词并且我不得不将文本包装在编辑器中以便立即查看它们,那么我不会在这个观点上走得那么远,是否有一条逻辑"线"可以描绘出你有多少谓词在类似意义上包含在单个if语句中,表示方法永远不需要超过7个参数
我有一个类,它是代码库项目的一部分,该项目是为不再需要的特定目的而编写的.所以问题是你用这样的代码做什么?你是删除它,还是留下它,请记住未来的开发人员可能会遇到它并且没有意识到他们可以忽略它或者你是否有某种存档系统,是否存在一种公认的"模式"使用...
c# ×4
.net ×2
coding-style ×2
linq-to-sql ×2
aes ×1
cryptography ×1
encryption ×1
generics ×1
image ×1
linq ×1
linqpad ×1
refactoring ×1
sql ×1