Simple Type Percent for XSD Files

To use the simply type percent (xs:decimal), see the snippet below.

<xs:simpleType name="percent">
  <xs:annotation>
    <xs:documentation>The percent type specifies a value from 0 to 100.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:decimal">
    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="100"/>
  </xs:restriction>
</xs:simpleType>

Please rate this snippet

What is the difference between typeof(), GetType() and IS in C# and VB.NET

What is the difference between typeof(), GetType() and is?

  • typeof() takes a type name specified at compile Time.
  • GetType() gets the Type of an Object at runtime
  • is returns true if an instance is in the inheritance tree. Since the is Keyword is casting the object, you should use it with care.
  • here is an example.

    class Employee { } 
    class Developer : Employee { }
    
    void PrintTypes(Employee e) { 
        print(e.GetType() == typeof(Employee)) // false 
        print(e is Employee)                   // true 
        print(e.GetType() == typeof(Developer))    // true
    }
    

    Please rate this snippet

    How to get all types that implement a specific Interface in C# and VB.NET

    To retrieve a IEnuemerable of all types in the current or another Assembly that implement a specific Interface / Abstract class and so on, you can use the snippets below.

    Methods

    C# Version

    VB.NET Version

    Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5

    Do you have an alternate or better method for this task?
    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

    Generic Type Conversion snippet for C# and VB.NET

    Here you can find a generic Type conversion snippet for C# and VB.NET.

    Sample C#

    public static T GenericConvert<T, X>(X value) where X : IConvertible
    {
    	return (T)Convert.ChangeType(value, typeof(T));
    }
    

    Sample VB.NET

    Public Shared Function GenericConvert(Of T, X As IConvertible)(value As X) As T
    	Return DirectCast(Convert.ChangeType(value, GetType(T)), T)
    End Function
    

    Please rate this snippet

    How to call a non-static method in different assembly using Reflection in C# and VB.NET

    To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

    Sample C#

    Assembly assembly = Assembly.LoadFile(@"Assembly_Location");   
    var type = assembly.Types().FirstOrDefault(x => x.FullName.Contains("MyClassName"));
    var constructor = type.GetConstructor(Type.EmptyTypes);
    
    var classObject = constructor.Invoke(new object[] { }); //call parameterless constructor
    var classObject = constructor.Invoke(new object[] { param1 }); //call non-parameterless constructor
    
    MethodInfo methodInfo = type.GetMethod("MyMethodName");
    methodInfo.Invoke(classObject, new object[] { }); //pass classobject, parameterless method
    methodInfo.Invoke(classObject, new object[] { param1 }); //pass classobject, parameterized method
    

    Sample VB.NET

    Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
    Dim type__2 = assembly__1.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
    Dim constructor = type__2.GetConstructor(Type.EmptyTypes)
    
    Dim classObject = constructor.Invoke(New Object() {})'call parameterless constructor
    Dim classObject = constructor.Invoke(New Object() {param1})'call non-parameterless constructor
    
    Dim methodInfo As MethodInfo = type__2.GetMethod("MyMethodName")
    methodInfo.Invoke(classObject, New Object() {})'pass classobject, parameterless method
    methodInfo.Invoke(classObject, New Object() {param1})'pass classobject, parameterized method
    

    Please rate this snippet

    How to call a static method in different assembly using Reflection in C# and VB.NET

    To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

    Sample C#

    Assembly assembly = Assembly.LoadFile(@"Assembly_Location"); 
    var t = assembly.Types().FirstOrDefault(x=>x.FullName.Contains("MyClassName"));
    var method = t.GetMethod("MyMethodName", BindingFlags.Public | BindingFlags.Static);
    method.Invoke(null, null); //assuming that the method does not have parameters
    method.Invoke(null, new object[] { param1}); //assuming that the method has 1 parameter
    

    Sample VB.NET

    Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
    Dim t = assembly.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
    Dim method = t.GetMethod("MyMethodName", BindingFlags.[Public] Or BindingFlags.[Static])
    method.Invoke(Nothing, Nothing) 'assuming that the method does not have parameters
    method.Invoke(Nothing, New Object() {param1}) 'assuming that the method has 1 parameter
    

    Please rate this snippet

    How to get the type of a generic parameter in C# and VB.NET

    To get the type of a generic parameter in C# and VB.NET you can use the following snippet.

    Sample C#

    Type typeParam = typeof(T);
    

    Sample VB.NET

    Dim typeParam As Type = GetType(T)
    

    Please rate this snippet

    What is the best datatype for money in C# and VB.NET

    The best Datatype for money in C# and VB.NET is Decimal.
    What is the MSDN saying about Decimal.

    The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.

    MSDN SOURCE

    Please rate this snippet

    How to get the mime type of a file in Java

    To get the mime type of a file in Java you can use the following snippet.

    Sample Java

    String fileName = "/path/to/file.zip";
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String mimeType = mimeTypesMap.getContentType(fileName);
    File file = new File(fileName);
    mimeType = mimeTypesMap.getContentType(file);
    System.out.println(mimeType);
    

    Please rate this snippet