Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

StealthyMark

@StealthyMark
About
Posts
17
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Conditional Property Setters (friends in C#)
    S StealthyMark

    If you are using binary serialization, the visibility of the property doesn't matter, because the serializer uses the (private) fields. Xml serialization is different. You could use the OnDeserialized attribute to execute a method whoch sets a boolean flag. In the setter, check the flag and throw an exception.

    C# csharp c++ json tutorial question

  • BSTR to c# string
    S StealthyMark

    You have to decorate these strings in your .net interop interface/class/struct with a MarshalAs(UnmanagedType.BStr) attribute.

    C# csharp com question

  • Persistent states for GUI
    S StealthyMark

    VS2005 does. It saves initial values for just about any aspect of a component (control) in a app.config file, and stores user-specific and machine-specific settings in the application data directory in the appropriate profile directory. You can read, write and save settings anywhere in your application. Mark

    C# csharp question

  • Interop question C#
    S StealthyMark

    Do you have any documentation? The first parameter unsigned char *Stamp might be 1. a pointer to a simple value, possibly taken from an enumeration ref char stamp ref short stamp [MarshalAs(UnmanagedType.U2)] ref YourEnumType stamp 2. a [In] null-terminated unicode string [MarshalAs(UnmanagedType.LPWStr)] string stamp 3. a [Out/maybe In] null-terminated unicode string [MarshalAs(UnmanagedType.LPWStr)] StringBuilder stamp 4. a [In] data array, its length is given in parameter nMaxLength [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] char[] stamp 5. a [Out] data array, its length is the return value of the function IntPtr stamp This goes for the second parameter as well, except for the last two possibilities, one is an [Out] parameter, the other one is an [In] parameter. Without some documentation it is very hard to tell. Mark

    C# csharp com tutorial question

  • how to encode string in serialization
    S StealthyMark

    I'm assuming you want to serialize your class with the XmlSerializer. The simplest trick is to mark your cleartext Password field/property with XMLIgnore and add another property providing an encrypted password.

    using System;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using System.Security.Cryptography;

    [Serializable]
    public class UserData
    {
    [XmlIgnore]
    public string Password;

    \[XmlElement("Password", DataType = "base64Binary")\]
    \[EditorBrowsable(EditorBrowsableState.Never)\]
    public byte\[\] EncryptedPassword
    {
        get
        {
            // use the classes in the System.Cryptography
            // namespace to return the encrypted password
            return YourEncryptMethod(Password);
        }
        set
        {
            // use the classes in the System.Cryptography
            // namespace to decrypt the encrypted password
            Password = YourDecryptMethod(value);
        }
    }
    

    }

    Another possibility is to implement the IXmlSerializable interface and serialize your class manually. HTH, Mark

    C# json tutorial question

  • Customizing .NET Collection Editor
    S StealthyMark

    heavenamour wrote: I Wrote a calendar class that have a collection of holidays as an ArrayList. This collection is a property of my custom control that I want Add some objects of Holiday class to it at design time. You have to do three things: 1. Use a strongly typed Collection, derived from CollectionBase instead of an ArrayList or Array. This allows the CollectionEditor to work properly. 2. Create a custom TypeConverter for Holiday, which is capable of converting a Holiday instance to an InstanceDescriptor. This allows the code generator to generate code to instantiate Holiday objects. 3. Decorate the collection property of your custom control with the DesignerSerializationVisibility attribute. This tells the code generator to serialize the contents of your collection, rather than the collection itself. To illustrate these points:

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Globalization;
    using System.ComponentModel.Design.Serialization;
    using System.Reflection;

    namespace Holidays
    {
    public class YourControl
    {
    private readonly HolidayCollection holidays = new HolidayCollection();

        // This attribute tells the code generator to serialize the contained items
        \[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)\]
        public HolidayCollection Holidays
        {
            get { return holidays; }
        }
    }
    
    
    // The strongly typed collection
    // Never expose an ArrayList or an Array as a public property!
    public class HolidayCollection : CollectionBase
    {
        public int Add(Holiday item)
        { return List.Add(item); }
    
        public Holiday this\[int index\]
        {
            get { return (Holiday)List\[index\]; }
            set { List\[index\] = value; }
        }
    }
    
    
    // assign the converter
    \[TypeConverter(typeof(HolidayConverter))\]
    public class Holiday
    {
        public Holiday()
        {
            this.month = -1;
            this.day = -1;
            this.reason = null;
        }
        
        public Holiday(int month, int day, string reason)
        {
            // add validation logic here
            this.month = month;
            this.day = day;
            this.reason = reason;
        }
    
        private int month;
        private int day;
        private string reason;
    
        public int Mo
    
    C# csharp design help tutorial

  • reading a file
    S StealthyMark

    cmarmr wrote: i would love to know how that programmer did it One word: Reflector[^].

    C#

  • Control handles via drag event ?
    S StealthyMark

    Start with looking up the documentation for Control.DoDragDrop(). The complicated part is detecting the start of a Drag-Drop-Operation; you probably already have that. OTOH, the simple part is providing string data for the operation.

    private void sourceControl_MouseMove(object sender, MouseEventArgs e)
    {
    /*
    code to detect dragging
    ...
    */

    // start the drag-drop operation
    sourceControl.DoDragDrop(someText, DragDropEffects.Copy | 
        DragDropEffects.Move);
    

    }

    That's it! You drag something, and drop it over *any* Textbox/RTF-Box (Explorer, Word(pad)...).

    C# question

  • Explain this to me
    S StealthyMark

    If the successful typecast is crucial in performing the function, go ahead and use var = (type) object;. If, however, there are alternate ways of performing the function, the as keyword is often better; even if you throw an exception anyway, because catching and rethrowing an exception is very expensive.

    void Function()
    {
    try
    {
    IReferenceService refSvc = (IReferenceService) GetService(typeof(IReferenceService));
    // do something
    }
    catch (Exception exc)
    {
    throw new UsefulException(message, exc);
    }
    }

    void Function()
    {
    IReferenceService refSvc = GetService(typeof(IReferenceService)) as IReferenceService;
    if (refSvc == null)
    {
    // alternatively, you could do it without refSvc
    throw new UsefulException(message);
    }
    // do something
    }

    C# sales question

  • C# Windows application and data store
    S StealthyMark

    Internally, I'd work with DataSets and DataTables, no question. Because both MSDE and Access databases have quite expensive disk costs, I'd use the XML serialization features in conjunction with compression (SharpZipLib perhaps?) to persist these structures to disk. Here comes the clue: You can use the DPAPI (Data Protection API; look for CryptProtectData in MSDN) to encrypt them without worrying about key/password management.

    C# database csharp mysql sql-server sysadmin

  • override root/parent node in tree menu
    S StealthyMark

    a) Add an event handler for the TreeView.BeforeSelect event. or b) Override the TreeView.OnBeforeSelect method of your TreeView-inherited control. Then, check the TreeViewCancelEventArgs.Node property and set TreeViewCancelEventArgs.Cancel to false to prevent selecting the node. Example:

    private void treeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
    {
    TreeNode parent = e.Node.Parent;
    if (parent == null)
    {
    // the root node(s) can't be selected
    e.Cancel = true;
    }
    else if (parent.Parent == null)
    {
    // the node(s) in the root node(s) can't be selected
    e.Cancel = true;
    }
    }

    C# data-structures

  • Updating Listbox Items
    S StealthyMark

    Don't use ToString(). Add the item itself, or better yet use databinding to display a complete collection. When you edit the collection entry, the listbox is updated (possibly after a call to Refresh()).

    C# help question announcement

  • How to set a datasource for a usercontrol?
    S StealthyMark

    Inherit your control from ListControl. It contains the base implementation for binding a control to a list. If you just want to bind your control to a single value, take a look at the Control.DataBindings property.

    C# tutorial question

  • Security a la Palladium ¿? ;)
    S StealthyMark

    Orlanda Ramos wrote: Get a C# Windows Service installed silently ... that gathers the components' names of the target computer Silently install a possibly public web service? No, thanks. Orlanda Ramos wrote: ...sends back a DLL... Another silent installation of executable code? No, thanks. Your application might be safe to sell for you, but the user is at the whim of your company, your code security and every hacker on the 'net, because you introduced a slew of security holes. If any application would do this kind of dangerous, annoying and extensive license verification, it's probably not worth using. Ironically, Windows XP introduced seemingly similar techniques. But at the heart, they are different.

    C# question csharp sysadmin security tutorial

  • How to swap primary key values in a DataTable?
    S StealthyMark

    Before editing your DataRows, set DataSet.EnforceConstraints to false.

    try
    {
    dt.DataSet.EnforceConstraints = false;
    // Edit your Rows
    // EndEdit
    }
    finally
    {
    // If you violated any constraints, like PKs,
    // this statement will throw an exception.
    dt.DataSet.EnforceConstraints = true;
    }

    C# tutorial question

  • Global Logger instance
    S StealthyMark

    Inherit a class from System.Diagnostics.TraceListener. On application start, add an instance of this class to the System.Diagnostics.Trace.Listeners and/or System.Diagnostics.Debug.Listeners collections. Every time you use Trace.Writexxx or Debug.Writexxx, it will be logged through your class. If you change/expand your logging facilities at some time, you don't have to change any client code, just your TraceListener.

    C# design regex architecture question

  • Milla Seconds in DateTime.Now
    S StealthyMark

    In the DateTime structure, one Tick always equals 100 ns (100 nanoseconds = 0.1 mikroseconds = 0.0001 milliseconds). But as you said, the actual resolution is somewhat lower.

    C# question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups