[{"data":1,"prerenderedAt":315},["ShallowReactive",2],{"article-iterate-over-object-properties-and-property-attributes-w-reflection":3},{"article":4,"tags":78,"previous":93,"next":268},{"id":5,"title":6,"author":7,"body":8,"createdAt":67,"description":68,"extension":69,"img":68,"meta":70,"navigation":71,"path":72,"seo":73,"stem":74,"tags":75,"updatedAt":67,"__hash__":77},"articles\u002Farticles\u002Fiterate-over-object-properties-and-property-attributes-w-reflection.md","Iterate Over Object Properties and Property Attributes w\u002FReflection","[object Object]",{"type":9,"value":10,"toc":64},"minimark",[11,15,54,60],[12,13,14],"p",{},"Define custom attribute class as follows as well as placing the attribute reference on the property “FirstName”.  In the following we are creating our own custom attribute by defining an attribute class which derives from Attribute which makes identifying attribute definitions in metadata easy.  The AttributeUsage attribute can be used to limit which asset the attribute can be placed such as class, struct, property etc.  In addition, in the example below I have disallowed multiple similar attributes from being used on the same property designated by AllowMultiple = false     ",[16,17,21,22,26,29,30,40,51],"pre",{"className":18},[19,20],"brush:","csharp","    ",[23,24,25],"span",{},"AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)",[27,28],"br",{},"\npublic class CustomItemAttribute : Attribute {",[16,31,36],{"className":32,"code":34,"language":35},[33],"language-text","    public string FieldName { get; set; }  \n\n    private bool _isMultiValue = false;  \n    public bool IsMultiValue {  \n        get { return _isMultiValue; }  \n        set {  \n            _isMultiValue = value;  \n        }  \n    }  \n\n    public CustomItemAttribute(string fieldName) {  \n        this.FieldName = fieldName;          \n    }  \n}  \n","text",[37,38,34],"code",{"__ignoreMap":39},"",[12,41,42,43,45,48,50],{},"public class Item{",[27,44],{},[23,46,47],{},"CustomItem(\"myfieldname\")",[27,49],{},"\npublic string FirstName { get; set;}",[12,52,53],{},"}",[12,55,56,57,59],{},"Now to iterate over the properties. Notice in the class Item above how we can exclude the 'Attribute' text in the name of the attribute applied to the FirstName property. Below we can use Type.GetProperties method to get the names of the properties for a specific type. The method GetProperties returns an array of PropertyInfo objects and the property names aer available through PropertyInfo.Name. If you want to get only a subset of the properties such as public static ones you can use BindingFlags parameters (Public\u002FNonPublic, Instance\u002FStatic). i.e. PropertyInfo",[23,58],{}," infos = typeof(Item).GetProperties(BindingFlags.Public|BindingFlags.Static);",[16,61,63],{"className":62},[19,20],"        private void IterateOverProperties() {  \n            CustomItemAttribute customItemAttribute;  \n            Type type = typeof(Item);  \n        \u002F\u002Ffor each property of object of Item  \n            foreach (PropertyInfo propInfo in type.GetProperties()) {  \n                \u002F\u002Ffor each custom attribute on the property loop  \n                foreach CustomItemAttribute attr in propInfo.GetCustomAttributes(typeof(CustomItemAttribute), false)) {  \n                    customItemAttribute = attr as CustomItemAttribute;  \n                    if (customItemAttribute != null) {  \n                        string propertyName = propInfo.Name;  \n                        string fieldName = customItemAttribute.FieldName;              \n            \u002F\u002FTODO: add your logic here  \n                    }   \n                }  \n            }  \n        }",{"title":39,"searchDepth":65,"depth":65,"links":66},2,[],"2015-04-20T08:07:14.1700000-04:00",null,"md",{},true,"\u002Farticles\u002Fiterate-over-object-properties-and-property-attributes-w-reflection",{"title":6,"description":68},"articles\u002Fiterate-over-object-properties-and-property-attributes-w-reflection",[76],"aspnet","ZthYNR0xRiDSvIjg9fVGjlPJjgpoE9X9J0htudQFbIM",[79],{"id":80,"title":81,"body":82,"description":86,"extension":69,"img":87,"meta":88,"name":76,"navigation":71,"path":89,"seo":90,"stem":91,"__hash__":92},"tags\u002Ftags\u002Faspnet.md","Aspnet",{"type":9,"value":83,"toc":84},[],{"title":39,"searchDepth":65,"depth":65,"links":85},[],"ASP.NET is an open source web framework, created by Microsoft, for building modern web apps and services with .NET.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Faspnet",{"description":86},"tags\u002Faspnet","SlUGLdZWQy8mYOWC6OetgJkwVulWNURoVHeuESIDleI",{"id":94,"title":95,"author":7,"body":96,"createdAt":259,"description":260,"extension":69,"img":68,"meta":261,"navigation":71,"path":262,"seo":263,"stem":264,"tags":265,"updatedAt":259,"__hash__":267},"articles\u002Farticles\u002Fsharepoint-method-return-splist-or-create-a-new-one.md","SharePoint Method–Return SPList (or Create a new one)",{"type":9,"value":97,"toc":257},[98,101,250,253],[12,99,100],{},"Method that returns an existing SPList on a SharePoint web (based on list name) or create a new one if not found.",[16,102,105],{"className":103,"code":104,"language":20,"meta":39,"style":39},"language-csharp shiki shiki-themes github-light github-dark","public static SPList EnsureList(SPWeb site, string listName, SPListTemplateType template, bool onQuickLaunch) {  \n      \n    SPList list = null;  \n    Guid listID = Guid.Empty;  \n    if (site != null) {  \n        foreach (SPList item in site.Lists) {  \n            if (item.Title.ToLower() == listName.ToLower()) {  \n                list = item;  \n                listID = item.ID;  \n                break;  \n            }  \n        }  \n  \n        if (list == null) {  \n            listID = site.Lists.Add(listName,\"\", template);  \n            list = site.Lists[listID];  \n            list.OnQuickLaunch = onQuickLaunch;  \n            list.Update();              \n        }  \n    } else {  \n        throw new Exception(\"In EnsureSiteDataList SPWeb is null\");  \n    }  \n    return list;  \n}  \n",[37,106,107,114,119,125,131,137,143,149,155,161,167,173,179,185,191,197,203,209,215,220,226,232,238,244],{"__ignoreMap":39},[23,108,111],{"class":109,"line":110},"line",1,[23,112,113],{},"public static SPList EnsureList(SPWeb site, string listName, SPListTemplateType template, bool onQuickLaunch) {  \n",[23,115,116],{"class":109,"line":65},[23,117,118],{},"      \n",[23,120,122],{"class":109,"line":121},3,[23,123,124],{},"    SPList list = null;  \n",[23,126,128],{"class":109,"line":127},4,[23,129,130],{},"    Guid listID = Guid.Empty;  \n",[23,132,134],{"class":109,"line":133},5,[23,135,136],{},"    if (site != null) {  \n",[23,138,140],{"class":109,"line":139},6,[23,141,142],{},"        foreach (SPList item in site.Lists) {  \n",[23,144,146],{"class":109,"line":145},7,[23,147,148],{},"            if (item.Title.ToLower() == listName.ToLower()) {  \n",[23,150,152],{"class":109,"line":151},8,[23,153,154],{},"                list = item;  \n",[23,156,158],{"class":109,"line":157},9,[23,159,160],{},"                listID = item.ID;  \n",[23,162,164],{"class":109,"line":163},10,[23,165,166],{},"                break;  \n",[23,168,170],{"class":109,"line":169},11,[23,171,172],{},"            }  \n",[23,174,176],{"class":109,"line":175},12,[23,177,178],{},"        }  \n",[23,180,182],{"class":109,"line":181},13,[23,183,184],{},"  \n",[23,186,188],{"class":109,"line":187},14,[23,189,190],{},"        if (list == null) {  \n",[23,192,194],{"class":109,"line":193},15,[23,195,196],{},"            listID = site.Lists.Add(listName,\"\", template);  \n",[23,198,200],{"class":109,"line":199},16,[23,201,202],{},"            list = site.Lists[listID];  \n",[23,204,206],{"class":109,"line":205},17,[23,207,208],{},"            list.OnQuickLaunch = onQuickLaunch;  \n",[23,210,212],{"class":109,"line":211},18,[23,213,214],{},"            list.Update();              \n",[23,216,218],{"class":109,"line":217},19,[23,219,178],{},[23,221,223],{"class":109,"line":222},20,[23,224,225],{},"    } else {  \n",[23,227,229],{"class":109,"line":228},21,[23,230,231],{},"        throw new Exception(\"In EnsureSiteDataList SPWeb is null\");  \n",[23,233,235],{"class":109,"line":234},22,[23,236,237],{},"    }  \n",[23,239,241],{"class":109,"line":240},23,[23,242,243],{},"    return list;  \n",[23,245,247],{"class":109,"line":246},24,[23,248,249],{},"}\n",[12,251,252],{},"Cool eh?",[254,255,256],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":39,"searchDepth":65,"depth":65,"links":258},[],"2015-04-20T08:07:14.2600000-04:00","Method that returns an existing SPList on a SharePoint web",{},"\u002Farticles\u002Fsharepoint-method-return-splist-or-create-a-new-one",{"title":95,"description":260},"articles\u002Fsharepoint-method-return-splist-or-create-a-new-one",[266],"sharepoint","23Ps1y5WrMGsI6PnpJjW-M6_FbRRv2pr0lErNFzPytw",{"id":269,"title":270,"author":7,"body":271,"createdAt":305,"description":306,"extension":69,"img":307,"meta":308,"navigation":71,"path":309,"seo":310,"stem":311,"tags":312,"updatedAt":305,"__hash__":314},"articles\u002Farticles\u002Fnet-4-new-gac-locations-gacutil.md",".NET 4 New GAC Locations\u002FGacUtil",{"type":9,"value":272,"toc":303},[273,276,279,282,285,288,291,294,297,300],[12,274,275],{}," This is what I know, let me know if you know otherwise.  There are now 2 distinct GAC locations that you have to manage as of the .NET 4 Framework release.",[12,277,278],{},"The GAC was split into two, one for each CLR (2.0, 3.5 AND 4.0).  The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. To avoid issues between CLR 2.0 and CLR 4.0 , the GAC is now split into private GAC’s for each runtime.  The main change is that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC.",[12,280,281],{},"In previous .NET versions, when I installed a .NET assembly into the GAC (using gacutil.exe or even drag and drop to the c:\\windows\\assembly directory), I could find it in the ‘C:\\Windows\\assembly’ path.",[12,283,284],{},"With .NET 4.0, GAC is now located in the 'C:\\Windows\\Microsoft.NET\\assembly’ path.",[12,286,287],{},"In order to install a dll to the .NET 4 GAC it is necessary to use the gacutil found C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\GacUtil.exe  In addition, you can no longer use the drag n' drop (in reality the drag n' drop really executed the gacutil via a windows explorer extension).",[12,289,290],{},"After you use the gacutil.exe -i {path to dll} you can view that it is indeed in the gac via gacutil -l (which will list all dlls in the gac).  I used this command and piped the results to a text file via > out.txt which made it easier to find the recently added component.",[12,292,293],{},"I was not able to see my gac object in the directory for .net 4 (i.e. c:\\windows\\microsoft.net\\assembly path).  I am not sure why just yet.  Ideas?",[12,295,296],{},"At this point, the object is in the local gac however if you are using vs.net 2010 it will still not show up in the list of references. To get the component to show up in the VS.NET list of references can add a registry entry to HKLM\\SOFTWARE\\WOW6432Node\\Microsoft.NETFramework\\v4.0.30319\\AssemblyFoldersEx  At this point, the component is in the local GAC and is in the list of references to be used by vs.net.",[12,298,299],{},"Note, I did find that if I just added the path to the registry without adding it to the gac it was available to vs.net.  So, because the component is listed via vs.net add references it does not necessarily mean it is in the gac.",[12,301,302],{},"What still confuses me is that I am still unable to view my recently added component in the .NET 4 directories above.  Ideas?",{"title":39,"searchDepth":65,"depth":65,"links":304},[],"2015-04-20T08:07:14.0800000-04:00","There are now 2 distinct GAC locations that you have to manage as of the .NET 4 Framework release...","\u002Farticles\u002Fimages\u002Fggb4dMDcZM.png",{},"\u002Farticles\u002Fnet-4-new-gac-locations-gacutil",{"title":270,"description":306},"articles\u002Fnet-4-new-gac-locations-gacutil",[76,313],"enterpriselibrary","2K_K7LqZ6HZ_OhbA_zCui0-ixHdV9XtLRHPoIkAcdss",1781574762372]