|
|
I think this is constant for all the document you generate...design your template by considering this...
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi all
do you know a way to amutomatic add a method to a class once this last is decorated with a C# custom attribute?
Thanks
MN
[MyAttribute("MyName")]
public class CA
{
public CA()
{}
};
CA obj = new CA();
obj.MethodDueToMyAttribute();
|
|
|
|
|
No, attributes only provide additional meta data, they can't do anything like that.
The only way to achieve that would be if the C# compiler detected the attribute and added the method when the class was compiled. Obviously, as you can't change the code for the C# compiler it's not something you can do - unless you fancy writing your own C# compiler.
I suppose you could add a pre-build event that searched through all the classes for the attribute and added the method, but as it would be running before the compiler, you would have to just to a text based search and modify the .cs file before it was compiled.
Simon
|
|
|
|
|
manustone wrote: CA obj = new CA();
obj.MethodDueToMyAttribute();
when class CA does not have a MethodDueToMyAttribute method at compile time (and there isn't a class holding an extension method for CA), this code will not compile.
Hence, you can create another DLL file with new functionality at run-time, however invoking the new stuff will take reflection code, not a simple call to a yet unknown method.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
|
egpuyos wrote: Dictionary myDictionary = new Dictionary();
Does this even compiles?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
sorry it was
Dictionary<byte[], string> myDictionary = new Dictionary<byte[], string>();
|
|
|
|
|
What do you think the output of:
string test = "test";
byte[] b1 = Encoding.Default.GetBytes(test);
byte[] b2 = Encoding.Default.GetBytes(test);
Console.WriteLine(b1 == b2); It will be false as arrays are reference type and compared with reference equality. This is the reason why your code fails. BTW, what is wrong in keeping the string itself rather than the bytes?
|
|
|
|
|
Actually Sir, it was just my sample code, the real code I have is this.
I don't understand why that the dictionary when I call the method Exists, it will return false while it already contain the key that I passed? How could it happen?
Thank you again with you're help Sir.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private static Dictionary<byte[], string> m_MyDictionary = null;
private static System.Text.ASCIIEncoding m_MyEncoding = new ASCIIEncoding();
static void Main(string[] args)
{
m_MyDictionary = new Dictionary<byte[], string>();
AddDataToDictionary();
Console.Write(Exists(m_MyEncoding.GetBytes("test 003")));
Console.Read();
}
private static void AddDataToDictionary()
{
string s;
byte[] myByte;
s = "test 001";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 002";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 003";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 004";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 0021537912";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 327487";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
}
private static bool Exists(byte[] key)
{
return m_MyDictionary.ContainsKey(key);
}
}
}
|
|
|
|
|
Dictionary.ContainsKey checks for value on value types, for reference on ref types.
As N a v a n e e t h said, two arrays with identical type, size and content are considered different, they are two distinct objects with different references.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
This is the whole code Sir, thank you with the help
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Dictionary<byte[], string> myDictionary = new Dictionary<byte[], string>();
System.Text.ASCIIEncoding myEncoding = new ASCIIEncoding();
string s;
byte[] myByte;
s = "test 001";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 002";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 003";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 004";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 0021537912";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 327487";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
string theString = "test 004";
byte[] find = myEncoding.GetBytes(theString);
if (myDictionary.ContainsKey(find))
{
Console.Write(find);
}
else
{
Console.Write("key not found.");
}
Console.Read();
}
}
}
|
|
|
|
|
hi,
you use the byte array as key instead of the string you are adding as value ?!?
why you don't add the string as key and the byte array as value. in your code above i see that would make no difference to the functionality and i think that would be the better way.
greetz
|
|
|
|
|
hey all,
i want to create a window service which send mail automatically at a given interval or any other condition.service should start with system boot n stop with system shutdown . i am not familiar with window services. thanks in advance for ur help n rplies.
|
|
|
|
|
Hi,
have a look here:
Simple Windows Service Sample[^]
It is a little bit old (e.g. using VS 2003), but the idea behind the article is still actual.
Regards
Sebastian
|
|
|
|
|
thanks Sebastian
actually i want to create a service which sends mails at the interval of 15 days. thanks for ur response
|
|
|
|
|
Hi,
How to get the menu like Cut,Copy,Paste,SelectAll in richTextBox.
Any idea?
Thanks,
Subbu
|
|
|
|
|
Combine the RichTextBox with a ContextMenu control, and do the methods of Cut, Copy, etc. in ContextMenu control?
|
|
|
|
|
Thanks for your prompt reply.
Here my question suppose If I am having two RichTextBox and Shall I want to create two ContextMenu Control or I can use One and refer two Rich textbox. Please explain.
|
|
|
|
|
As d@nish said below, that is 100% possible. You just have to set the ContextMenuStrip Property for those two of your RichTextBoxes, enjoying the coding time.
|
|
|
|
|
There is a ContextMenu property for a RichTextBox. You can use that to add a context menu with whatever items you like.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I used SMO to manage SQL server 2005.
I want to modify a column to be same with other column.
I used the following code but it has error while calling Column.Alter() function.
<code>
public void RepairColumns(object dcolumn)
{
try
{
Column d_Column = (Column)dcolumn;
Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex];
l_Column.Initialize(true);
l_Column.Collation = d_Column.Collation;
l_Column.Computed = d_Column.Computed;
l_Column.ComputedText = d_Column.ComputedText;
l_Column.DataType = d_Column.DataType;
l_Column.Default = d_Column.Default;
l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name;
l_Column.IdentityIncrement = d_Column.IdentityIncrement;
l_Column.IdentitySeed = d_Column.IdentitySeed;
l_Column.NotForReplication = d_Column.NotForReplication;
l_Column.Nullable = d_Column.Nullable;
l_Column.RowGuidCol = d_Column.RowGuidCol;
l_Column.Rule = d_Column.Rule;
l_Column.RuleSchema = d_Column.RuleSchema;
l_Column.IsPersisted = d_Column.IsPersisted;
l_Column.DefaultSchema = d_Column.DefaultSchema;
l_Column.Alter();
}
catch (SmoException ex)
{
throw ex;
}
}
</code>
If u knows my mistakes, pls point me.
Thanks
|
|
|
|
|
Hi,
could you post the error message? This would help us to understand the problem a bit better.
Regards
Sebastian
|
|
|
|
|
I use adventurework database.
Error is
FailedOperationException - "Alter failed for Column 'SystemInformationID'."
InnerExcetpion - "Modifying the Computed property of the Column object is not allowed. You must drop and recreate the object with the desired property."
|
|
|
|
|
Setting the computed property does only work if you drop and add the column. (As the error message is saying):
http://www.windows-tech.info/15/83beeb9f84f9b78a.php[^]
Do you need to change the computed value of the column? If not, just leave the line
l_Column.Computed = d_Column.Computed;
out.
|
|
|
|