Click here to Skip to main content

Eddy Vluggen - Professional Profile





Summary

    Blog RSS
3,767
Author
67,335
Authority
30,250
Debator
53
Editor
633
Enquirer
10,716
Organiser
6,832
Participant
I'm a Delphi-convert, mostly into WinForms and C#. My first article is from 2001, extending the Delphi-debugger, which is still visible on the WayBackMachine[^] and even available in Russian[^] Smile | :)
  • 31 Dec 2012: CodeProject MVP 2013
  • 31 Dec 2009: CodeProject MVP 2010

 
Articles 3 (Writer)
Tech Blogs 0
Messages 9,725 (Master)
Q&A Questions 0
Q&A Answers 113
Tips/Tricks 3
Comments 50

Groups

Below is the list of groups in which the member is participating

CodeProject Beta Testers

United States United States
No Biography provided
Group type: Collaborative Group
This member has Group Status: Member

members

Reputation

For more information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege, and the given member types also gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilverAdmin
Store personal files in your account areaplatinumplatinumSitebuilder, Subeditor, Supporter, Editor, Staff
Have live hyperlinks in your biographybronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Edit a Question in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Edit an Answer in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Delete a Question in Q&AYesSubeditor, Protector, Editor, Admin
Delete an Answer in Q&AYesSubeditor, Protector, Editor, Admin
Report an ArticlesilversilversilversilverSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubeditor, Mentor, Protector, Editor, Staff, Admin
Edit other members' articlesSubeditor, Protector, Editor, Admin
Create an article without requiring moderationplatinumSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending QuestionProtector, Admin
Approve/Disapprove a pending AnswerProtector, Admin
Report a forum messagesilversilverbronzeProtector, Editor, Admin
Approve/Disapprove a pending Forum MessageProtector, Admin
Create a new tagsilversilversilversilverAdmin
Modify a tagsilversilversilversilverAdmin

Actions with a green tick can be performed by this member.


 
GeneralBookmarks [modified] PinmemberEddy Vluggen18-Mar-11 5:14 
GeneralRelated Utilities [modified] PinmemberEddy Vluggen2-Mar-12 13:10 
NewsOnline tools [modified] PinmemberEddy Vluggen14-Mar-12 9:21 
NewsCustom Controls / Libraries [modified] PinmemberEddy Vluggen9-Apr-12 10:54 
NewsDebugging [modified] PinmemberEddy Vluggen26-Apr-12 23:02 
NewsDesign Patterns PinmemberEddy Vluggen17-Jun-12 1:25 
GeneralRefactorings PinmvpEddy Vluggen7-Oct-10 13:55 
GeneralRe: Refactorings PinmemberVercas26-Dec-10 6:31 
News.NET related snippets PinmvpEddy Vluggen5-Oct-10 10:58 
GeneralTemporaryOverride class PinmvpEddy Vluggen5-Oct-10 11:15 
Sometimes you'd temporarily want to change the value of a variable, and the most common pattern is probably the one below;
string temp = someObject.SomeValue;
someObject.SomeValue = "Updating, call again later";
try
{
    // do stuff
}
finally
{
    someObject.SomeValue = temp;
}
I'm currently working in VB.NET, and it would seem like a dandy idea to be able to do something like the pattern below;
Imports System
Imports SubSystem
 
Public Class SomeLogger
    Public CategoryName As String = "None Specified"
    Public Sub DoLog(ByVal SomeText As String)
        Console.WriteLine("{0}:    {1}", CategoryName, SomeText)
    End Sub
End Class
 
Public Class Application
    Public Shared Logger As New SomeLogger
 
    Public Shared Sub Main()
                
        Logger.DoLog("Hello World")
 
        Using Temporary.Override(Logger, "CategoryName", "Sub Main")
        
            Logger.DoLog("Hello World")
            
        End Using
 
        Logger.DoLog("Hello World")
        
    End Sub
End Class
 
Well, that's possible. Temporary is a static class, returning an IDisposable that wraps the property on said object. When the computer leaves the Using statement, the IDisposable will reflect the original value back, even if we exit the procedure by throwing a new exception.
 
The actual implementation as a reference;
using System;
using System.Collections;
using System.Reflection;
using System.IO;
using System.ComponentModel;
 
namespace SubSystem
{
    public class Temporary
    {
        public static IDisposable Override (Object aObject, String aMemberName, Object aScopedValue)
        {
            return init (aMemberName, aObject.GetType (), aObject, aScopedValue);
        }
        public static IDisposable Override (Type aType, String aMemberName, Object aScopedValue)
        {
            return init (aMemberName, aType, null, aScopedValue);
        }
        
        static IDisposable init (String aMemberName, Type aType, Object aObject, Object aScopedValue)
        {
            MemberInfo memberInfo = aType.GetMember (aMemberName)[0];
            
            switch (memberInfo.MemberType) 
            {
                case MemberTypes.Property:
                    return new TemporaryOverrideProperty (
                        aObject == null ? aType : aObject, 
                        (PropertyInfo)memberInfo, 
                        aScopedValue);
    
                case MemberTypes.Field:
                    return new TemporaryOverrideField (
                        aObject == null ? aType : aObject, 
                        (FieldInfo)memberInfo, 
                        aScopedValue);
    
                default:
                    throw new NotSupportedException ();
            }
        }
    }
 

    public class TemporaryOverrideProperty : TemporaryOverride
    {
        PropertyInfo _overridenProperty;
 
        public TemporaryOverrideProperty(Object aObject, PropertyInfo aProperty, Object aScopedValue)
        {
            this._sourceObject = aObject;
            this.init(aProperty, aScopedValue);
        }
        public TemporaryOverrideProperty(Type aSource, PropertyInfo aProperty, Object aScopedValue)
        {
            this._sourceClass = aSource;
            this.init(aProperty, aScopedValue);
        }
 
        ~TemporaryOverrideProperty()
        {
            this.Dispose(false);
        }
 
        void init(PropertyInfo aProperty, Object aScopedValue)
        {
            this._overridenProperty = aProperty;
            this._originalValue = this._overridenProperty.GetValue(this._sourceObject, null);
            this._overridenProperty.SetValue(this._sourceObject, aScopedValue, null);
        }
 
        protected override void Dispose(Boolean disposing)
        {
            if (disposing)
            {
                this._overridenProperty.SetValue(this._sourceObject, this._originalValue, null);
            }
            base.Dispose(disposing);
        }
    }
    public class TemporaryOverrideField : TemporaryOverride
    {
        FieldInfo _overridenField;
 
        public TemporaryOverrideField(Object aObject, FieldInfo aField, Object aScopedValue)
        {
            this._sourceObject = aObject;
            this.init(aField, aScopedValue);
        }
        public TemporaryOverrideField(Type aSource, FieldInfo aField, Object aScopedValue)
        {
            this._sourceClass = aSource;
            this.init(aField, aScopedValue);
        }
 
        ~TemporaryOverrideField()
        {
            this.Dispose(false);
        }
 
        void init(FieldInfo aField, Object aScopedValue)
        {
            this._overridenField = aField;
            this._originalValue = this._overridenField.GetValue(this._sourceObject);
            this._overridenField.SetValue(this._sourceObject, aScopedValue);
        }
 
        protected override void Dispose(Boolean disposing)
        {
            if (disposing)
            {
                this._overridenField.SetValue(this._sourceObject, this._originalValue);
            }
            base.Dispose(disposing);
        }
    }
 
    public class TemporaryOverride : IDisposable
    {
        protected Object _sourceObject;
        protected Type _sourceClass;
        protected Object _originalValue;
        
        protected TemporaryOverride()
        {
        }
 
        #region IDisposable implementation (MSDN adapted version)
        Boolean disposed = false;
 
        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }
 
        protected virtual void Dispose(Boolean disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                }
 
                // Call the appropriate methods to clean up
                // unmanaged resources here.

                // Note disposing has been done.
                this.disposed = true;
            }
        }
        #endregion
    }
}
I are Troll Suspicious | :suss:

NewsTemporaryOverride class (VB.NET version) PinmemberEddy Vluggen22-Jul-11 5:30 
NewsScopedSupportInitialize PinmemberEddy Vluggen10-Apr-12 9:35 
GeneralA clean CreateDelegate PinmemberEddy Vluggen13-Apr-11 11:04 
NewsInterop with .NET, tested with Lazarus; PinmemberEddy Vluggen13-Sep-11 13:32 
NewsStandard reader-pattern PinmemberEddy Vluggen29-Oct-11 15:31 
NewsAttributionAttribute AboutBox PinmemberEddy Vluggen29-Oct-11 15:55 
NewsMy BigInt implementation PinmemberEddy Vluggen11-Nov-11 8:20 
GeneralTSQL: Fetch metadata for a table PinmvpEddy Vluggen6-Sep-10 10:54 
GeneralTSQL: Fetch tables without Primary Key PinmemberEddy Vluggen31-Jan-11 2:36 
GeneralTSQL: Fetch tables without clustered index PinmemberEddy Vluggen1-Feb-11 22:04 
GeneralVisual Studio macro's: replacing the default help-system PinmvpEddy Vluggen2-Sep-10 10:49 
GeneralVisual Studio macro's: AsQuotedString() PinmvpEddy Vluggen7-Oct-10 14:13 
NewsNo news :) PinmemberEddy Vluggen29-Apr-09 13:55 
GeneralRe: No news :) PinmvpRajesh R Subramanian12-Jan-10 2:55 
GeneralRe: No news :) PinmvpEddy Vluggen12-Jan-10 4:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150302.1 | Last Updated 5 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid