|
but it's really using reflection.~
|
|
|
|
|
|
The following IL code is retrieved by ILDasm:
class with SerializableAttribute:
<br />
.class public auto ansi serializable beforefieldinit ClassLibrary2.Class1<br />
extends [mscorlib]System.Object<br />
{<br />
}
method with ObsoleteAttribute:
<br />
.method public hidebysig instance void s() cil managed<br />
{<br />
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 ) <br />
.maxstack 8<br />
IL_0000: nop<br />
IL_0001: ret<br />
}
|
|
|
|
|
Thanks natsuyaki,
1.
It is great! Are there any tool for us to use to retrieve readable meta data and attribute information without using ILDasm tool?
2.
Generally speaking, from what pattern, could you identify a part of code in IL is dealing with attribute -- like the following code,
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 )
regards,
George
|
|
|
|
|
1.
i don't really know, maybe the tool you mentioned can.
2.
I wrote a custom attribute PuginAttribute. All the plugins must add this attribute. So, I can get it at runtime by GetCustomAttribute(), if exists, that mean this is a plugin.
<br />
[Plugin(true)]<br />
public class SamplePlugin:IPlugin<br />
{<br />
.....<br />
....<br />
IL code would be displayed like this:
<br />
.custom instance void [XXXX]aaa.bbb.ccc.PluginAttribute::.ctor(bool) = ( 01 00 00 00 )<br />
|
|
|
|
|
Thanks natsuyaki,
1.
Looks like attribute will be treated as a private class in IL?
2.
I think not all built-in attributes will be left in final IL, what kinds of built-in attributes will be in final IL, could you list some please?
regards,
George
|
|
|
|
|
1.some like that
2.some attributes reprent for "mark",and some for "deal". That means, some attributes are use for comment the content, some for the compiler that the content will be processed by the mean mentioned in the attributes. So, some keep there and some disappeared.
This is my point of view. For the precise definition, please view msdn.
|
|
|
|
|
Thanks natsuyaki,
I agree with your points. Could you list some of the attribute names which do not disappear in IL please? Sorry, my knowledge of attribute is limited.
regards,
George
|
|
|
|
|
That's a big work to do....
You may be interested in this book: Applied .Net Attributes by Jason Bock
Sorry, here we go.
And this could also help:http://www.codeproject.com/KB/cs/attributes.aspx
modified on Monday, May 12, 2008 4:30 AM
|
|
|
|
|
Thanks natsuyaki,
The link you provided can not be opened, could you double check please?
regards,
George
|
|
|
|
|
byte[] CryptographicKey = Convert.FromBase64String(txtCK.Text);<br />
byte[] IVector = new byte[16];
Array.Copy(CryptographicKey, IVector, 16);
<br />
RijndaelManaged AES256 = new RijndaelManaged();<br />
AES256.KeySize = 256;<br />
AES256.Mode = CipherMode.CBC;<br />
ICryptoTransform Encryptor = AES256.CreateEncryptor(CryptographicKey, IVector);<br />
<br />
Ciphertext = new FileStream(txtOutputPath.Text, FileMode.Create, FileAccess.Write, FileShare.None);<br />
CryptoStream CStreamWriter = new CryptoStream(Ciphertext, Encryptor, CryptoStreamMode.Write);<br />
<br />
CStreamWriter.Write(Plaintext, 0, Plaintext.Length);
CStreamWriter.FlushFinalBlock();<br />
<br />
Ciphertext.Close();<br />
CStreamWriter.Close();
CStreamWriter.Write(Plaintext, 0, Plaintext.Length); //OUT OF MEMORY EXCEPTION HERE
The code works fine for files smaller than 150mb, but when I tried to encrypt a 300mb file. I got that exception. I have 3gb of ram and when I started the encryption, my usage is only at 30%.
What seems to be the problem?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Allocating a memory block of 300M at a time is not a good idea...
Try to split the file into smaller pieces and then encrypt.
|
|
|
|
|
Will the output still be the same?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Yes, if each piece is encrypted with the same key and IV.
And remember to use the same size to decrypt.
Sample:
<br />
FileStream fs = new FileStream(f, FileMode.Open);<br />
byte[] data=new byte[1024];<br />
while (true)<br />
{<br />
int i = fs.Read(data, 0, 1024);<br />
if (i <= 0)<br />
break;<br />
else<br />
{<br />
CStreamWriter.Write(data, 0, 1024);
CStreamWriter.FlushFinalBlock();<br />
}<br />
}<br />
modified on Sunday, May 11, 2008 7:19 AM
|
|
|
|
|
Thanks! I'll give it a try.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
If i have any number like : 1234
and i want to do 1+2+3+4 = 10
What should i do? and what method should i use ?
-Thanks
Peter
|
|
|
|
|
string number="1234";<br />
int total=0;<br />
<br />
for(int i=0;i<number.length;i++)><br />
{<br />
total+=Int32.Parse(number);<br />
}</number.length;i++)>
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Thanks
i think this is really tricky..any other way you can solve this ?
Peter
|
|
|
|
|
How is it "tricky"?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Here is a method that can work, should in theory also be able to add numbers in string with chars.
<code>
string s = "1234";
int total = 0;
foreach (char c in s)
{
int x;
int.TryParse(c.ToString(), out x);
total += x;
}
</code>
|
|
|
|
|
..and the shortest one:
<br />
string s = "1234";<br />
int total = s.ToCharArray().Sum((x) => int.Parse(x.ToString()));<br />
|
|
|
|
|
Naaah
int total = s.ToCharArray().Sum((x) => ((int)x)-48);
(ok ok , it is more of a hack )
|
|
|
|
|
But you can still leave out the brackets around x :P
|
|
|
|
|
You should use the modulus or remainder function and integer division to solve this problem. Using a divisor of 10 you extract one decimal digit at a time from the number. The same technique with a divisor of 16 can be used to extract hexdecimal digits.
Int32 num = 123456789;
Int32 sum = 0;
Int32 temp = num;
while (temp > 0) {
sum += temp % 10;
temp = temp / 10;
}
Console.WriteLine("Sum of all digits in {0} is {1}", num, sum);
AlanN
|
|
|
|
|
Hi! Me and some people have formed a small development team called Condemned Entertainment for making games but we ran into a snag. We have no people who know C# and the engine we are using uses C# wondering if we can get some help if someone can help set us up. my name is Midias on the forums and our leader is Craka_J the forums is: http://www.condemnedentertainment.webs.com/index.html thanks.
|
|
|
|