|
Have anyone used ngen.exe to generate native images of an assembly? I need to know if it has real utility...
Any sample will be welcome. Thanks in advance.
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
Yes, I've done it before. It can speed up cold boots of your app significantly and warm boots somewhat. You can read more articles about it on MSDN. Here's one[^] for you.
|
|
|
|
|
How can I get the collection of field values from the below class.
So consider this instance of SentRecord
SentRecord sr=new SentRecord(1,new Subscriber(), DataTime.Now, false, "C:\img.jpg", 0);
Now how can I get all fields and values from sr. e.g.:
SentRecordID => 1
ContentCampaign => [ContentCampaign object]
Subscriber => [Subscriber object]
TimeSent => [DateTime object]
Confirmed => false
FileSent => "C:\img.jpg"
AdIDDelivered => 0
public class SentRecord : Model
{
public SentRecord(int contentID, Subscriber subscriber, DateTime timeSent, bool confirmed, string fileSent, int adIDDelivered)
{
this.ContentCampaign.ContentID = contentID;
this.Subscriber = subscriber;
this.TimeSent = timeSent;
this.Confirmed = confirmed;
this.FileSent = fileSent;
this.AdIDDelivered = adIDDelivered;
}
public int SentRecordID;
public ContentCampaign ContentCampaign;
public Subscriber Subscriber;
public DateTime TimeSent;
public bool Confirmed;
public string FileSent;
public int AdIDDelivered;
}
/\ |_ E X E GG
|
|
|
|
|
Look for these classes in MSDN.
1. System.Type
2. System.Reflection.FieldInfo.
Call GetField() method of your type and GetValue() method of FieldInfo of your members.
Farhan Noor Qureshi
|
|
|
|
|
I'm having trouble using GetValue()
Type t = this.MetaClass.modelObject.GetType();
this.MetaClass.TableName = t.FullName.Substring(t.FullName.LastIndexOf(".")+1);
FieldInfo []fields=t.GetFields();
this.MetaClass.fields =new string[fields.Length];
this.MetaClass.values = new string[fields.Length];
for (int i = 0; i < fields.Length; i++)
{
this.MetaClass.fields[i] = fields[i].Name;
}
I'm able to get all the field names, but I can't get the values of the fields. See the commented line.
Any ideas?
/\ |_ E X E GG
|
|
|
|
|
Hi
Try the following example that iterate over all the fields of an object and print the field name and value
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Test
{
public class CustomizeField
{
public CustomizeField(int x, int y)
{
m_x = x;
m_y = y;
}
public int m_x;
public int m_y;
public override string ToString()
{
return string.Format("X:{0}, Y:{1}", m_x, m_y);
}
};
public class SentRecord
{
public SentRecord(
DateTime timeSent,
bool confirmed,
string fileSent,
int adIDDelivered)
{
this.customizeField = new CustomizeField(10, 15);
this.TimeSent = timeSent;
this.Confirmed = confirmed;
this.FileSent = fileSent;
this.AdIDDelivered = adIDDelivered;
}
public CustomizeField customizeField;
public DateTime TimeSent;
public bool Confirmed;
public string FileSent;
public int AdIDDelivered;
}
class Program
{
static void Main(string[] args)
{
SentRecord sr = new SentRecord(DateTime.Now, true, @"c:\image.jpg", 10);
FieldInfo[] fields = sr.GetType().GetFields();
foreach (FieldInfo fi in fields)
{
Console.WriteLine(fi.Name + " " + fi.GetValue(sr).ToString());
}
}
}
}
|
|
|
|
|
Hi, how come GetFields doesn't pick up any public properties?
/\ |_ E X E GG
|
|
|
|
|
Hi All,
I am working on an application in which there is a toolstrip containing two ToolStripSplitButton. If I click on the button the drop-down comes down and when re-click duration is more than .5 seconds approx then re-click doesnot closes the drop-down. Also in another toolstrip when one button is checked taking mouse over to another button makes the MouseOver bordering and Tooltip fliker.
If anyone is having any idea please let me know. Thanks.
|
|
|
|
|
Have you looked at any of the C# graphing libraries out there? They generate 3d-like shapes using GDI/System.Drawing. Some of them are open source. I believe this site has some articles on graphing and charting as well.
p.s. next time use <pre> tags around your code. It preserves formatting and is easier to read.
|
|
|
|
|
I want a bidirectional way for cryptography in c#.
(not like MD5 unidirectional!)
|
|
|
|
|
MD5 is not an encryption method, it's a hashing method. Any encryption method is bidirectional.
You find the encryption methods in the System.Security.Cryptography namespace.
---
single minded; short sighted; long gone;
|
|
|
|
|
could you say the Methods?
|
|
|
|
|
DES, DSA, RC2, Rijndael, RSA, TripleDES
---
single minded; short sighted; long gone;
|
|
|
|
|
MSDN has several good samples. Here is one.
using System;
using System.Security.Cryptography;
using System.Text;
class RSACSPSample
{
static void Main()
{
try
{
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false);
decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false);
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(ArgumentNullException)
{
Console.WriteLine("Encryption failed.");
}
}
static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
try
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(RSAKeyInfo);
return RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding)
{
try
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(RSAKeyInfo);
return RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
}
catch(CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
}
Farhan Noor Qureshi
|
|
|
|
|
i have added control at runtime in .aspx page using c#. the dyamic controls are textbox and literal controls. as per the design issue i have added all thes controls in a html table in which i have added dynamic rows as per requirement. so table > dyamic row>panel>table with the controls.
so now i cant find the controls as the dynamic child level is three...
Please help me out...
Thanx..
Jayesh Talsaniya
|
|
|
|
|
Why would you have to find the controls? Just keep the references from when you create the controls.
---
single minded; short sighted; long gone;
|
|
|
|
|
When you create a control dynamically, assign it a unique name. Now when you need to refer to them you can call something like this:
FindControl("<your unique control name level 1>").FindControl("<your unique control name level 2>").FindControl("<your unique control name level 3>")
Farhan Noor Qureshi
|
|
|
|
|
Q #1:
I have two buttons to zoom in and zoom out the text size of a RichTextBox. Is it possible to increment/decrement the ZoomFactor by 0.1F each time?
Q #2:
Does changing the ZoomFactor also change the font size when you save the file as .rtf?
Thanks,
Mark
|
|
|
|
|
Hi,
Q1.
from reading the documentation it is not completely clear, so an experiment may be in order.
It says it accepts numbers from 1/64 to 64
That could mean all fractions 1/n and all integers n with 1 <= n <= 64
Q2.
I doubt that very much; normally "zoom" indicates a visualization property, not a
content property. Try it !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the tips. I will have to make a small test form and see what happens.
Mark
|
|
|
|
|
Yes it is Possible
No it does not any effect on the saved File
|
|
|
|
|
Is there a way to have the text expand to the left (locking the right) of a label?
|
|
|
|
|
Sure, give it the Width you want, turn AutoSize off, and set TextAlign to one
of the Right values.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
If you haven't seen the Django web app framework, it's pretty cool.
All DB access code is generated dynamicly -- all you have to do is define the table structures you want. I.E. (python code)
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Which Django would evaluate to:
CREATE TABLE myapp_person (
"id" serial NOT NULL PRIMARY KEY,
"first_name" varchar(30) NOT NULL,
"last_name" varchar(30) NOT NULL
);
To create a new row in the person table, just create a new instance of Person and call save()
p = Person(first_name='Alex', last_name='Egg')
p.save()
To get all the rows/fields from the Person table just call the static method all Persons.objects.all()
It all seems so elegant, so I wanted to try and recreate this using C#.
So I created a class called Model which is a DB Model like the person class above. I also created a Manager class which exposes the static method All to read data.
public class Model
{
public Model()
{
new NotImplementedException();
}
public static Manager Objects;
public void Save()
{
}
public void Delete()
{
}
}
public class Manager
{
public Manager()
{
}
public void Get()
{
new NotImplementedException();
}
public void All()
{
new NotImplementedException();
}
}
So now I will create my Person object in C#:
public class SentRecord : Model
{
public Person(string firstName, string lastName)
{
this.FirstName= firstName;
this.LastName = lastName;
}
public string FirstName;
public string LastName;
}
I figure this this is pretty much the same idea as the python Person class at the top.
Now I create a new instance of my Person model:
Person p=new Person("Alex","Egg");
Now I can save it to the DB by calling:
p.Save();
Now, my question is, how do I go about implementing Model.Save()? I somehow need to get the names of deriving class' public fields. Reflection? So If I just get the table name (I'll hardcode for now) and the People's fields I can generate my SQL insert statement.
Any pointers on how to implement Save()?
/\ |_ E X E GG
|
|
|
|