|
Hi,
Let's have a dream. I have a class with some properties, here a sample :
public class TestClass<br />
{<br />
private int myint;<br />
private string mystring = "";<br />
<br />
public TestClass() { }<br />
<br />
[DefaultValue(100)]<br />
public int IntProp<br />
{<br />
get { return myint; }<br />
set { myint = value; }<br />
}<br />
<br />
[DefaultValue("idea")]<br />
public string StringProp<br />
{<br />
get { return mystring ; }<br />
set { mystring = value; }<br />
}<br />
}
I wonder if it is possible to set at runtime the DefaultValue for every properties. My wish is to be able to serialize theses values. So at next startup, the new defaultvalues will be used.
So what are the issues ?
- It's straightforward to enumerate the current DefaultValueAttribute of every properties.
- I think I have to use the ICustomTypeDescriptor to get a dynamic defaultValue attribute.
- I really don't know where to put the serialization and deserialization code for putting and getting back the default values. Constructor ? Desctructor ?
- Another point, by setting the DefaultValueAttribute of one propertie, will it be set for every instance of the class ?
Thanks for helping me.
---
Alexandre Jenny
|
|
|
|
|
Implement the ICustomTypeDescriptor in your class. In the implementation for GetProperties you can attach all the attributes to your <cdoe>PropertyDescriptors that you want. I use this for an object with "properties" that are allocated from a database, and I add a DefaultValueAttribute to those PropertyDescriptor s from the database as well.
If you simply want to serialize these, then you use the TypeDescriptor.GetProperties method to get the PropertyDescriptorCollection and enumerate those properties, getting the value from the DefaultValueAttribute which may be found in PropertyDescriptor.Attributes (inheritted from MemberDescriptor ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a user control that i created which contains a bunch of search varibles in the form of text boxes and drop-down lists. I include this control in the search page and a couple of others. I am trying to update the value of the textbox and drop down lists within this user control and can't. I have been able to read the values of the Controls using:
<br />
Control myKeywords = FindControl("ctl_search:tb_keywords");<br />
TextBox tb_keywords = (TextBox)myKeywords;<br />
tb_keywords.Text.ToString();<br />
But I need to update the value of those controls.
Any help you can provide would be greatly appreciated!
|
|
|
|
|
Why are you using Text.ToString ? Text already returns a string. This is a waste of CPU cycles.
If you're getting back a value (i.e., not null ) from FindControl , then just set cast to a TextBox as you're doing and set Text to some string, like tb_keywords.Text = "Some string"; .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I have to develop an Ssh client/server in c# and, enjoyed, i found that there's no c# library for .NET .
I've heard that it's possible to import classes from other language in c#, but i haven't found solution for my problem yet...
Help....
|
|
|
|
|
polkiujhy wrote:
Ssh client/server in c# and, enjoyed, i found that there's no c# library for .NET
A library to do what? The entire Secure Shell server and client? What would you be developing then?
RageInTheMachine9532
|
|
|
|
|
There's a mistake in my previous message. I wanted to say : "Ssh client/server in c# and, enjoyed, I found that there's no Ssh library for .NET"
I have to send and receive RPC messages through an ssh connection. So I have to develop first an Ssh client and server in c#, but i don't know how.
|
|
|
|
|
I haven't been able to find any classes that do Secure Shell in .NET or anything else for that matter. I have found various projects on SourceForge and other OpenSource websites. You can try this[^] Java example for code ideas.
RageInTheMachine9532
|
|
|
|
|
Why not just establish an ssh tunnel and send RPC commands to the local port, which is presumably forwarded to the remote RPC port. If the client has the ssh client install, you could simply invoke the command with the necessary parameters using the Process class.
There is one SSH client for .NET that I was able to find with a simple search on google for "SSH .NET": http://www.nsoftware.com/products/ipworksssh.aspx[^]. It's from IP*Works which, IMO, makes pretty good libraries.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am working an n-Tier application, and I have a component which is a representation of database tables (just collections of structs), I use this component as a container of data that can be sent between the tiers.
When I try to use an adding function on the server, I put the data from the client into one struct and send it as parameter to the server function but I am getting the following message
"Because of the security restrictions, the type Entities.Suppliers cannot be accessed"
as long as I try to get a list of the suppliers (returns a datatable) I have no problem.
|
|
|
|
|
Hello,
I'm fairly new to C# and I've got a syntax question. I've seen some C# syntax on the CP located above some function declorations, syntax like [sometext("more text")]. What does that mean? Where can I find documentation describing this?
An example of this syntax would be [DllImport("wininet.dll")], which I understand tells the compiler that you're importing the wininet.dll and are going to use a function in that dll.
Thanks!
|
|
|
|
|
These are called attributes. Attributes are used to further define or enhance certain metadata.
Attribute classes in .Net always end with "Attribute", although that part of the class name doesn't have to be provided when applying the attribute in code. For instance, if you wanted to look up information on DllImport in the MSDN library, you would actually look for the DllImportAttribute class.
For more information and a better starting point on attributes, try starting with this page in the MSDN library:
Introduction to Attributes[^]
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|
|
Either in the Visual Studio Help or on MSDN here[^].
You can also search for keywords on MSDN.
RageInTheMachine9532
|
|
|
|
|
Any ideas on how to go about serializing a winform using C#.
|
|
|
|
|
Easy enough. Forms aren't serializable...
RageInTheMachine9532
|
|
|
|
|
As said, the Form class isn't serializable. But it should be enough to serialize step by step the most important properties like Size and Font.
|
|
|
|
|
...or extend Form and attribute the class with [Serializable] . By default, all private and protected fields are serialized if they themselves are serializable. If you want more control on how your class is serialized, implement the ISerializable interface. More information about the SerializableAttribute class and ISerializable interface can be found in the .NET Framework SDK documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi
i have a problem accessin the arraylist i made in a form by another form as i had to make static array and when i put data in it in for loop it just saves the last data the loop put what can i do?
thanx
|
|
|
|
|
A static array exists only once. Anything you do to it will reflect elsewhere. Make it non static so that each instance has it's own array.
If you are using a form, try calling the array from a non static method. You are probably trying to read it from main.
Cata
|
|
|
|
|
thanx
but i don't need that each instance have its own array as i need the data from the array that i put in the 1rst form in the second to do changes in it then i need the changed array in the 3rd form
|
|
|
|
|
Ok, you could always use the array.clone() method, to copy it into a local array, and then apply the changes there. THEN forward the modified array.
This will keep the origional array unchanged, but enable you to manipulate a modified version.
|
|
|
|
|
You might want to post some code samples of your array and what your doing to modify it.
RageInTheMachine9532
|
|
|
|
|
((Offices)(OfficesNames[i])).OfficeAtt= new ArrayList(AllNodes);
Offices ->class
OfficesNames->array of object of offices
officeAtt->arraylist have object of another class called attributes
this line of code to intialize the arraylist of attributes of each office
for(int i=0;i
|
|
|
|
|
When you enumerate a collection or list (anything that implements IEnumerable , it is documented behavior to throw an exception. This is to ensure that changes to the list or collection aren't skipped when looping. You can either clone the list or collection or use an iterative loop (for , as opposed to foreach ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello dave,
remeber me?? today i am asking about keystrokes in every applications...i want to trace keystrokes and specify in which application were they typed..wait ur reply...give me hint in which way to search..thanks in advance
|
|
|
|