Click here to Skip to main content
15,893,487 members

Ilka Guigova - Professional Profile



Summary

    Blog RSS
3,733
Author
60
Authority
328
Debator
193
Editor
5
Enquirer
346
Organiser
888
Participant

Reputation

Weekly Data. Recent events may not appear immediately. For 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. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

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


 
GeneralRemoving Event Handlers Using Reflection Pin
Ilka Guigova3-Nov-11 7:42
Ilka Guigova3-Nov-11 7:42 
GeneralLogos. No images. No JS. Just CSS Pin
Ilka Guigova31-Oct-11 10:07
Ilka Guigova31-Oct-11 10:07 
GeneralOperating System Version Info Pin
Ilka Guigova24-Oct-11 8:25
Ilka Guigova24-Oct-11 8:25 
GeneralSet a .NET 4.0 Application to auto-start upon login Pin
Ilka Guigova16-Oct-11 16:50
Ilka Guigova16-Oct-11 16:50 
GeneralA sample implementation Pin
Ilka Guigova26-Jun-12 7:13
Ilka Guigova26-Jun-12 7:13 
GeneralExtended ExtJS HtmlEditor to handle paste from MS Word and table manipulations Pin
Ilka Guigova6-Sep-11 9:49
Ilka Guigova6-Sep-11 9:49 
GeneralConvertWord documents to Clean HTML Pin
Ilka Guigova24-Jul-12 10:12
Ilka Guigova24-Jul-12 10:12 
GeneralInvoking a Generic Method With Parameters using Reflection Pin
Ilka Guigova28-Aug-11 13:35
Ilka Guigova28-Aug-11 13:35 
Context

Imagine that you have few lookup tables[^]. Each one can have its own lookup method; e.g.,
C#
string LookupCountryCodes(string query);
string LookupStateCodes(string query);
string LookupCardTypes(string query)

Likely, these methods differ only in the table /entity name that they apply to. Every time a new lookup table / entity is added, the lookup method has to be copied. Readability, extensibility, and maintainability of the code suffers.

Idea

Instead, we can define the lookup as a generic method[^]; e.g.,
C#
string Lookup<T>(string query) where T: class, ILookupEntity, new();


Then, given a table / entity name, we can find the associated:

  • table / entity type
  • C#
    var t = Type.GetType(typeName);
    if (t == null)
    {
        var types = from assembly in System.AppDomain.CurrentDomain.GetAssemblies()
                    from assemblyType in assembly.GetTypes()
                    where assemblyType.Name == typeName
                    select assemblyType;
    
        t = types.FirstOrDefault();
    }


  • Lookup method
  • C#
    var method = <owner_of_Lookup_method>.GetType()
        .GetMethod("Lookup", new Type[] {typeof (string)})
        .MakeGenericMethod(entityType);

    where the <owner_of_Lookup_method> is either a static class or an instance of an object with a Lookup method definition.

    Implementation

    Putting it all together:
    C#
    private Dictionary<string, Type> typeCache = new Dictionary<string, Type>(); 
    
    public bool TryFindType(string typeName, out Type t)
    {
        lock (typeCache)
        {
            if (!typeCache.TryGetValue(typeName, out t))
            {
                t = Type.GetType(typeName);
                if (t == null)
                {
                    var types = from assembly in System.AppDomain.CurrentDomain.GetAssemblies()
                                from assemblyType in assembly.GetTypes()
                                where assemblyType.Name == typeName
                                select assemblyType;
    
                    t = types.FirstOrDefault();
                }
                typeCache[typeName] = t; // perhaps null
            }
        }
        return t != null;
    }
    
    public string Get(string entityTypeName, string query)
    {
        Type entityType;
    
        if (TryFindType(entityTypeName, out entityType))
        {
            var method = <owner_of_Lookup_method>.GetType()
                .GetMethod("Lookup", new Type[] {typeof (string)})
                .MakeGenericMethod(entityType);
    
            return Convert.ToString(method.Invoke(<owner_of_Lookup_method>, new[] { query }));
        }
    
        return string.Empty;
    }


    See also:
    How to use reflection to call generic method[^]
    GetType returns null[^]
    GetType returns null (2)[^]
    How to invoke method with parameters[^]
    Object does not match target type+Reflection[^]
    Overcoming problems with MethodInfo.Invoke of methods with by-reference value type arguments[^]
    modified on Wednesday, August 31, 2011 12:20 AM

    GeneralRe: Invoking a Generic Method With Parameters using Reflection Pin
    Ilka Guigova1-Mar-12 7:25
    Ilka Guigova1-Mar-12 7:25 
    GeneralSlide-In Image Captions Pin
    Ilka Guigova27-Aug-11 19:49
    Ilka Guigova27-Aug-11 19:49 
    General30 Useful jQuery Tabs Tutorials Pin
    Ilka Guigova9-Jul-11 14:36
    Ilka Guigova9-Jul-11 14:36 
    GeneralOne-liners Pin
    Ilka Guigova4-Jun-12 7:34
    Ilka Guigova4-Jun-12 7:34 
    GeneralLogical XOR in Javascript Pin
    Ilka Guigova25-Apr-11 14:36
    Ilka Guigova25-Apr-11 14:36 
    GeneralA Collapsible Outline of Indented Text in Javascript Pin
    Ilka Guigova6-Feb-11 16:19
    Ilka Guigova6-Feb-11 16:19 
    GeneralPython calculations - arrangements Pin
    Ilka Guigova30-Aug-10 7:44
    Ilka Guigova30-Aug-10 7:44 
    GeneralVisualStudio 2005 Slow On Save Pin
    Ilka Guigova23-May-10 13:44
    Ilka Guigova23-May-10 13:44 
    GeneralT-SQL Cursor and XML Basic Example Pin
    Ilka Guigova3-Apr-10 13:13
    Ilka Guigova3-Apr-10 13:13 
    GeneralT-SQL Auto Increment Variable Pin
    Ilka Guigova2-Apr-10 20:04
    Ilka Guigova2-Apr-10 20:04 
    GeneralApplying XSL Transformations Pin
    Ilka Guigova29-Mar-10 11:05
    Ilka Guigova29-Mar-10 11:05 
    GeneralXML DOM Load Functions Pin
    Ilka Guigova10-Aug-12 13:46
    Ilka Guigova10-Aug-12 13:46 
    GeneralWorking with durations in MSSQL server Pin
    Ilka Guigova31-Jan-10 13:11
    Ilka Guigova31-Jan-10 13:11 
    GeneralRe: Working with durations in MSSQL server Pin
    Grunge Boy31-Jan-10 23:29
    Grunge Boy31-Jan-10 23:29 
    GeneralRe: Working with durations in MSSQL server Pin
    Ilka Guigova1-Feb-10 7:17
    Ilka Guigova1-Feb-10 7:17 
    GeneralThe hidden __arglist keyword Pin
    Ilka Guigova9-Aug-09 14:38
    Ilka Guigova9-Aug-09 14:38 
    GeneralServices Pin
    Ilka Guigova9-Aug-09 14:27
    Ilka Guigova9-Aug-09 14:27 

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

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