How to select an element with its name attribute in jQuery

To select an element with its name attribute in jQuery you can use the snippet below.

Samples

Javascript Sample

if you remove the div in div[name=”de.Fesslersoft.Testname”] you will get all elements with the specific name.

You can also have a look at this JSFiddle.

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to get all Description Attributes of an Enum using C# or VB.NET

To get all Description Attributes of an Enum using C# or VB.NET you can use the snippet below.

Sample C# – Class

public class DescriptionAttributes<T>
    {
        protected List<DescriptionAttribute> Attributes = new List<DescriptionAttribute>();
        public List<string> Descriptions { get; set; }

        public DescriptionAttributes()
        {
            RetrieveAttributes();
            Descriptions = Attributes.Select(x => x.Description).ToList();
        }

        private void RetrieveAttributes()
        {
            foreach (var attribute in typeof(T).GetMembers().SelectMany(member => member.GetCustomAttributes(typeof(DescriptionAttribute), true).Cast<DescriptionAttribute>()))
            {
                Attributes.Add(attribute);
            }
        }
    }

Usage C#

class Program
    {
        public enum TestEnum
        {
            [Description("An apple a day keeps the doctor away")]
            Apple=0,
            [Description("Yummie Strawberry")]
            Strawberry=1,
            [Description("Banana for scale")]
            Banana=2
        }

        static void Main(string[] args)
        {
            var descriptions = new DescriptionAttributes<TestEnum>().Descriptions.ToList();
            foreach (var description in descriptions)
            {
                Console.WriteLine(description);
            }
            Console.Read();
        }
    }

Sample VB.NET – Class

Public Class DescriptionAttributes(Of T)
	Protected Attributes As New List(Of DescriptionAttribute)()
	Public Property Descriptions() As List(Of String)
		Get
			Return m_Descriptions
		End Get
		Set
			m_Descriptions = Value
		End Set
	End Property
	Private m_Descriptions As List(Of String)

	Public Sub New()
		RetrieveAttributes()
		Descriptions = Attributes.[Select](Function(x) x.Description).ToList()
	End Sub

	Private Sub RetrieveAttributes()
		For Each attribute As var In GetType(T).GetMembers().SelectMany(Function(member) member.GetCustomAttributes(GetType(DescriptionAttribute), True).Cast(Of DescriptionAttribute)())
			Attributes.Add(attribute)
		Next
	End Sub
End Class

Usage VB.NET

Class Program
	Public Enum TestEnum
		<Description("An apple a day keeps the doctor away")> _
		Apple = 0
		<Description("Yummie Strawberry")> _
		Strawberry = 1
		<Description("Banana for scale")> _
		Banana = 2
	End Enum

	Private Shared Sub Main(args As String())
		Dim descriptions = New DescriptionAttributes(Of TestEnum)().Descriptions.ToList()
		For Each description As var In descriptions
			Console.WriteLine(description)
		Next
		Console.Read()
	End Sub
End Class

Result / Output

Enum Descriptions

Enum Descriptions

Please rate this snippet

How to use the assembly InternalsVisibleTo attribute

If your code contains classes, interfaces or structs that have the internal (c#) access qualifier or the Friend (VB.NET) access qualifier, you cannot access them from another assembly (e.g. unit testing). Types have this qualifier for one of two reasons

– You have explicitly marked them as internal.
– By default, top-level classes, interfaces, or structs that have no explicit access qualifier are treated as internal.

But what if you need to make them visible just for a specific assembly? Thats where the assembly InternalsVisibleTo attribute comes into play.
If your Assembly which has the Internal access qualifiers has no strong name you simply have to put the following line of code to its AssemblyInfo-File.

Sample C#

[assembly:InternalsVisibleTo("OtherAssemblyName")]

Sample VB.NET

<Assembly:InternalsVisibleTo("OtherAssemblyName")>

If your Assembly which has the Internal access qualifiers has strong name you simply have to put the following line of code to its AssemblyInfo-File.
The PublicKey depends on your Assembly, so you need to put the right PublicKey in it, check the links on the bottom of this Posts on how to get the PublicKey.

Sample C#

[assembly:InternalsVisibleTo("OtherAssemblyName,PublicKey=00240000048000009400000006020000002400005253413100040000010001002B4D3670141EEBB497143AD5400105B520B65C7CC91076C86BDEBDFB9BBB527D4B98F51F70D12B92008DB4D0715C26E7C4857CD1D44EC12AD17CED8E7DC94CD4F28E4962BB88EF6224F4BC6C1A7F35238383B70E56323B48B1C57F4E0510C0E9C5625A0A485AB22A03C7B199CB529FB234D279F883633A18509AC231B643E1E5")]

Sample VB.NET

<Assembly:InternalsVisibleTo("OtherAssemblyName,PublicKey=00240000048000009400000006020000002400005253413100040000010001002B4D3670141EEBB497143AD5400105B520B65C7CC91076C86BDEBDFB9BBB527D4B98F51F70D12B92008DB4D0715C26E7C4857CD1D44EC12AD17CED8E7DC94CD4F28E4962BB88EF6224F4BC6C1A7F35238383B70E56323B48B1C57F4E0510C0E9C5625A0A485AB22A03C7B199CB529FB234D279F883633A18509AC231B643E1E5")>

More informations: Setting the InternalsVisibleTo Attribute, Getting Public Key Token of Assembly Within Visual Studio, AssemblyHelperTool

Please rate this snippet