From a0ed7fc91ba55b1acf94e14d84f71150aeb288ba Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:52:14 -0700 Subject: [PATCH 1/4] Modernize C# code snippets --- .../Type/AssemblyQualifiedName/fullname1.cs | 6 +- .../System/Type/Attributes/attributes1.cs | 158 +++++++++--------- .../csharp/System/Type/BaseType/basetype3.cs | 42 ++--- .../csharp/System/Type/BaseType/remarks.cs | 6 +- .../System/Type/BaseType/testbasetype.cs | 4 +- .../Type/ContainsGenericParameters/source.cs | 29 ++-- .../System/Type/DeclaringMethod/source.cs | 26 +-- .../System/Type/DeclaringType/remarks.cs | 8 +- .../System/Type/DeclaringType/source.cs | 8 +- .../Type/DefaultBinder/type_defaultbinder.cs | 15 +- .../csharp/System/Type/EmptyTypes/source.cs | 12 +- .../csharp/System/Type/Equals/EqualsEx1.cs | 69 ++++---- snippets/csharp/System/Type/Equals/source.cs | 14 +- .../FilterAttribute/type_filterattribute.cs | 18 +- .../csharp/System/Type/FilterName/source.cs | 30 ++-- .../type_filternameignorecase.cs | 14 +- .../FindInterfaces/type_findinterfaces.cs | 32 ++-- .../Type/FindMembers/type_findmembers.cs | 18 +- .../csharp/System/Type/FullName/Fullname3.cs | 32 ++-- .../csharp/System/Type/FullName/Fullname4.cs | 57 +++---- .../csharp/System/Type/FullName/Fullname5.cs | 48 +++--- .../System/Type/FullName/fullnameex1.cs | 18 +- .../System/Type/FullName/testfullname.cs | 8 +- snippets/csharp/System/Type/GUID/type_guid.cs | 8 +- .../Type/GenericParameterAttributes/source.cs | 38 ++--- .../Type/GenericParameterPosition/remarks.cs | 11 +- .../Type/GetArrayRank/type_getarrayrank.cs | 8 +- .../System/Type/GetConstructors/source1.cs | 31 ++-- .../System/Type/GetConstructors/source2.cs | 35 ++-- .../System/Type/GetDefaultMembers/source2.cs | 24 +-- .../type_getdefaultmembers.cs | 22 +-- .../Type/GetElementType/testgetelementtype.cs | 10 +- .../System/Type/GetEvent/type_getevent.cs | 14 +- .../System/Type/GetEvent/type_getevent1.cs | 14 +- .../System/Type/GetEvents/type_getevents1.cs | 8 +- .../System/Type/GetEvents/type_getevents2.cs | 8 +- .../System/Type/GetField/type_getfield.cs | 19 +-- .../Type/GetFields/fieldinfo_isspecialname.cs | 13 +- .../csharp/System/Type/GetFields/source.cs | 11 +- .../System/Type/GetGenericArguments/source.cs | 23 +-- .../Type/GetGenericTypeDefinition/source.cs | 18 +- .../GetHashCode/type_gethashcode_getfields.cs | 27 ++- .../Type/GetInterface/type_getinterface.cs | 38 ++--- .../Type/GetInterfaceMap/interfacemapping1.cs | 37 ++-- .../System/Type/GetMember/type_getmember.cs | 48 +++--- .../Type/GetMembers/type_getmembers1.cs | 70 ++++---- .../Type/GetMembers/type_getmembers2.cs | 80 ++++----- .../System/Type/GetMethod/GetMethod1.cs | 88 +++++----- .../Type/GetMethod/GetMethodWithOverloads1.cs | 32 ++-- .../Type/GetMethod/GetMethodWithOverloads2.cs | 21 +-- .../System/Type/GetMethod/type_getmethod1.cs | 2 +- .../System/Type/GetMethod/type_getmethod2.cs | 2 +- .../System/Type/GetMethod/type_getmethod3.cs | 92 +++++----- .../System/Type/GetMethod/type_getmethod4.cs | 64 +++---- .../System/Type/GetMethod/type_getmethod5.cs | 82 ++++----- .../Type/GetMethods/type_getmethods2.cs | 28 ++-- .../type_getnestedclassesabs.cs | 12 +- .../GetNestedTypes/type_getnestedtypes.cs | 20 +-- .../Type/GetProperties/type_getproperties2.cs | 87 ++++------ .../Type/GetProperties/type_gettypecode.cs | 28 ++-- .../Type/GetProperty/type_getproperty1.cs | 2 +- .../Type/GetProperty/type_getproperty2.cs | 2 +- .../Type/GetProperty/type_getproperty21.cs | 26 ++- .../Type/GetProperty/type_getproperty3.cs | 17 +- .../GetProperty/type_getproperty_types.cs | 12 +- .../Type/GetType/mypath/v5.0/myassembly.cs | 4 +- snippets/csharp/System/Type/GetType/source.cs | 2 +- .../System/Type/GetType/type_gettype.cs | 43 ++--- .../System/Type/GetTypeCode/iconvertible.cs | 107 ++++-------- .../GetTypeFromCLSID/gettypefromclsid1.cs | 33 ++-- .../GetTypeFromCLSID/gettypefromclsid11.cs | 106 ++++++------ .../GetTypeFromCLSID/gettypefromclsid_ex2.cs | 46 ++--- .../GetTypeFromCLSID/gettypefromclsid_ex3.cs | 44 ++--- .../GetTypeFromCLSID/gettypefromclsid_ex4.cs | 54 +++--- .../type_gettypefromhandle.cs | 18 +- .../type_gettypefromprogid2.cs | 16 +- .../type_gettypefromprogid3.cs | 18 +- .../type_gettypefromprogid4.cs | 18 +- .../HasElementType/type_haselementtype.cs | 25 ++- .../type_haselementtypeimpl.cs | 31 ++-- .../System/Type/InvokeMember/invokemem.cs | 32 ++-- .../System/Type/IsAbstract/isabstract1.cs | 26 ++- .../Type/IsAnsiClass/type_isansiclass.cs | 16 +- .../csharp/System/Type/IsArray/isarray2.cs | 17 +- .../Type/IsArrayImpl/type_isarrayimpl.cs | 25 ++- .../IsAssignableFrom/IsAssignableFrom2.cs | 18 +- .../IsAssignableFrom/IsAssignableFrom3.cs | 24 +-- .../IsAssignableFrom/isassignablefrom_ex1.cs | 30 ++-- .../IsAssignableFrom/testisassignablefrom.cs | 110 ++++++------ .../Type/IsAutoLayout/type_isautolayout.cs | 7 +- .../System/Type/IsClass/type_isclass.cs | 12 +- .../Type/IsContextful/type_iscontextful.cs | 28 ++-- .../IsContextfulImpl/type_iscontextfulimpl.cs | 25 ++- .../csharp/System/Type/IsEnum/testisenum.cs | 14 +- .../IsExplicitLayout/type_isexplicitlayout.cs | 29 ++-- .../System/Type/IsGenericParameter/source.cs | 23 +-- .../System/Type/IsGenericType/remarks.cs | 14 +- .../System/Type/IsGenericType/source.cs | 28 ++-- .../IsInstanceOfType/testisinstanceoftype.cs | 23 +-- .../Type/IsInterface/type_isinterface.cs | 12 +- .../type_islayoutsequential.cs | 18 +- .../type_ismarshalbyrefimpl.cs | 25 ++- .../IsNested/isnestedfamilyandassembly1.cs | 35 ++-- .../csharp/System/Type/IsNotPublic/source.cs | 8 +- .../IsPrimitiveImpl/type_isprimitiveimpl.cs | 27 ++- .../System/Type/IsPublic/type_ispublic.cs | 18 +- .../System/Type/IsSealed/type_issealed.cs | 32 ++-- .../IsSubclassOf/issubclassof_interface1.cs | 21 +-- .../Type/IsSubclassOf/testissubclassof.cs | 8 +- .../Type/IsValueType/type_isvaluetype.cs | 4 +- .../csharp/System/Type/IsVisible/source.cs | 18 +- .../System/Type/MakeByRefType/source.cs | 14 +- .../System/Type/MakeGenericType/remarks.cs | 10 +- .../System/Type/MakeGenericType/source.cs | 27 ++- snippets/csharp/System/Type/Missing/source.cs | 17 +- .../System/Type/Module/type_tostring.cs | 20 +-- .../csharp/System/Type/Overview/Equals1.cs | 8 +- .../csharp/System/Type/Overview/GetType1.cs | 4 +- .../csharp/System/Type/Overview/source.cs | 8 +- .../System/Type/ReflectedType/source.cs | 5 +- .../Type/StructLayoutAttribute/source.cs | 8 +- .../System/Type/TypeHandle/type_typehandle.cs | 14 +- .../Overview/Missing1.cs | 20 +-- .../Overview/Missing1a.cs | 23 +-- .../Overview/Regex1.cs | 4 +- .../Overview/ctorException1.cs | 32 ++-- .../.ctor/typeloadexception_constructor2.cs | 32 ++-- .../.ctor/typeloadexception_constructor3.cs | 64 +++---- .../Message/typeloadexception_typename.cs | 41 +++-- .../System/TypedReference/Overview/source.cs | 28 ++-- 130 files changed, 1669 insertions(+), 1906 deletions(-) diff --git a/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs b/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs index 4ff74780f6b..ce3d21c98c2 100644 --- a/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs +++ b/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs @@ -7,17 +7,17 @@ public class Example { public static void Main() { - Type t = typeof(String); + Type t = typeof(string); ShowTypeInfo(t); t = typeof(List<>); ShowTypeInfo(t); - var list = new List(); + var list = new List(); t = list.GetType(); ShowTypeInfo(t); - Object v = 12; + object v = 12; t = v.GetType(); ShowTypeInfo(t); diff --git a/snippets/csharp/System/Type/Attributes/attributes1.cs b/snippets/csharp/System/Type/Attributes/attributes1.cs index c76637c5c15..c56eed168b8 100644 --- a/snippets/csharp/System/Type/Attributes/attributes1.cs +++ b/snippets/csharp/System/Type/Attributes/attributes1.cs @@ -9,9 +9,9 @@ internal struct S public abstract class Example { - protected sealed class NestedClass {} + protected sealed class NestedClass { } - public interface INested {} + public interface INested { } public static void Main() { @@ -19,89 +19,89 @@ public static void Main() Type[] types = { typeof(Example), typeof(NestedClass), typeof(INested), typeof(S) }; - foreach (var t in types) + foreach (var t in types) { - Console.WriteLine("Attributes for type {0}:", t.Name); + Console.WriteLine($"Attributes for type {t.Name}:"); - TypeAttributes attr = t.Attributes; + TypeAttributes attr = t.Attributes; - // To test for visibility attributes, you must use the visibility mask. - TypeAttributes visibility = attr & TypeAttributes.VisibilityMask; - switch (visibility) - { - case TypeAttributes.NotPublic: - Console.WriteLine(" ...is not public"); - break; - case TypeAttributes.Public: - Console.WriteLine(" ...is public"); - break; - case TypeAttributes.NestedPublic: - Console.WriteLine(" ...is nested and public"); - break; - case TypeAttributes.NestedPrivate: - Console.WriteLine(" ...is nested and private"); - break; - case TypeAttributes.NestedFamANDAssem: - Console.WriteLine(" ...is nested, and inheritable only within the assembly" + - "\n (cannot be declared in C#)"); - break; - case TypeAttributes.NestedAssembly: - Console.WriteLine(" ...is nested and internal"); - break; - case TypeAttributes.NestedFamily: - Console.WriteLine(" ...is nested and protected"); - break; - case TypeAttributes.NestedFamORAssem: - Console.WriteLine(" ...is nested and protected internal"); - break; - } + // To test for visibility attributes, you must use the visibility mask. + TypeAttributes visibility = attr & TypeAttributes.VisibilityMask; + switch (visibility) + { + case TypeAttributes.NotPublic: + Console.WriteLine(" ...is not public"); + break; + case TypeAttributes.Public: + Console.WriteLine(" ...is public"); + break; + case TypeAttributes.NestedPublic: + Console.WriteLine(" ...is nested and public"); + break; + case TypeAttributes.NestedPrivate: + Console.WriteLine(" ...is nested and private"); + break; + case TypeAttributes.NestedFamANDAssem: + Console.WriteLine(" ...is nested, and inheritable only within the assembly" + + "\n (cannot be declared in C#)"); + break; + case TypeAttributes.NestedAssembly: + Console.WriteLine(" ...is nested and internal"); + break; + case TypeAttributes.NestedFamily: + Console.WriteLine(" ...is nested and protected"); + break; + case TypeAttributes.NestedFamORAssem: + Console.WriteLine(" ...is nested and protected internal"); + break; + } - // Use the layout mask to test for layout attributes. - TypeAttributes layout = attr & TypeAttributes.LayoutMask; - switch (layout) - { - case TypeAttributes.AutoLayout: - Console.WriteLine(" ...is AutoLayout"); - break; - case TypeAttributes.SequentialLayout: - Console.WriteLine(" ...is SequentialLayout"); - break; - case TypeAttributes.ExplicitLayout: - Console.WriteLine(" ...is ExplicitLayout"); - break; - } + // Use the layout mask to test for layout attributes. + TypeAttributes layout = attr & TypeAttributes.LayoutMask; + switch (layout) + { + case TypeAttributes.AutoLayout: + Console.WriteLine(" ...is AutoLayout"); + break; + case TypeAttributes.SequentialLayout: + Console.WriteLine(" ...is SequentialLayout"); + break; + case TypeAttributes.ExplicitLayout: + Console.WriteLine(" ...is ExplicitLayout"); + break; + } - // Use the class semantics mask to test for class semantics attributes. - TypeAttributes classSemantics = attr & TypeAttributes.ClassSemanticsMask; - switch (classSemantics) - { - case TypeAttributes.Class: - if (t.IsValueType) - { - Console.WriteLine(" ...is a value type"); - } - else - { - Console.WriteLine(" ...is a class"); - } - break; - case TypeAttributes.Interface: - Console.WriteLine(" ...is an interface"); - break; - } + // Use the class semantics mask to test for class semantics attributes. + TypeAttributes classSemantics = attr & TypeAttributes.ClassSemanticsMask; + switch (classSemantics) + { + case TypeAttributes.Class: + if (t.IsValueType) + { + Console.WriteLine(" ...is a value type"); + } + else + { + Console.WriteLine(" ...is a class"); + } + break; + case TypeAttributes.Interface: + Console.WriteLine(" ...is an interface"); + break; + } - if ((attr & TypeAttributes.Abstract) != 0) - { - Console.WriteLine(" ...is abstract"); - } + if ((attr & TypeAttributes.Abstract) != 0) + { + Console.WriteLine(" ...is abstract"); + } - if ((attr & TypeAttributes.Sealed) != 0) - { - Console.WriteLine(" ...is sealed"); - } - - Console.WriteLine(); - } + if ((attr & TypeAttributes.Sealed) != 0) + { + Console.WriteLine(" ...is sealed"); + } + + Console.WriteLine(); + } } } // The example displays the following output: @@ -128,4 +128,4 @@ public static void Main() // ...is SequentialLayout // ...is a value type // ...is sealed -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/BaseType/basetype3.cs b/snippets/csharp/System/Type/BaseType/basetype3.cs index 500bf5b7dd4..6d0aed03f61 100644 --- a/snippets/csharp/System/Type/BaseType/basetype3.cs +++ b/snippets/csharp/System/Type/BaseType/basetype3.cs @@ -3,39 +3,41 @@ public class Example { - public static void Main() - { - foreach (var t in typeof(Example).Assembly.GetTypes()) { - Console.WriteLine("{0} derived from: ", t.FullName); - var derived = t; - do { - derived = derived.BaseType; - if (derived != null) - Console.WriteLine(" {0}", derived.FullName); - } while (derived != null); - Console.WriteLine(); - } - } + public static void Main() + { + foreach (var t in typeof(Example).Assembly.GetTypes()) + { + Console.WriteLine($"{t.FullName} derived from: "); + var derived = t; + do + { + derived = derived.BaseType; + if (derived != null) + Console.WriteLine($" {derived.FullName}"); + } while (derived != null); + Console.WriteLine(); + } + } } -public class A {} +public class A { } public class B : A -{} +{ } -public class C : B -{} +public class C : B +{ } // The example displays the following output: // Example derived from: // System.Object -// +// // A derived from: // System.Object -// +// // B derived from: // A // System.Object -// +// // C derived from: // B // A diff --git a/snippets/csharp/System/Type/BaseType/remarks.cs b/snippets/csharp/System/Type/BaseType/remarks.cs index fbc5b1bee05..252849ac5a5 100644 --- a/snippets/csharp/System/Type/BaseType/remarks.cs +++ b/snippets/csharp/System/Type/BaseType/remarks.cs @@ -1,4 +1,4 @@ -using System; + // class B { } @@ -7,5 +7,5 @@ class C : B { } class ProgStubClass { - public static void Main() {} -} \ No newline at end of file + public static void Main() { } +} diff --git a/snippets/csharp/System/Type/BaseType/testbasetype.cs b/snippets/csharp/System/Type/BaseType/testbasetype.cs index 08e8fc01e5e..f324d83297c 100644 --- a/snippets/csharp/System/Type/BaseType/testbasetype.cs +++ b/snippets/csharp/System/Type/BaseType/testbasetype.cs @@ -5,7 +5,7 @@ class TestType public static void Main() { Type t = typeof(int); - Console.WriteLine("{0} inherits from {1}.", t,t.BaseType); + Console.WriteLine($"{t} inherits from {t.BaseType}."); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/ContainsGenericParameters/source.cs b/snippets/csharp/System/Type/ContainsGenericParameters/source.cs index 065bda276aa..c4d1e611e5c 100644 --- a/snippets/csharp/System/Type/ContainsGenericParameters/source.cs +++ b/snippets/csharp/System/Type/ContainsGenericParameters/source.cs @@ -1,7 +1,7 @@ // using System; -using System.Reflection; -using System.Collections.Generic; + + // Define a base class with two type parameters. public class Base { } @@ -25,10 +25,10 @@ public static void Main() "\r\n--- Display a generic type and the open constructed"); Console.WriteLine(" type from which it is derived."); - // Create a Type object representing the generic type definition + // Create a Type object representing the generic type definition // for the Derived type, by omitting the type argument. (For // types with multiple type parameters, supply the commas but - // omit the type arguments.) + // omit the type arguments.) // Type derivedType = typeof(Derived<>); DisplayGenericTypeInfo(derivedType); @@ -39,16 +39,13 @@ public static void Main() private static void DisplayGenericTypeInfo(Type t) { - Console.WriteLine("\r\n{0}", t); + Console.WriteLine($"\r\n{t}"); - Console.WriteLine("\tIs this a generic type definition? {0}", - t.IsGenericTypeDefinition); + Console.WriteLine($"\tIs this a generic type definition? {t.IsGenericTypeDefinition}"); - Console.WriteLine("\tIs it a generic type? {0}", - t.IsGenericType); + Console.WriteLine($"\tIs it a generic type? {t.IsGenericType}"); - Console.WriteLine("\tDoes it have unassigned generic parameters? {0}", - t.ContainsGenericParameters); + Console.WriteLine($"\tDoes it have unassigned generic parameters? {t.ContainsGenericParameters}"); if (t.IsGenericType) { @@ -56,8 +53,7 @@ private static void DisplayGenericTypeInfo(Type t) // Type[] typeArguments = t.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", - typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { @@ -66,14 +62,11 @@ private static void DisplayGenericTypeInfo(Type t) // if (tParam.IsGenericParameter) { - Console.WriteLine( - "\t\t{0} (unassigned - parameter position {1})", - tParam, - tParam.GenericParameterPosition); + Console.WriteLine($"\t\t{tParam} (unassigned - parameter position {tParam.GenericParameterPosition})"); } else { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } diff --git a/snippets/csharp/System/Type/DeclaringMethod/source.cs b/snippets/csharp/System/Type/DeclaringMethod/source.cs index 486c25baa98..a0f5bf9f23a 100644 --- a/snippets/csharp/System/Type/DeclaringMethod/source.cs +++ b/snippets/csharp/System/Type/DeclaringMethod/source.cs @@ -6,10 +6,7 @@ // Define a class with a generic method. public class Example { - public static void Generic(T toDisplay) - { - Console.WriteLine("\r\nHere it is: {0}", toDisplay); - } + public static void Generic(T toDisplay) => Console.WriteLine($"\r\nHere it is: {toDisplay}"); } // @@ -37,7 +34,7 @@ public static void Main() // // Invoke the method. - object[] args = {42}; + object[] args = { 42 }; miConstructed.Invoke(null, args); // Invoke the method normally. @@ -48,28 +45,24 @@ public static void Main() // and show it's the same as the original definition. // MethodInfo miDef = miConstructed.GetGenericMethodDefinition(); - Console.WriteLine("\r\nThe definition is the same: {0}", - miDef == mi); + Console.WriteLine($"\r\nThe definition is the same: {miDef == mi}"); // } private static void DisplayGenericMethodInfo(MethodInfo mi) { - Console.WriteLine("\r\n{0}", mi); + Console.WriteLine($"\r\n{mi}"); // - Console.WriteLine("\tIs this a generic method definition? {0}", - mi.IsGenericMethodDefinition); + Console.WriteLine($"\tIs this a generic method definition? {mi.IsGenericMethodDefinition}"); // // - Console.WriteLine("\tIs it a generic method? {0}", - mi.IsGenericMethod); + Console.WriteLine($"\tIs it a generic method? {mi.IsGenericMethod}"); // // - Console.WriteLine("\tDoes it have unassigned generic parameters? {0}", - mi.ContainsGenericParameters); + Console.WriteLine($"\tDoes it have unassigned generic parameters? {mi.ContainsGenericParameters}"); // // @@ -79,8 +72,7 @@ private static void DisplayGenericMethodInfo(MethodInfo mi) { Type[] typeArguments = mi.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", - typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { @@ -97,7 +89,7 @@ private static void DisplayGenericMethodInfo(MethodInfo mi) } else { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } diff --git a/snippets/csharp/System/Type/DeclaringType/remarks.cs b/snippets/csharp/System/Type/DeclaringType/remarks.cs index 65cefe2b1d1..8df6af54a2b 100644 --- a/snippets/csharp/System/Type/DeclaringType/remarks.cs +++ b/snippets/csharp/System/Type/DeclaringType/remarks.cs @@ -5,9 +5,9 @@ class ProgStubClass { public static void Main() { -// + // Type t = typeof(List).GetMethod("ConvertAll").GetGenericArguments()[0].DeclaringType; -// - Console.WriteLine("Declaring type: {0:s}", t.FullName); + // + Console.WriteLine($"Declaring type: {t.FullName:s}"); } -} \ No newline at end of file +} diff --git a/snippets/csharp/System/Type/DeclaringType/source.cs b/snippets/csharp/System/Type/DeclaringType/source.cs index c89abffcee0..1ed1680ee72 100644 --- a/snippets/csharp/System/Type/DeclaringType/source.cs +++ b/snippets/csharp/System/Type/DeclaringType/source.cs @@ -1,6 +1,6 @@ // using System; -using System.Reflection; + public abstract class dtype { @@ -14,11 +14,7 @@ public abstract class MyClassB : MyClassA { } - public static void Main(string[] args) - { - Console.WriteLine("The declaring type of m is {0}.", - typeof(MyClassB).GetMethod("m").DeclaringType); - } + public static void Main(string[] args) => Console.WriteLine($"The declaring type of m is {typeof(MyClassB).GetMethod("m").DeclaringType}."); } /* The example produces the following output: diff --git a/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs b/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs index cf63b5bcb1d..8ee5ffdc6f4 100644 --- a/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs +++ b/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs @@ -9,23 +9,20 @@ public static void Main() try { Binder defaultBinder = Type.DefaultBinder; - MyClass myClass = new MyClass(); + MyClass myClass = new(); // Invoke the HelloWorld method of MyClass. myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, - defaultBinder, myClass, new object [] {}); + defaultBinder, myClass, new object[] { }); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception :" + e.Message); } - } + } class MyClass { - public void HelloWorld() - { - Console.WriteLine("Hello World"); - } + public void HelloWorld() => Console.WriteLine("Hello World"); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/EmptyTypes/source.cs b/snippets/csharp/System/Type/EmptyTypes/source.cs index 904cf7bd34d..dfe135cac1a 100644 --- a/snippets/csharp/System/Type/EmptyTypes/source.cs +++ b/snippets/csharp/System/Type/EmptyTypes/source.cs @@ -1,15 +1,15 @@ using System; -using System.IO; using System.Reflection; public class Sample { - public void Method(Type type) { + public void Method(Type type) + { ConstructorInfo cInfo; -// -cInfo = type.GetConstructor (BindingFlags.ExactBinding, null, - Type.EmptyTypes, null); -// + // + cInfo = type.GetConstructor(BindingFlags.ExactBinding, null, + Type.EmptyTypes, null); + // } } diff --git a/snippets/csharp/System/Type/Equals/EqualsEx1.cs b/snippets/csharp/System/Type/Equals/EqualsEx1.cs index 6d50d87251a..aa41ba7847b 100644 --- a/snippets/csharp/System/Type/Equals/EqualsEx1.cs +++ b/snippets/csharp/System/Type/Equals/EqualsEx1.cs @@ -5,48 +5,47 @@ public class Example { - public static void Main() - { - Type t =typeof(int); - Object obj1 = typeof(int).GetTypeInfo(); - IsEqualTo(t, obj1); + public static void Main() + { + Type t = typeof(int); + object obj1 = typeof(int).GetTypeInfo(); + IsEqualTo(t, obj1); - Object obj2 = typeof(String); - IsEqualTo(t, obj2); - - t = typeof(Object); - Object obj3 = typeof(Object); - IsEqualTo(t, obj3); - - t = typeof(List<>); - Object obj4 = (new List()).GetType(); - IsEqualTo(t, obj4); - - t = typeof(Type); - Object obj5 = null; - IsEqualTo(t, obj5); - } - - private static void IsEqualTo(Type t, Object inst) - { - Type t2 = inst as Type; - if (t2 != null) - Console.WriteLine("{0} = {1}: {2}", t.Name, t2.Name, - t.Equals(t2)); - else - Console.WriteLine("Cannot cast the argument to a type."); + object obj2 = typeof(string); + IsEqualTo(t, obj2); - Console.WriteLine(); - } + t = typeof(object); + object obj3 = typeof(object); + IsEqualTo(t, obj3); + + t = typeof(List<>); + object obj4 = (new List()).GetType(); + IsEqualTo(t, obj4); + + t = typeof(Type); + object obj5 = null; + IsEqualTo(t, obj5); + } + + private static void IsEqualTo(Type t, object inst) + { + Type t2 = inst as Type; + if (t2 != null) + Console.WriteLine($"{t.Name} = {t2.Name}: {t.Equals(t2)}"); + else + Console.WriteLine("Cannot cast the argument to a type."); + + Console.WriteLine(); + } } // The example displays the following output: // Int32 = Int32: True -// +// // Int32 = String: False -// +// // Object = Object: True -// +// // List`1 = List`1: False -// +// // Cannot cast the argument to a type. // diff --git a/snippets/csharp/System/Type/Equals/source.cs b/snippets/csharp/System/Type/Equals/source.cs index 2e1a1ec3040..ec0d404e1e9 100644 --- a/snippets/csharp/System/Type/Equals/source.cs +++ b/snippets/csharp/System/Type/Equals/source.cs @@ -1,17 +1,17 @@ // using System; -using System.Reflection; + class Example { public static void Main() { - Type a = typeof(System.String); - Type b = typeof(System.Int32); + Type a = typeof(string); + Type b = typeof(int); - Console.WriteLine("{0} == {1}: {2}", a, b, a.Equals(b)); + Console.WriteLine($"{a} == {b}: {a.Equals(b)}"); // The Type objects in a and b are not equal, // because they represent different types. @@ -19,14 +19,14 @@ public static void Main() a = typeof(Example); b = new Example().GetType(); - Console.WriteLine("{0} is equal to {1}: {2}", a, b, a.Equals(b)); + Console.WriteLine($"{a} is equal to {b}: {a.Equals(b)}"); // The Type objects in a and b are equal, // because they both represent type Example. b = typeof(Type); - Console.WriteLine("typeof({0}).Equals(typeof({1})): {2}", a, b, a.Equals(b)); + Console.WriteLine($"typeof({a}).Equals(typeof({b})): {a.Equals(b)}"); // The Type objects in a and b are not equal, // because variable a represents type Example @@ -42,4 +42,4 @@ public static void Main() Example is equal to Example: True typeof(Example).Equals(typeof(System.Type)): False */ -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs b/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs index f2a0fe4c3e0..1d0b7d0f6b7 100644 --- a/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs +++ b/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs @@ -10,28 +10,28 @@ public static void Main() try { MemberFilter myFilter = Type.FilterAttribute; - Type myType = typeof(System.String); + Type myType = typeof(string); MemberInfo[] myMemberInfoArray = myType.FindMembers(MemberTypes.Constructor - |MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | + | MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, myFilter, MethodAttributes.SpecialName); foreach (MemberInfo myMemberinfo in myMemberInfoArray) { - Console.Write ("\n" + myMemberinfo.Name); - Console.Write (" is a " + myMemberinfo.MemberType.ToString()); + Console.Write("\n" + myMemberinfo.Name); + Console.Write(" is a " + myMemberinfo.MemberType.ToString()); } } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.Write("ArgumentNullException : " + e.Message); } - catch(SecurityException e) + catch (SecurityException e) { Console.Write("SecurityException : " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.Write("Exception :" + e.Message); } - } + } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/FilterName/source.cs b/snippets/csharp/System/Type/FilterName/source.cs index 350fbe03859..fb3126f09c6 100644 --- a/snippets/csharp/System/Type/FilterName/source.cs +++ b/snippets/csharp/System/Type/FilterName/source.cs @@ -3,22 +3,24 @@ public class Sample { - public void Method() - { -// - // Get the set of methods associated with the type - MemberInfo[] mi = typeof(Application).FindMembers(MemberTypes.Constructor | - MemberTypes.Method, - BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.DeclaredOnly, - Type.FilterName, "*"); - Console.WriteLine("Number of methods (includes constructors): " + mi.Length); -// - } + public void Method() + { + // + // Get the set of methods associated with the type + MemberInfo[] mi = typeof(Application).FindMembers(MemberTypes.Constructor | + MemberTypes.Method, + BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | + BindingFlags.Instance | BindingFlags.DeclaredOnly, + Type.FilterName, "*"); + Console.WriteLine("Number of methods (includes constructors): " + mi.Length); + // + } } // Class added so sample will compile -public class Application { - public void Method() { +public class Application +{ + public void Method() + { } } diff --git a/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs b/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs index 419668f72c1..8f5fe976b6e 100644 --- a/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs +++ b/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs @@ -7,11 +7,11 @@ public class MyFilterNameIgnoreCaseSample public static void Main() { try - { + { MemberFilter myFilter = Type.FilterNameIgnoreCase; - Type myType = typeof(System.String); + Type myType = typeof(string); MemberInfo[] myMemberinfo1 = myType.FindMembers(MemberTypes.Constructor - |MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | + | MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, myFilter, "C*"); foreach (MemberInfo myMemberinfo2 in myMemberinfo1) { @@ -20,18 +20,18 @@ public static void Main() Console.WriteLine(" is a " + Mymembertypes.ToString()); } } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.Write("ArgumentNullException : " + e.Message); } - catch(SecurityException e) + catch (SecurityException e) { Console.Write("SecurityException : " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.Write("Exception : " + e.Message); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs b/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs index bf7c4b78a44..abee4581f12 100644 --- a/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs +++ b/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs @@ -9,55 +9,51 @@ public static void Main() { try { - XmlDocument myXMLDoc = new XmlDocument(); + XmlDocument myXMLDoc = new(); myXMLDoc.LoadXml("" + "Pride And Prejudice" + ""); Type myType = myXMLDoc.GetType(); // Specify the TypeFilter delegate that compares the // interfaces against filter criteria. - TypeFilter myFilter = new TypeFilter(MyInterfaceFilter); - String[] myInterfaceList = new String[2] + TypeFilter myFilter = new(MyInterfaceFilter); + string[] myInterfaceList = new string[2] {"System.Collections.IEnumerable", "System.Collections.ICollection"}; - for(int index=0; index < myInterfaceList.Length; index++) + for (int index = 0; index < myInterfaceList.Length; index++) { Type[] myInterfaces = myType.FindInterfaces(myFilter, myInterfaceList[index]); if (myInterfaces.Length > 0) { - Console.WriteLine("\n{0} implements the interface {1}.", - myType, myInterfaceList[index]); - for(int j =0;j < myInterfaces.Length;j++) - Console.WriteLine("Interfaces supported: {0}.", - myInterfaces[j].ToString()); + Console.WriteLine($"\n{myType} implements the interface {myInterfaceList[index]}."); + for (int j = 0; j < myInterfaces.Length; j++) + Console.WriteLine($"Interfaces supported: {myInterfaces[j].ToString()}."); } else - Console.WriteLine( - "\n{0} does not implement the interface {1}.", - myType,myInterfaceList[index]); + Console.WriteLine($"\n{myType} does not implement the interface {myInterfaceList[index]}."); } } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException: " + e.Message); } - catch(TargetInvocationException e) + catch (TargetInvocationException e) { Console.WriteLine("TargetInvocationException: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } } - public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj) + public static bool MyInterfaceFilter(Type typeObj, object criteriaObj) { - if(typeObj.ToString() == criteriaObj.ToString()) + if (typeObj.ToString() == criteriaObj.ToString()) return true; else return false; } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/FindMembers/type_findmembers.cs b/snippets/csharp/System/Type/FindMembers/type_findmembers.cs index e0fee47a706..ef595523385 100644 --- a/snippets/csharp/System/Type/FindMembers/type_findmembers.cs +++ b/snippets/csharp/System/Type/FindMembers/type_findmembers.cs @@ -6,29 +6,29 @@ class MyFindMembersClass { public static void Main() { - Object objTest = new Object(); - Type objType = objTest.GetType (); + object objTest = new(); + Type objType = objTest.GetType(); MemberInfo[] arrayMemberInfo; try { //Find all static or public methods in the Object class that match the specified name. arrayMemberInfo = objType.FindMembers(MemberTypes.Method, - BindingFlags.Public | BindingFlags.Static| BindingFlags.Instance, + BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, new MemberFilter(DelegateToSearchCriteria), "ReferenceEquals"); - for(int index=0;index < arrayMemberInfo.Length ;index++) - Console.WriteLine ("Result of FindMembers -\t"+ arrayMemberInfo[index].ToString() +"\n"); + for (int index = 0; index < arrayMemberInfo.Length; index++) + Console.WriteLine("Result of FindMembers -\t" + arrayMemberInfo[index].ToString() + "\n"); } catch (Exception e) { - Console.WriteLine ("Exception : " + e.ToString() ); + Console.WriteLine("Exception : " + e.ToString()); } } - public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object objSearch) + public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, object objSearch) { // Compare the name of the member function with the filter criteria. - if(objMemberInfo.Name.ToString() == objSearch.ToString()) + if (objMemberInfo.Name.ToString() == objSearch.ToString()) return true; else return false; @@ -38,4 +38,4 @@ public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object obj Result of FindMembers - Boolean ReferenceEquals(System.Object, System.Object) */ -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/FullName/Fullname3.cs b/snippets/csharp/System/Type/FullName/Fullname3.cs index 3e1a2dcf054..a62b34c701a 100644 --- a/snippets/csharp/System/Type/FullName/Fullname3.cs +++ b/snippets/csharp/System/Type/FullName/Fullname3.cs @@ -1,23 +1,25 @@ // using System; -using System.Reflection; + public class Example { - public static void Main() - { - Type t = typeof(Nullable<>); - Console.WriteLine(t.FullName); - if (t.IsGenericType) { - Console.Write(" Generic Type Parameters: "); - Type[] gtArgs = t.GetGenericArguments(); - for (int ctr = 0; ctr < gtArgs.Length; ctr++) { - Console.WriteLine(gtArgs[ctr].FullName ?? - "(unassigned) " + gtArgs[ctr].ToString()); - } - Console.WriteLine(); - } - } + public static void Main() + { + Type t = typeof(Nullable<>); + Console.WriteLine(t.FullName); + if (t.IsGenericType) + { + Console.Write(" Generic Type Parameters: "); + Type[] gtArgs = t.GetGenericArguments(); + for (int ctr = 0; ctr < gtArgs.Length; ctr++) + { + Console.WriteLine(gtArgs[ctr].FullName ?? + "(unassigned) " + gtArgs[ctr].ToString()); + } + Console.WriteLine(); + } + } } // The example displays the following output: // System.Nullable`1 diff --git a/snippets/csharp/System/Type/FullName/Fullname4.cs b/snippets/csharp/System/Type/FullName/Fullname4.cs index 0d349fefccc..69dc72938eb 100644 --- a/snippets/csharp/System/Type/FullName/Fullname4.cs +++ b/snippets/csharp/System/Type/FullName/Fullname4.cs @@ -2,41 +2,38 @@ using System; using System.Reflection; -public class GenericType1 +public class GenericType1 { - public void Display(T[] elements) - {} - - public void HandleT(T obj) - {} - - public bool ChangeValue(ref T arg) - { - return true; - } + public void Display(T[] elements) + { } + + public void HandleT(T obj) + { } + + public bool ChangeValue(ref T arg) => true; } public class Example { - public static void Main() - { - Type t = typeof(GenericType1<>); - Console.WriteLine("Type Name: {0}", t.FullName); - MethodInfo[] methods = t.GetMethods(BindingFlags.Instance | - BindingFlags.DeclaredOnly | - BindingFlags.Public); - foreach (var method in methods) { - Console.WriteLine(" Method: {0}", method.Name); - // Get method parameters. - ParameterInfo param = method.GetParameters()[0]; - Type paramType = param.ParameterType; - if (method.Name == "HandleT") - paramType = paramType.MakePointerType(); - Console.WriteLine(" Parameter: {0}", - paramType.FullName ?? - paramType.ToString() + " (unassigned)"); - } - } + public static void Main() + { + Type t = typeof(GenericType1<>); + Console.WriteLine($"Type Name: {t.FullName}"); + MethodInfo[] methods = t.GetMethods(BindingFlags.Instance | + BindingFlags.DeclaredOnly | + BindingFlags.Public); + foreach (var method in methods) + { + Console.WriteLine($" Method: {method.Name}"); + // Get method parameters. + ParameterInfo param = method.GetParameters()[0]; + Type paramType = param.ParameterType; + if (method.Name == "HandleT") + paramType = paramType.MakePointerType(); + Console.WriteLine($" Parameter: {paramType.FullName ?? + paramType.ToString() + " (unassigned)"}"); + } + } } // The example displays the following output: // Type Name: GenericType1`1 diff --git a/snippets/csharp/System/Type/FullName/Fullname5.cs b/snippets/csharp/System/Type/FullName/Fullname5.cs index c2bd57eb565..ce7fca7452a 100644 --- a/snippets/csharp/System/Type/FullName/Fullname5.cs +++ b/snippets/csharp/System/Type/FullName/Fullname5.cs @@ -1,6 +1,6 @@ // using System; -using System.Reflection; + public class Base { } @@ -8,44 +8,36 @@ public class Derived : Base { } public class Example { - public static void Main() - { - Type t = typeof(Derived<>); - Console.WriteLine("Generic Class: {0}", t.FullName); - Console.WriteLine(" Contains Generic Paramters: {0}", - t.ContainsGenericParameters); - Console.WriteLine(" Generic Type Definition: {0}\n", - t.IsGenericTypeDefinition); + public static void Main() + { + Type t = typeof(Derived<>); + Console.WriteLine($"Generic Class: {t.FullName}"); + Console.WriteLine($" Contains Generic Paramters: {t.ContainsGenericParameters}"); + Console.WriteLine($" Generic Type Definition: {t.IsGenericTypeDefinition}\n"); - Type baseType = t.BaseType; - Console.WriteLine("Its Base Class: {0}", - baseType.FullName ?? - "(unassigned) " + baseType.ToString()); - Console.WriteLine(" Contains Generic Paramters: {0}", - baseType.ContainsGenericParameters); - Console.WriteLine(" Generic Type Definition: {0}", - baseType.IsGenericTypeDefinition); - Console.WriteLine(" Full Name: {0}\n", - baseType.GetGenericTypeDefinition().FullName); + Type baseType = t.BaseType; + Console.WriteLine($"Its Base Class: {baseType.FullName ?? + "(unassigned) " + baseType.ToString()}"); + Console.WriteLine($" Contains Generic Paramters: {baseType.ContainsGenericParameters}"); + Console.WriteLine($" Generic Type Definition: {baseType.IsGenericTypeDefinition}"); + Console.WriteLine($" Full Name: {baseType.GetGenericTypeDefinition().FullName}\n"); - t = typeof(Base<>); - Console.WriteLine("Generic Class: {0}", t.FullName); - Console.WriteLine(" Contains Generic Paramters: {0}", - t.ContainsGenericParameters); - Console.WriteLine(" Generic Type Definition: {0}\n", - t.IsGenericTypeDefinition); - } + t = typeof(Base<>); + Console.WriteLine($"Generic Class: {t.FullName}"); + Console.WriteLine($" Contains Generic Paramters: {t.ContainsGenericParameters}"); + Console.WriteLine($" Generic Type Definition: {t.IsGenericTypeDefinition}\n"); + } } // The example displays the following output: // Generic Class: Derived`1 // Contains Generic Paramters: True // Generic Type Definition: True -// +// // Its Base Class: (unassigned) Base`1[T] // Contains Generic Paramters: True // Generic Type Definition: False // Full Name: Base`1 -// +// // Generic Class: Base`1 // Contains Generic Paramters: True // Generic Type Definition: True diff --git a/snippets/csharp/System/Type/FullName/fullnameex1.cs b/snippets/csharp/System/Type/FullName/fullnameex1.cs index ef2b91e4e60..c62f05b4a07 100644 --- a/snippets/csharp/System/Type/FullName/fullnameex1.cs +++ b/snippets/csharp/System/Type/FullName/fullnameex1.cs @@ -4,16 +4,16 @@ public class Example { - public static void Main() - { - Type t = typeof(List<>); - Console.WriteLine(t.FullName); - Console.WriteLine(); + public static void Main() + { + Type t = typeof(List<>); + Console.WriteLine(t.FullName); + Console.WriteLine(); - List list = new List(); - t = list.GetType(); - Console.WriteLine(t.FullName); - } + List list = new(); + t = list.GetType(); + Console.WriteLine(t.FullName); + } } // The example displays the following output: // System.Collections.Generic.List`1 diff --git a/snippets/csharp/System/Type/FullName/testfullname.cs b/snippets/csharp/System/Type/FullName/testfullname.cs index cd4311ff848..0ca5eea2e2e 100644 --- a/snippets/csharp/System/Type/FullName/testfullname.cs +++ b/snippets/csharp/System/Type/FullName/testfullname.cs @@ -2,10 +2,10 @@ using System; class TestFullName { -public static void Main() + public static void Main() { - Type t = typeof(Array); - Console.WriteLine("The full name of the Array type is {0}.", t.FullName); + Type t = typeof(Array); + Console.WriteLine($"The full name of the Array type is {t.FullName}."); } } @@ -13,4 +13,4 @@ public static void Main() The full name of the Array type is System.Array. */ -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GUID/type_guid.cs b/snippets/csharp/System/Type/GUID/type_guid.cs index 3d8d9ae108f..43a2706f8c6 100644 --- a/snippets/csharp/System/Type/GUID/type_guid.cs +++ b/snippets/csharp/System/Type/GUID/type_guid.cs @@ -1,4 +1,4 @@ -// +// using System; class MyGetTypeFromCLSID @@ -14,9 +14,9 @@ public static void Main() // Get the type corresponding to the class MyClass. Type myType = typeof(MyClass1); // Get the object of the Guid. - Guid myGuid =(Guid) myType.GUID; - Console.WriteLine("The name of the class is "+myType.ToString()); - Console.WriteLine("The ClassId of MyClass is "+myType.GUID); + Guid myGuid = (Guid)myType.GUID; + Console.WriteLine("The name of the class is " + myType.ToString()); + Console.WriteLine("The ClassId of MyClass is " + myType.GUID); } } // diff --git a/snippets/csharp/System/Type/GenericParameterAttributes/source.cs b/snippets/csharp/System/Type/GenericParameterAttributes/source.cs index de9251c2277..a7706371fc2 100644 --- a/snippets/csharp/System/Type/GenericParameterAttributes/source.cs +++ b/snippets/csharp/System/Type/GenericParameterAttributes/source.cs @@ -3,24 +3,25 @@ using System.Reflection; // Define a sample interface to use as an interface constraint. -public interface ITest {} +public interface ITest { } // Define a base type to use as a base class constraint. -public class Base {} +public class Base { } // Define the generic type to examine. The first generic type parameter, // T, derives from the class Base and implements ITest. This demonstrates -// a base class constraint and an interface constraint. The second generic -// type parameter, U, must be a reference type (class) and must have a +// a base class constraint and an interface constraint. The second generic +// type parameter, U, must be a reference type (class) and must have a // default constructor (new()). This demonstrates special constraints. // -public class Test - where T : Base, ITest - where U : class, new() {} +public class Test + where T : Base, ITest + where U : class, new() +{ } // Define a type that derives from Base and implements ITest. This type // satisfies the constraints on T in class Test. -public class Derived : Base, ITest {} +public class Derived : Base, ITest { } public class Example { @@ -28,10 +29,10 @@ public static void Main() { // To get the generic type definition, omit the type // arguments but retain the comma to indicate the number - // of type arguments. + // of type arguments. // Type def = typeof(Test<,>); - Console.WriteLine("\r\nExamining generic type {0}", def); + Console.WriteLine($"\r\nExamining generic type {def}"); // Get the type parameters of the generic type definition, // and display them. @@ -39,30 +40,29 @@ public static void Main() Type[] defparams = def.GetGenericArguments(); foreach (Type tp in defparams) { - Console.WriteLine("\r\nType parameter: {0}", tp.Name); - Console.WriteLine("\t{0}", - ListGenericParameterAttributes(tp)); + Console.WriteLine($"\r\nType parameter: {tp.Name}"); + Console.WriteLine($"\t{ListGenericParameterAttributes(tp)}"); // List the base class and interface constraints. The - // constraints are returned in no particular order. If + // constraints are returned in no particular order. If // there are no class or interface constraints, an empty // array is returned. // Type[] tpConstraints = tp.GetGenericParameterConstraints(); foreach (Type tpc in tpConstraints) { - Console.WriteLine("\t{0}", tpc); + Console.WriteLine($"\t{tpc}"); } } } - // List the variance and special constraint flags. + // List the variance and special constraint flags. // private static string ListGenericParameterAttributes(Type t) { string retval; GenericParameterAttributes gpa = t.GenericParameterAttributes; - GenericParameterAttributes variance = gpa & + GenericParameterAttributes variance = gpa & GenericParameterAttributes.VarianceMask; // Select the variance flags. @@ -78,8 +78,8 @@ private static string ListGenericParameterAttributes(Type t) retval = "Contravariant;"; } - // Select - GenericParameterAttributes constraints = gpa & + // Select + GenericParameterAttributes constraints = gpa & GenericParameterAttributes.SpecialConstraintMask; if (constraints == GenericParameterAttributes.None) diff --git a/snippets/csharp/System/Type/GenericParameterPosition/remarks.cs b/snippets/csharp/System/Type/GenericParameterPosition/remarks.cs index 007f013977c..5966452546e 100644 --- a/snippets/csharp/System/Type/GenericParameterPosition/remarks.cs +++ b/snippets/csharp/System/Type/GenericParameterPosition/remarks.cs @@ -1,17 +1,14 @@ -using System; + // public class B { } public class A { - public B GetSomething() - { - return new B(); - } + public B GetSomething() => new B(); } // class ProgStubClass { - public static void Main() {} -} \ No newline at end of file + public static void Main() { } +} diff --git a/snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs b/snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs index 0048d76a9dc..ce178bbc8e8 100644 --- a/snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs +++ b/snippets/csharp/System/Type/GetArrayRank/type_getarrayrank.cs @@ -7,19 +7,19 @@ public static void Main() { try { - int[,,] myArray = new int[,,] {{{12,2,35},{300,78,33}},{{92,42,135},{30,7,3}}}; + int[,,] myArray = new int[,,] { { { 12, 2, 35 }, { 300, 78, 33 } }, { { 92, 42, 135 }, { 30, 7, 3 } } }; Type myType = myArray.GetType(); Console.WriteLine("Contents of myArray: {{{12,2,35},{300,78,33}},{{92,42,135},{30,7,3}}}"); - Console.WriteLine("myArray has {0} dimensions.", myType.GetArrayRank()); + Console.WriteLine($"myArray has {myType.GetArrayRank()} dimensions."); } - catch(NotSupportedException e) + catch (NotSupportedException e) { Console.WriteLine("NotSupportedException raised."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception raised."); Console.WriteLine("Source: " + e.Source); diff --git a/snippets/csharp/System/Type/GetConstructors/source1.cs b/snippets/csharp/System/Type/GetConstructors/source1.cs index 64bca042ab6..d4fb3c07cce 100644 --- a/snippets/csharp/System/Type/GetConstructors/source1.cs +++ b/snippets/csharp/System/Type/GetConstructors/source1.cs @@ -1,19 +1,22 @@ // - using System; - using System.Reflection; +using System; +using System.Reflection; - public class t { - public t() {} - static t() {} - public t(int i) {} +public class t +{ + public t() { } + static t() { } + public t(int i) { } - public static void Main() { - ConstructorInfo[] p = typeof(t).GetConstructors(); - Console.WriteLine(p.Length); + public static void Main() + { + ConstructorInfo[] p = typeof(t).GetConstructors(); + Console.WriteLine(p.Length); - for (int i=0;i diff --git a/snippets/csharp/System/Type/GetConstructors/source2.cs b/snippets/csharp/System/Type/GetConstructors/source2.cs index 4a8a66813cd..8ae22826118 100644 --- a/snippets/csharp/System/Type/GetConstructors/source2.cs +++ b/snippets/csharp/System/Type/GetConstructors/source2.cs @@ -1,21 +1,24 @@ // - using System; - using System.Reflection; +using System; +using System.Reflection; - public class t { - public t() {} - static t() {} - public t(int i) {} +public class t +{ + public t() { } + static t() { } + public t(int i) { } - public static void Main() { - ConstructorInfo[] p = typeof(t).GetConstructors( - BindingFlags.Public | BindingFlags.Static | - BindingFlags.NonPublic | BindingFlags.Instance); - Console.WriteLine(p.Length); + public static void Main() + { + ConstructorInfo[] p = typeof(t).GetConstructors( + BindingFlags.Public | BindingFlags.Static | + BindingFlags.NonPublic | BindingFlags.Instance); + Console.WriteLine(p.Length); - for (int i=0;i diff --git a/snippets/csharp/System/Type/GetDefaultMembers/source2.cs b/snippets/csharp/System/Type/GetDefaultMembers/source2.cs index e5be6267577..7bc4770e6c5 100644 --- a/snippets/csharp/System/Type/GetDefaultMembers/source2.cs +++ b/snippets/csharp/System/Type/GetDefaultMembers/source2.cs @@ -15,15 +15,9 @@ public Class1() sval = "6040"; } - public int GetIVal() - { - return ival; - } + public int GetIVal() => ival; - public string GetSVal() - { - return sval; - } + public string GetSVal() => sval; } // @@ -32,10 +26,10 @@ public class GetMemberExample public static void Main() { // - Class1 c = new Class1(); + Class1 c = new(); object o; o = c.GetType().InvokeMember("", BindingFlags.InvokeMethod, null, c, new object[0]); - Console.WriteLine("Default member result: {0}", o); + Console.WriteLine($"Default member result: {o}"); // GetDefMemberExample1(); @@ -52,9 +46,9 @@ public static void GetDefMemberExample1() (DefaultMemberAttribute)Attribute.GetCustomAttribute((MemberInfo)classType, attribType); MemberInfo[] memInfo = classType.GetMember(defMem.MemberName); // - if ( memInfo.Length > 0) + if (memInfo.Length > 0) { - Console.WriteLine("Default Member: {0}", memInfo[0].Name); + Console.WriteLine($"Default Member: {memInfo[0].Name}"); } } @@ -64,9 +58,9 @@ public static void GetDefMemberExample2() Type t = typeof(Class1); MemberInfo[] memInfo = t.GetDefaultMembers(); // - if ( memInfo.Length > 0) + if (memInfo.Length > 0) { - Console.WriteLine("Default Member: {0}", memInfo[0].Name); + Console.WriteLine($"Default Member: {memInfo[0].Name}"); } } @@ -81,7 +75,7 @@ public static void GetDefMemberExample3() MemberInfo[] memInfo = t.GetMember(defMem.MemberName); if (memInfo.Length > 0) { - Console.WriteLine("Default Member: {0}", memInfo[0].Name); + Console.WriteLine($"Default Member: {memInfo[0].Name}"); } } // diff --git a/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs b/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs index 11ac59b32f6..8b419322a02 100644 --- a/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs +++ b/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs @@ -6,23 +6,17 @@ [DefaultMemberAttribute("Age")] public class MyClass { - public void Name(String s) {} - public int Age - { - get - { - return 20; - } - } + public void Name(string s) { } + public int Age => 20; public static void Main() { try { - Type myType = typeof(MyClass); + Type myType = typeof(MyClass); MemberInfo[] memberInfoArray = myType.GetDefaultMembers(); if (memberInfoArray.Length > 0) { - foreach(MemberInfo memberInfoObj in memberInfoArray) + foreach (MemberInfo memberInfoObj in memberInfoArray) { Console.WriteLine("The default member name is: " + memberInfoObj.ToString()); } @@ -32,18 +26,18 @@ public static void Main() Console.WriteLine("No default members are available."); } } - catch(InvalidOperationException e) + catch (InvalidOperationException e) { Console.WriteLine("InvalidOperationException: " + e.Message); } - catch(IOException e) + catch (IOException e) { Console.WriteLine("IOException: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs b/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs index fa98300952f..a14ca67e520 100644 --- a/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs +++ b/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs @@ -4,14 +4,14 @@ class TestGetElementType { public static void Main() { - int[] array = {1,2,3}; + int[] array = { 1, 2, 3 }; Type t = array.GetType(); Type t2 = t.GetElementType(); - Console.WriteLine("The element type of {0} is {1}.",array, t2.ToString()); - TestGetElementType newMe = new TestGetElementType(); + Console.WriteLine($"The element type of {array} is {t2.ToString()}."); + TestGetElementType newMe = new(); t = newMe.GetType(); t2 = t.GetElementType(); - Console.WriteLine("The element type of {0} is {1}.", newMe, t2==null? "null" : t2.ToString()); + Console.WriteLine($"The element type of {newMe} is {(t2 == null ? "null" : t2.ToString())}."); } } @@ -20,4 +20,4 @@ public static void Main() The element type of System.Int32[] is System.Int32. The element type of TestGetElementType is null. */ -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent.cs b/snippets/csharp/System/Type/GetEvent/type_getevent.cs index 159dad978ab..276518eadde 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent.cs @@ -12,7 +12,7 @@ public static void Main() Type myType = typeof(System.Windows.Forms.Button); EventInfo myEvent = myType.GetEvent("Click"); - if(myEvent != null) + if (myEvent != null) { Console.WriteLine("Looking for the Click event in the Button class."); Console.WriteLine(myEvent.ToString()); @@ -22,19 +22,19 @@ public static void Main() Console.WriteLine("The Click event is not available in the Button class."); } } - catch(SecurityException e) + catch (SecurityException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message :"+e.Message); + Console.WriteLine("Message :" + e.Message); } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message :"+e.Message); + Console.WriteLine("Message :" + e.Message); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("The following exception was raised : {0}",e.Message); + Console.WriteLine($"The following exception was raised : {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs index 336fb59f405..e140ca49f54 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs @@ -14,7 +14,7 @@ public static void Main() BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; Type myTypeBindingFlags = typeof(System.Windows.Forms.Button); EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags); - if(myEventBindingFlags != null) + if (myEventBindingFlags != null) { Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags."); Console.WriteLine(myEventBindingFlags.ToString()); @@ -24,19 +24,19 @@ public static void Main() Console.WriteLine("The Click event is not available with the Button class."); } } - catch(SecurityException e) + catch (SecurityException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message :"+e.Message); + Console.WriteLine("Message :" + e.Message); } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message :"+e.Message); + Console.WriteLine("Message :" + e.Message); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("The following exception was raised : {0}",e.Message); + Console.WriteLine($"The following exception was raised : {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs index 35382b881ce..8bc140dfcbb 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs @@ -19,18 +19,18 @@ public static void Main() Console.WriteLine(myEventsBindingFlags[index].ToString()); } } - catch(SecurityException e) + catch (SecurityException e) { Console.WriteLine("SecurityException :" + e.Message); } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException : " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception : " + e.Message); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs index 3ab6230ee4f..c733e6d7ebe 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs @@ -19,18 +19,18 @@ public static void Main() Console.WriteLine(myEventsBindingFlags[index].ToString()); } } - catch(SecurityException e) + catch (SecurityException e) { Console.WriteLine("SecurityException:" + e.Message); } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetField/type_getfield.cs b/snippets/csharp/System/Type/GetField/type_getfield.cs index fcd7cc1a842..8af2e2b7908 100644 --- a/snippets/csharp/System/Type/GetField/type_getfield.cs +++ b/snippets/csharp/System/Type/GetField/type_getfield.cs @@ -14,15 +14,12 @@ public class MyFieldClassB private string field = "B Field"; public string Field { - get - { - return field; - } + get => field; set { - if (field!=value) + if (field != value) { - field=value; + field = value; } } } @@ -32,8 +29,8 @@ public class MyFieldInfoClass { public static void Main() { - MyFieldClassB myFieldObjectB = new MyFieldClassB(); - MyFieldClassA myFieldObjectA = new MyFieldClassA(); + MyFieldClassB myFieldObjectB = new(); + MyFieldClassA myFieldObjectA = new(); Type myTypeA = typeof(MyFieldClassA); FieldInfo myFieldInfo = myTypeA.GetField("Field"); @@ -42,10 +39,8 @@ public static void Main() FieldInfo myFieldInfo1 = myTypeB.GetField("field", BindingFlags.NonPublic | BindingFlags.Instance); - Console.WriteLine("The value of the public field is: '{0}'", - myFieldInfo.GetValue(myFieldObjectA)); - Console.WriteLine("The value of the private field is: '{0}'", - myFieldInfo1.GetValue(myFieldObjectB)); + Console.WriteLine($"The value of the public field is: '{myFieldInfo.GetValue(myFieldObjectA)}'"); + Console.WriteLine($"The value of the private field is: '{myFieldInfo1.GetValue(myFieldObjectB)}'"); } } // diff --git a/snippets/csharp/System/Type/GetFields/fieldinfo_isspecialname.cs b/snippets/csharp/System/Type/GetFields/fieldinfo_isspecialname.cs index 7b01efe830f..577256cc55a 100644 --- a/snippets/csharp/System/Type/GetFields/fieldinfo_isspecialname.cs +++ b/snippets/csharp/System/Type/GetFields/fieldinfo_isspecialname.cs @@ -16,20 +16,19 @@ public static void Main() FieldInfo[] myField = myType.GetFields(); Console.WriteLine("\nDisplaying fields that have SpecialName attributes:\n"); - for(int i = 0; i < myField.Length; i++) + for (int i = 0; i < myField.Length; i++) { // Determine whether or not each field is a special name. - if(myField[i].IsSpecialName) + if (myField[i].IsSpecialName) { - Console.WriteLine("The field {0} has a SpecialName attribute.", - myField[i].Name); + Console.WriteLine($"The field {myField[i].Name} has a SpecialName attribute."); } } } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("Exception : {0} " , e.Message); + Console.WriteLine($"Exception : {e.Message} "); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetFields/source.cs b/snippets/csharp/System/Type/GetFields/source.cs index 3de817ec246..6f11b871149 100644 --- a/snippets/csharp/System/Type/GetFields/source.cs +++ b/snippets/csharp/System/Type/GetFields/source.cs @@ -1,18 +1,15 @@ -// +// using System; using System.Reflection; class AttributesSample { - public void Mymethod (int int1m, out string str2m, ref string str3m) - { - str2m = "in Mymethod"; - } + public void Mymethod(int int1m, out string str2m, ref string str3m) => str2m = "in Mymethod"; public static int Main(string[] args) { - Console.WriteLine ("Reflection.MethodBase.Attributes Sample"); + Console.WriteLine("Reflection.MethodBase.Attributes Sample"); // Get the type. Type MyType = Type.GetType("AttributesSample"); @@ -27,7 +24,7 @@ public static int Main(string[] args) MethodAttributes Myattributes = Mymethodbase.Attributes; // Display the flags that are set. - PrintAttributes(typeof(System.Reflection.MethodAttributes), (int) Myattributes); + PrintAttributes(typeof(System.Reflection.MethodAttributes), (int)Myattributes); return 0; } diff --git a/snippets/csharp/System/Type/GetGenericArguments/source.cs b/snippets/csharp/System/Type/GetGenericArguments/source.cs index aff8b688c19..b129230bb08 100644 --- a/snippets/csharp/System/Type/GetGenericArguments/source.cs +++ b/snippets/csharp/System/Type/GetGenericArguments/source.cs @@ -1,19 +1,17 @@ // using System; -using System.Reflection; + using System.Collections.Generic; public class Test { private static void DisplayGenericTypeInfo(Type t) { - Console.WriteLine("\r\n{0}", t); + Console.WriteLine($"\r\n{t}"); - Console.WriteLine("\tIs this a generic type definition? {0}", - t.IsGenericTypeDefinition); + Console.WriteLine($"\tIs this a generic type definition? {t.IsGenericTypeDefinition}"); - Console.WriteLine("\tIs it a generic type? {0}", - t.IsGenericType); + Console.WriteLine($"\tIs it a generic type? {t.IsGenericType}"); // if (t.IsGenericType) @@ -22,8 +20,7 @@ private static void DisplayGenericTypeInfo(Type t) // Type[] typeArguments = t.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", - typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { @@ -32,13 +29,11 @@ private static void DisplayGenericTypeInfo(Type t) // if (tParam.IsGenericParameter) { - Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})", - tParam, - tParam.GenericParameterPosition); + Console.WriteLine($"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})"); } else { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } @@ -51,8 +46,8 @@ public static void Main() Console.WriteLine(" generic type definition, and an ordinary type."); // Create a Dictionary of Test objects, using strings for the - // keys. - Dictionary d = new Dictionary(); + // keys. + Dictionary d = new(); // Display information for the constructed type and its generic // type definition. diff --git a/snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs b/snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs index cb7b7df42ce..98438f97aba 100644 --- a/snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs +++ b/snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs @@ -1,6 +1,6 @@ // using System; -using System.Reflection; + using System.Collections.Generic; public class Test @@ -10,8 +10,8 @@ public static void Main() Console.WriteLine("\r\n--- Get the generic type that defines a constructed type."); // Create a Dictionary of Test objects, using strings for the - // keys. - Dictionary d = new Dictionary(); + // keys. + Dictionary d = new(); // Get a Type object representing the constructed type. // @@ -24,16 +24,14 @@ public static void Main() private static void DisplayTypeInfo(Type t) { - Console.WriteLine("\r\n{0}", t); - Console.WriteLine("\tIs this a generic type definition? {0}", - t.IsGenericTypeDefinition); - Console.WriteLine("\tIs it a generic type? {0}", - t.IsGenericType); + Console.WriteLine($"\r\n{t}"); + Console.WriteLine($"\tIs this a generic type definition? {t.IsGenericTypeDefinition}"); + Console.WriteLine($"\tIs it a generic type? {t.IsGenericType}"); Type[] typeArguments = t.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } diff --git a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs index 779f730e297..a1aea2695df 100644 --- a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs +++ b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs @@ -5,37 +5,36 @@ class FieldsSample { - public static void Main() + public static void Main() { Type myType = typeof(System.Net.IPAddress); - FieldInfo [] myFields = myType.GetFields(BindingFlags.Static | BindingFlags.NonPublic); - Console.WriteLine ("\nThe IPAddress class has the following nonpublic fields: "); + FieldInfo[] myFields = myType.GetFields(BindingFlags.Static | BindingFlags.NonPublic); + Console.WriteLine("\nThe IPAddress class has the following nonpublic fields: "); foreach (FieldInfo myField in myFields) { Console.WriteLine(myField.ToString()); } Type myType1 = typeof(System.Net.IPAddress); - FieldInfo [] myFields1 = myType1.GetFields(); - Console.WriteLine ("\nThe IPAddress class has the following public fields: "); + FieldInfo[] myFields1 = myType1.GetFields(); + Console.WriteLine("\nThe IPAddress class has the following public fields: "); foreach (FieldInfo myField in myFields1) { Console.WriteLine(myField.ToString()); } try { - Console.WriteLine("The HashCode of the System.Windows.Forms.Button type is: {0}", - typeof(System.Windows.Forms.Button).GetHashCode()); - } - catch(SecurityException e) + Console.WriteLine($"The HashCode of the System.Windows.Forms.Button type is: {typeof(System.Windows.Forms.Button).GetHashCode()}"); + } + catch (SecurityException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message: "+e.Message); + Console.WriteLine("Message: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Message: "+e.Message); - } + Console.WriteLine("Message: " + e.Message); + } } -} +} // diff --git a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs index 010de7d835e..79809770bc2 100644 --- a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs +++ b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs @@ -13,42 +13,42 @@ with the specified name. Then prints the method name of that interface. class MyInterfaceClass { -// -// -// + // + // + // public static void Main() { - Hashtable hashtableObj = new Hashtable(); + Hashtable hashtableObj = new(); Type objType = hashtableObj.GetType(); MethodInfo[] arrayMethodInfo; MemberInfo[] arrayMemberInfo; try { // Get the methods implemented in 'IDeserializationCallback' interface. - arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods(); - Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :"); - foreach(MethodInfo methodInfo in arrayMethodInfo) - Console.WriteLine (methodInfo); + arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods(); + Console.WriteLine("\nMethods of 'IDeserializationCallback' Interface :"); + foreach (MethodInfo methodInfo in arrayMethodInfo) + Console.WriteLine(methodInfo); // Get FullName for interface by using Ignore case search. - Console.WriteLine ("\nMethods of 'IEnumerable' Interface"); - arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods(); - foreach(MethodInfo methodInfo in arrayMethodInfo) - Console.WriteLine (methodInfo); + Console.WriteLine("\nMethods of 'IEnumerable' Interface"); + arrayMethodInfo = objType.GetInterface("ienumerable", true).GetMethods(); + foreach (MethodInfo methodInfo in arrayMethodInfo) + Console.WriteLine(methodInfo); //Get the Interface methods for 'IDictionary' interface InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary)); arrayMemberInfo = interfaceMappingObj.InterfaceMethods; - Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :"); - foreach(MemberInfo memberInfo in arrayMemberInfo) - Console.WriteLine (memberInfo); + Console.WriteLine("\nHashtable class Implements the following IDictionary Interface methods :"); + foreach (MemberInfo memberInfo in arrayMemberInfo) + Console.WriteLine(memberInfo); } catch (Exception e) { - Console.WriteLine ("Exception : " + e.ToString()); + Console.WriteLine("Exception : " + e.ToString()); } } -// -// -// + // + // + // } diff --git a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs index 1ce9ac58388..f21c29e20c2 100644 --- a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs +++ b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs @@ -5,26 +5,27 @@ public class Example { - public static void Main() - { - Type[] interf = { typeof(IFormatProvider), typeof(IAppDomainSetup) }; - Type[] impl = { typeof(CultureInfo), typeof(AppDomainSetup) }; + public static void Main() + { + Type[] interf = { typeof(IFormatProvider), typeof(IAppDomainSetup) }; + Type[] impl = { typeof(CultureInfo), typeof(AppDomainSetup) }; - for (int ctr = 0; ctr < interf.Length; ctr++) - ShowInterfaceMapping(interf[ctr], impl[ctr]); - } + for (int ctr = 0; ctr < interf.Length; ctr++) + ShowInterfaceMapping(interf[ctr], impl[ctr]); + } - private static void ShowInterfaceMapping(Type intType, Type implType) - { - InterfaceMapping map = implType.GetInterfaceMap(intType); - Console.WriteLine("Mapping of {0} to {1}: ", map.InterfaceType, map.TargetType); - for (int ctr = 0; ctr < map.InterfaceMethods.Length; ctr++) { - MethodInfo im = map.InterfaceMethods[ctr]; - MethodInfo tm = map.TargetMethods[ctr]; - Console.WriteLine(" {0} --> {1}", im.Name,tm.Name); - } - Console.WriteLine(); - } + private static void ShowInterfaceMapping(Type intType, Type implType) + { + InterfaceMapping map = implType.GetInterfaceMap(intType); + Console.WriteLine($"Mapping of {map.InterfaceType} to {map.TargetType}: "); + for (int ctr = 0; ctr < map.InterfaceMethods.Length; ctr++) + { + MethodInfo im = map.InterfaceMethods[ctr]; + MethodInfo tm = map.TargetMethods[ctr]; + Console.WriteLine($" {im.Name} --> {tm.Name}"); + } + Console.WriteLine(); + } } // The example displays the following output: // Mapping of System.IFormatProvider to System.Globalization.CultureInfo: diff --git a/snippets/csharp/System/Type/GetMember/type_getmember.cs b/snippets/csharp/System/Type/GetMember/type_getmember.cs index 745de08fe85..e6df4edaf53 100644 --- a/snippets/csharp/System/Type/GetMember/type_getmember.cs +++ b/snippets/csharp/System/Type/GetMember/type_getmember.cs @@ -8,32 +8,32 @@ public class MyMemberSample { public static void Main() { - MyMemberSample myClass = new MyMemberSample(); + MyMemberSample myClass = new(); try { myClass.GetMemberInfo(); - myClass.GetPublicStaticMemberInfo(); - myClass.GetPublicInstanceMethodMemberInfo(); + myClass.GetPublicStaticMemberInfo(); + myClass.GetPublicInstanceMethodMemberInfo(); } - catch(ArgumentNullException e) + catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException occurred."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } - catch(NotSupportedException e) + catch (NotSupportedException e) { Console.WriteLine("NotSupportedException occurred."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } - catch(SecurityException e) + catch (SecurityException e) { Console.WriteLine("SecurityException occurred."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("Exception occurred."); Console.WriteLine("Source: " + e.Source); @@ -43,16 +43,16 @@ public static void Main() public void GetMemberInfo() { - String myString = "GetMember_String"; + string myString = "GetMember_String"; Type myType = myString.GetType(); // Get the members for myString starting with the letter C. MemberInfo[] myMembers = myType.GetMember("C*"); - if(myMembers.Length > 0) + if (myMembers.Length > 0) { - Console.WriteLine("\nThe member(s) starting with the letter C for type {0}:", myType); - for(int index=0; index < myMembers.Length; index++) - Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString()); + Console.WriteLine($"\nThe member(s) starting with the letter C for type {myType}:"); + for (int index = 0; index < myMembers.Length; index++) + Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); } else { @@ -64,16 +64,16 @@ public void GetMemberInfo() // public void GetPublicStaticMemberInfo() { - String myString = "GetMember_String_BindingFlag"; + string myString = "GetMember_String_BindingFlag"; Type myType = myString.GetType(); // Get the public static members for the class myString starting with the letter C. MemberInfo[] myMembers = myType.GetMember("C*", - BindingFlags.Public |BindingFlags.Static); - if(myMembers.Length > 0) + BindingFlags.Public | BindingFlags.Static); + if (myMembers.Length > 0) { - Console.WriteLine("\nThe public static member(s) starting with the letter C for type {0}:", myType); - for(int index=0; index < myMembers.Length; index++) - Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString()); + Console.WriteLine($"\nThe public static member(s) starting with the letter C for type {myType}:"); + for (int index = 0; index < myMembers.Length; index++) + Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); } else { @@ -85,16 +85,16 @@ public void GetPublicStaticMemberInfo() // public void GetPublicInstanceMethodMemberInfo() { - String myString = "GetMember_String_MemberType_BindingFlag"; + string myString = "GetMember_String_MemberType_BindingFlag"; Type myType = myString.GetType(); // Get the public instance methods for myString starting with the letter C. MemberInfo[] myMembers = myType.GetMember("C*", MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance); - if(myMembers.Length > 0) + if (myMembers.Length > 0) { - Console.WriteLine("\nThe public instance method(s) starting with the letter C for type {0}:", myType); - for(int index=0; index < myMembers.Length; index++) - Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString()); + Console.WriteLine($"\nThe public instance method(s) starting with the letter C for type {myType}:"); + for (int index = 0; index < myMembers.Length; index++) + Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); } else { @@ -102,4 +102,4 @@ public void GetPublicInstanceMethodMemberInfo() } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs b/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs index 370d3130ecb..98c0a533269 100644 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs @@ -13,43 +13,43 @@ of the class 'MyClass' and displays the same to the console. // class MyClass { - public int myInt = 0; - public string myString = null; - - public MyClass() - { - } - public void Myfunction() - { - } + public int myInt = 0; + public string myString = null; + + public MyClass() + { + } + public void Myfunction() + { + } } class Type_GetMembers { - public static void Main() - { - try - { - MyClass myObject = new MyClass(); - MemberInfo[] myMemberInfo; - - // Get the type of 'MyClass'. - Type myType = myObject.GetType(); - - // Get the information related to all public member's of 'MyClass'. - myMemberInfo = myType.GetMembers(); - - Console.WriteLine( "\nThe members of class '{0}' are :\n", myType); - for (int i =0 ; i < myMemberInfo.Length ; i++) - { - // Display name and type of the concerned member. - Console.WriteLine( "'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType); - } - } - catch(SecurityException e) - { - Console.WriteLine("Exception : " + e.Message ); - } - } + public static void Main() + { + try + { + MyClass myObject = new(); + MemberInfo[] myMemberInfo; + + // Get the type of 'MyClass'. + Type myType = myObject.GetType(); + + // Get the information related to all public member's of 'MyClass'. + myMemberInfo = myType.GetMembers(); + + Console.WriteLine($"\nThe members of class '{myType}' are :\n"); + for (int i = 0; i < myMemberInfo.Length; i++) + { + // Display name and type of the concerned member. + Console.WriteLine($"'{myMemberInfo[i].Name}' is a {myMemberInfo[i].MemberType}"); + } + } + catch (SecurityException e) + { + Console.WriteLine("Exception : " + e.Message); + } + } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs b/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs index 5c51ce13c01..14998f975df 100644 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs @@ -15,56 +15,56 @@ the console. class MyClass { - public int myInt = 0; - public string myString = null; + public int myInt = 0; + public string myString = null; - public MyClass() - { - } - public void Myfunction() - { - } + public MyClass() + { + } + public void Myfunction() + { + } } class Type_GetMembers_BindingFlags { - public static void Main() - { - try - { - MyClass MyObject = new MyClass(); - MemberInfo [] myMemberInfo; + public static void Main() + { + try + { + MyClass MyObject = new(); + MemberInfo[] myMemberInfo; - // Get the type of the class 'MyClass'. - Type myType = MyObject.GetType(); + // Get the type of the class 'MyClass'. + Type myType = MyObject.GetType(); - // Get the public instance members of the class 'MyClass'. - myMemberInfo = myType.GetMembers(BindingFlags.Public|BindingFlags.Instance); + // Get the public instance members of the class 'MyClass'. + myMemberInfo = myType.GetMembers(BindingFlags.Public | BindingFlags.Instance); - Console.WriteLine( "\nThe public instance members of class '{0}' are : \n", myType); - for (int i =0 ; i < myMemberInfo.Length ; i++) - { - // Display name and type of the member of 'MyClass'. - Console.WriteLine( "'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType); - } - } - catch (SecurityException e) - { - Console.WriteLine("SecurityException : " + e.Message ); - } + Console.WriteLine($"\nThe public instance members of class '{myType}' are : \n"); + for (int i = 0; i < myMemberInfo.Length; i++) + { + // Display name and type of the member of 'MyClass'. + Console.WriteLine($"'{myMemberInfo[i].Name}' is a {myMemberInfo[i].MemberType}"); + } + } + catch (SecurityException e) + { + Console.WriteLine("SecurityException : " + e.Message); + } - //Output: - //The public instance members of class 'MyClass' are : + //Output: + //The public instance members of class 'MyClass' are : - //'Myfunction' is a Method - //'ToString' is a Method - //'Equals' is a Method - //'GetHashCode' is a Method - //'GetType' is a Method - //'.ctor' is a Constructor - //'myInt' is a Field - //'myString' is a Field - } + //'Myfunction' is a Method + //'ToString' is a Method + //'Equals' is a Method + //'GetHashCode' is a Method + //'GetType' is a Method + //'.ctor' is a Constructor + //'myInt' is a Field + //'myString' is a Field + } } // diff --git a/snippets/csharp/System/Type/GetMethod/GetMethod1.cs b/snippets/csharp/System/Type/GetMethod/GetMethod1.cs index f1fea4624d6..638f394e65e 100644 --- a/snippets/csharp/System/Type/GetMethod/GetMethod1.cs +++ b/snippets/csharp/System/Type/GetMethod/GetMethod1.cs @@ -6,53 +6,55 @@ public class Example { - public static void Main() - { - // Get a Type object that represents a non-generic type. - GetAddMethod(typeof(ArrayList)); + public static void Main() + { + // Get a Type object that represents a non-generic type. + GetAddMethod(typeof(ArrayList)); - var list = new List(); - // Get a Type object that represents a constructed generic type. - Type closed = list.GetType(); - GetAddMethod(closed); - - // Get a Type object that represents an open generic type. - Type open = typeof(List<>); - GetAddMethod(open); - } + var list = new List(); + // Get a Type object that represents a constructed generic type. + Type closed = list.GetType(); + GetAddMethod(closed); - private static void GetAddMethod(Type typ) - { - MethodInfo method; - // Determine if this is a generic type. - if (typ.IsGenericType) { - // Is it an open generic type? - if (typ.ContainsGenericParameters) - method = typ.GetMethod("Add", typ.GetGenericArguments()); - // Get closed generic type arguments. - else - method = typ.GetMethod("Add", typ.GenericTypeArguments); - } - // This is not a generic type. - else { - method = typ.GetMethod("Add", new Type[] { typeof(Object) } ); - } + // Get a Type object that represents an open generic type. + Type open = typeof(List<>); + GetAddMethod(open); + } - // Test if an Add method was found. - if (method == null) { - Console.WriteLine("No Add method found."); - return; - } - - Type t = method.ReflectedType; - Console.Write("{0}.{1}.{2}(", t.Namespace, t.Name, method.Name); - ParameterInfo[] parms = method.GetParameters(); - for (int ctr = 0; ctr < parms.Length; ctr++) - Console.Write("{0}{1}", parms[ctr].ParameterType.Name, - ctr < parms.Length - 1 ? ", " : ""); + private static void GetAddMethod(Type typ) + { + MethodInfo method; + // Determine if this is a generic type. + if (typ.IsGenericType) + { + // Is it an open generic type? + if (typ.ContainsGenericParameters) + method = typ.GetMethod("Add", typ.GetGenericArguments()); + // Get closed generic type arguments. + else + method = typ.GetMethod("Add", typ.GenericTypeArguments); + } + // This is not a generic type. + else + { + method = typ.GetMethod("Add", new Type[] { typeof(object) }); + } - Console.WriteLine(")"); - } + // Test if an Add method was found. + if (method == null) + { + Console.WriteLine("No Add method found."); + return; + } + + Type t = method.ReflectedType; + Console.Write($"{t.Namespace}.{t.Name}.{method.Name}("); + ParameterInfo[] parms = method.GetParameters(); + for (int ctr = 0; ctr < parms.Length; ctr++) + Console.Write($"{parms[ctr].ParameterType.Name}{(ctr < parms.Length - 1 ? ", " : "")}"); + + Console.WriteLine(")"); + } } // The example displays the following output: // System.Collections.ArrayList.Add(Object) diff --git a/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs b/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs index e54e8d6d12a..3c6b0b60463 100644 --- a/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs +++ b/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs @@ -4,25 +4,13 @@ public class TestClass { - public void DisplayValue(String s) - { - Console.WriteLine(s); - } + public void DisplayValue(string s) => Console.WriteLine(s); - public void DisplayValue(String s, params Object[] values) - { - Console.WriteLine(s, values); - } + public void DisplayValue(string s, params object[] values) => Console.WriteLine(s, values); - public static bool Equals(TestClass t1, TestClass t2) - { - return Object.ReferenceEquals(t1, t2); - } + public static bool Equals(TestClass t1, TestClass t2) => object.ReferenceEquals(t1, t2); - public bool Equals(TestClass t) - { - return Object.ReferenceEquals(this, t); - } + public bool Equals(TestClass t) => object.ReferenceEquals(this, t); } public class Example1 @@ -40,14 +28,14 @@ public static void Main() RetrieveMethod(t, "Equals", BindingFlags.Public | BindingFlags.Static); } - private static void RetrieveMethod(Type t, String name, BindingFlags flags) + private static void RetrieveMethod(Type t, string name, BindingFlags flags) { try { MethodInfo m = t.GetMethod(name, flags); if (m != null) { - Console.Write("{0}.{1}(", t.Name, m.Name); + Console.Write($"{t.Name}.{m.Name}("); ParameterInfo[] parms = m.GetParameters(); for (int ctr = 0; ctr < parms.Length; ctr++) { @@ -70,7 +58,7 @@ private static void RetrieveMethod(Type t, String name, BindingFlags flags) { if (method.Name != name) continue; - Console.Write(" {0}.{1}(", t.Name, method.Name); + Console.Write($" {t.Name}.{method.Name}("); ParameterInfo[] parms = method.GetParameters(); for (int ctr = 0; ctr < parms.Length; ctr++) { @@ -88,12 +76,12 @@ private static void RetrieveMethod(Type t, String name, BindingFlags flags) // The following duplicate matches were found: // TestClass.DisplayValue(String) // TestClass.DisplayValue(String, Object[]) -// +// // The following duplicate matches were found: // TestClass.Equals(TestClass) // TestClass.Equals(Object) -// +// // TestClass.Equals(TestClass) -// +// // TestClass.Equals(TestClass, TestClass) // diff --git a/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs b/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs index a20302fe188..76fee533016 100644 --- a/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs +++ b/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs @@ -4,13 +4,10 @@ public class Person { - public String FirstName; - public String LastName; + public string FirstName; + public string LastName; - public override String ToString() - { - return (FirstName + " " + LastName).Trim(); - } + public override string ToString() => (FirstName + " " + LastName).Trim(); } public class Example2 @@ -20,25 +17,23 @@ public static void Main() Type t = typeof(Person); RetrieveMethod(t, "ToString"); - t = typeof(Int32); + t = typeof(int); RetrieveMethod(t, "ToString"); } - private static void RetrieveMethod(Type t, String name) + private static void RetrieveMethod(Type t, string name) { try { MethodInfo m = t.GetMethod(name); if (m != null) - Console.WriteLine("{0}.{1}: {2} method", m.ReflectedType.Name, - m.Name, m.IsStatic ? "Static" : "Instance"); + Console.WriteLine($"{m.ReflectedType.Name}.{m.Name}: {(m.IsStatic ? "Static" : "Instance")} method"); else - Console.WriteLine("{0}.ToString method not found", t.Name); + Console.WriteLine($"{t.Name}.ToString method not found"); } catch (AmbiguousMatchException) { - Console.WriteLine("{0}.{1} has multiple public overloads.", - t.Name, name); + Console.WriteLine($"{t.Name}.{name} has multiple public overloads."); } } } diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod1.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod1.cs index daa6c4a49ff..02904730e99 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod1.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod1.cs @@ -14,7 +14,7 @@ static void Main(string[] args) // Get MethodA() MethodInfo mInfo = typeof(Program).GetMethod("MethodA"); - Console.WriteLine("Found method: {0}", mInfo); + Console.WriteLine($"Found method: {mInfo}"); } } // diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod2.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod2.cs index 90bca4d28cb..2b71ad9dbd6 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod2.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod2.cs @@ -12,7 +12,7 @@ static void Main(string[] args) // Get MethodA() MethodInfo mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance); - Console.WriteLine("Found method: {0}", mInfo); + Console.WriteLine($"Found method: {mInfo}"); } } // diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs index 71abd1f72aa..27fec6818c1 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs @@ -13,59 +13,59 @@ public void MethodA(int[] i) { } public unsafe void MethodA(int* i) { } - public void MethodA(ref int r) {} + public void MethodA(ref int r) { } // Method that takes an out parameter: - public void MethodA(int i, out int o) { o = 100;} + public void MethodA(int i, out int o) => o = 100; - static void Main(string[] args) - { - MethodInfo mInfo; + static void Main(string[] args) + { + MethodInfo mInfo; - // Get MethodA(int i, int j) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - CallingConventions.Any, - new Type[] { typeof(int), typeof(int) }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int i, int j) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + CallingConventions.Any, + new Type[] { typeof(int), typeof(int) }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int[] i) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - CallingConventions.Any, - new Type[] { typeof(int[]) }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int[] i) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + CallingConventions.Any, + new Type[] { typeof(int[]) }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int* i) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - CallingConventions.Any, - new Type[] { typeof(int).MakePointerType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int* i) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + CallingConventions.Any, + new Type[] { typeof(int).MakePointerType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(ref int r) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - CallingConventions.Any, - new Type[] { typeof(int).MakeByRefType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(ref int r) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + CallingConventions.Any, + new Type[] { typeof(int).MakeByRefType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int i, out int o) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - CallingConventions.Any, - new Type[] { typeof(int), typeof(int).MakeByRefType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); - } + // Get MethodA(int i, out int o) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + CallingConventions.Any, + new Type[] { typeof(int), typeof(int).MakeByRefType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); + } } // diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs index 9275c15de43..7877f930328 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs @@ -13,39 +13,39 @@ public void MethodA(int[] i) { } public unsafe void MethodA(int* i) { } - public void MethodA(ref int r) {} + public void MethodA(ref int r) { } // Method that takes an out parameter: - public void MethodA(int i, out int o) { o = 100;} - - static void Main(string[] args) - { - MethodInfo mInfo; - - // Get MethodA(int i, int i) - mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int), typeof(int) }); - Console.WriteLine("Found method: {0}", mInfo); - - // Get MethodA(int[] i) - mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int[]) }); - Console.WriteLine("Found method: {0}", mInfo); - - // Get MethodA(int* i) - mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int).MakePointerType() }); - Console.WriteLine("Found method: {0}", mInfo); - - // Get MethodA(ref int r) - mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int).MakeByRefType() }); - Console.WriteLine("Found method: {0}", mInfo); - - // Get MethodA(int i, out int o) - mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int), typeof(int).MakeByRefType() }); - Console.WriteLine("Found method: {0}", mInfo); - } + public void MethodA(int i, out int o) => o = 100; + + static void Main(string[] args) + { + MethodInfo mInfo; + + // Get MethodA(int i, int i) + mInfo = typeof(Program).GetMethod("MethodA", + new Type[] { typeof(int), typeof(int) }); + Console.WriteLine($"Found method: {mInfo}"); + + // Get MethodA(int[] i) + mInfo = typeof(Program).GetMethod("MethodA", + new Type[] { typeof(int[]) }); + Console.WriteLine($"Found method: {mInfo}"); + + // Get MethodA(int* i) + mInfo = typeof(Program).GetMethod("MethodA", + new Type[] { typeof(int).MakePointerType() }); + Console.WriteLine($"Found method: {mInfo}"); + + // Get MethodA(ref int r) + mInfo = typeof(Program).GetMethod("MethodA", + new Type[] { typeof(int).MakeByRefType() }); + Console.WriteLine($"Found method: {mInfo}"); + + // Get MethodA(int i, out int o) + mInfo = typeof(Program).GetMethod("MethodA", + new Type[] { typeof(int), typeof(int).MakeByRefType() }); + Console.WriteLine($"Found method: {mInfo}"); + } } // diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs index bdd2e23efcb..56d72d7fd0c 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs @@ -13,54 +13,54 @@ public void MethodA(int[] i) { } public unsafe void MethodA(int* i) { } - public void MethodA(ref int r) {} + public void MethodA(ref int r) { } // Method that takes an out parameter. - public void MethodA(int i, out int o) { o = 100; } + public void MethodA(int i, out int o) => o = 100; - static void Main(string[] args) - { - MethodInfo mInfo; + static void Main(string[] args) + { + MethodInfo mInfo; - // Get MethodA(int i, int j) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - new Type[] { typeof(int), typeof(int) }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int i, int j) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + new Type[] { typeof(int), typeof(int) }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int[] i) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - new Type[] { typeof(int[]) }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int[] i) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + new Type[] { typeof(int[]) }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int* i) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - new Type[] { typeof(int).MakePointerType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(int* i) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + new Type[] { typeof(int).MakePointerType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(ref int r) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - new Type[] { typeof(int).MakeByRefType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); + // Get MethodA(ref int r) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + new Type[] { typeof(int).MakeByRefType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); - // Get MethodA(int i, out int o) - mInfo = typeof(Program).GetMethod("MethodA", - BindingFlags.Public | BindingFlags.Instance, - null, - new Type[] { typeof(int), typeof(int).MakeByRefType() }, - null); - Console.WriteLine("Found method: {0}", mInfo); - } + // Get MethodA(int i, out int o) + mInfo = typeof(Program).GetMethod("MethodA", + BindingFlags.Public | BindingFlags.Instance, + null, + new Type[] { typeof(int), typeof(int).MakeByRefType() }, + null); + Console.WriteLine($"Found method: {mInfo}"); + } } // diff --git a/snippets/csharp/System/Type/GetMethods/type_getmethods2.cs b/snippets/csharp/System/Type/GetMethods/type_getmethods2.cs index f50aed0e5f4..952b4f26bfc 100644 --- a/snippets/csharp/System/Type/GetMethods/type_getmethods2.cs +++ b/snippets/csharp/System/Type/GetMethods/type_getmethods2.cs @@ -1,7 +1,7 @@ // using System; using System.Reflection; -using System.Reflection.Emit; + // Create a class having two public methods and one protected method. public class MyTypeClass @@ -9,38 +9,32 @@ public class MyTypeClass public void MyMethods() { } - public int MyMethods1() - { - return 3; - } - protected String MyMethods2() - { - return "hello"; - } + public int MyMethods1() => 3; + protected string MyMethods2() => "hello"; } public class TypeMain { public static void Main() { - Type myType =(typeof(MyTypeClass)); + Type myType = (typeof(MyTypeClass)); // Get the public methods. - MethodInfo[] myArrayMethodInfo = myType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly); - Console.WriteLine("\nThe number of public methods is {0}.", myArrayMethodInfo.Length); + MethodInfo[] myArrayMethodInfo = myType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + Console.WriteLine($"\nThe number of public methods is {myArrayMethodInfo.Length}."); // Display all the methods. DisplayMethodInfo(myArrayMethodInfo); // Get the nonpublic methods. - MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly); - Console.WriteLine("\nThe number of protected methods is {0}.", myArrayMethodInfo1.Length); + MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); + Console.WriteLine($"\nThe number of protected methods is {myArrayMethodInfo1.Length}."); // Display information for all methods. - DisplayMethodInfo(myArrayMethodInfo1); + DisplayMethodInfo(myArrayMethodInfo1); } public static void DisplayMethodInfo(MethodInfo[] myArrayMethodInfo) { // Display information for all methods. - for(int i=0;i \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs b/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs index 0815b133ce2..8cae9b676a7 100644 --- a/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs +++ b/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs @@ -1,15 +1,15 @@ // using System; -using System.Reflection; + public class MyClass { public class NestClass { - public static int myPublicInt=0; + public static int myPublicInt = 0; } public struct NestStruct { - public static int myPublicInt=0; + public static int myPublicInt = 0; } } @@ -20,16 +20,16 @@ public static void Main() try { // Get the Type object corresponding to MyClass. - Type myType=typeof(MyClass); + Type myType = typeof(MyClass); // Get an array of nested type objects in MyClass. - Type[] nestType=myType.GetNestedTypes(); - Console.WriteLine("The number of nested types is {0}.", nestType.Length); - foreach(Type t in nestType) - Console.WriteLine("Nested type is {0}.", t.ToString()); + Type[] nestType = myType.GetNestedTypes(); + Console.WriteLine($"The number of nested types is {nestType.Length}."); + foreach (Type t in nestType) + Console.WriteLine($"Nested type is {t.ToString()}."); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("Error"+e.Message); + Console.WriteLine("Error" + e.Message); } } } diff --git a/snippets/csharp/System/Type/GetProperties/type_getproperties2.cs b/snippets/csharp/System/Type/GetProperties/type_getproperties2.cs index 0ccfc43b7ee..0296cbaba17 100644 --- a/snippets/csharp/System/Type/GetProperties/type_getproperties2.cs +++ b/snippets/csharp/System/Type/GetProperties/type_getproperties2.cs @@ -5,35 +5,17 @@ // Create a class having six properties. public class PropertyClass { - public String Property1 - { - get { return "hello"; } - } + public string Property1 => "hello"; - public String Property2 - { - get { return "hello"; } - } + public string Property2 => "hello"; - protected String Property3 - { - get { return "hello"; } - } + protected string Property3 => "hello"; - private Int32 Property4 - { - get { return 32; } - } + private int Property4 => 32; - internal String Property5 - { - get { return "value"; } - } + internal string Property5 => "value"; - protected internal String Property6 - { - get { return "value"; } - } + protected internal string Property6 => "value"; } public class Example @@ -42,16 +24,14 @@ public static void Main() { Type t = typeof(PropertyClass); // Get the public properties. - PropertyInfo[] propInfos = t.GetProperties(BindingFlags.Public|BindingFlags.Instance); - Console.WriteLine("The number of public properties: {0}.\n", - propInfos.Length); + PropertyInfo[] propInfos = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); + Console.WriteLine($"The number of public properties: {propInfos.Length}.\n"); // Display the public properties. DisplayPropertyInfo(propInfos); // Get the nonpublic properties. - PropertyInfo[] propInfos1 = t.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance); - Console.WriteLine("The number of non-public properties: {0}.\n", - propInfos1.Length); + PropertyInfo[] propInfos1 = t.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance); + Console.WriteLine($"The number of non-public properties: {propInfos1.Length}.\n"); // Display all the nonpublic properties. DisplayPropertyInfo(propInfos1); } @@ -59,39 +39,40 @@ public static void Main() public static void DisplayPropertyInfo(PropertyInfo[] propInfos) { // Display information for all properties. - foreach (var propInfo in propInfos) { + foreach (var propInfo in propInfos) + { bool readable = propInfo.CanRead; bool writable = propInfo.CanWrite; - Console.WriteLine(" Property name: {0}", propInfo.Name); - Console.WriteLine(" Property type: {0}", propInfo.PropertyType); - Console.WriteLine(" Read-Write: {0}", readable & writable); - if (readable) { - MethodInfo getAccessor = propInfo.GetMethod; - Console.WriteLine(" Visibility: {0}", - GetVisibility(getAccessor)); + Console.WriteLine($" Property name: {propInfo.Name}"); + Console.WriteLine($" Property type: {propInfo.PropertyType}"); + Console.WriteLine($" Read-Write: {readable & writable}"); + if (readable) + { + MethodInfo getAccessor = propInfo.GetMethod; + Console.WriteLine($" Visibility: {GetVisibility(getAccessor)}"); } - if (writable) { - MethodInfo setAccessor = propInfo.SetMethod; - Console.WriteLine(" Visibility: {0}", - GetVisibility(setAccessor)); + if (writable) + { + MethodInfo setAccessor = propInfo.SetMethod; + Console.WriteLine($" Visibility: {GetVisibility(setAccessor)}"); } Console.WriteLine(); } } - public static String GetVisibility(MethodInfo accessor) + public static string GetVisibility(MethodInfo accessor) { - if (accessor.IsPublic) - return "Public"; - else if (accessor.IsPrivate) - return "Private"; - else if (accessor.IsFamily) - return "Protected"; - else if (accessor.IsAssembly) - return "Internal/Friend"; - else - return "Protected Internal/Friend"; + if (accessor.IsPublic) + return "Public"; + else if (accessor.IsPrivate) + return "Private"; + else if (accessor.IsFamily) + return "Protected"; + else if (accessor.IsAssembly) + return "Internal/Friend"; + else + return "Protected Internal/Friend"; } } // The example displays the following output: diff --git a/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs b/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs index ea1d3e67d35..6374d82f853 100644 --- a/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs +++ b/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs @@ -20,14 +20,14 @@ class MyClass { static void Main(string[] args) { -// + // // Create an object of 'Type' class. Type myType1 = Type.GetType("System.Int32"); // Get the 'TypeCode' of the 'Type' class object created above. TypeCode myTypeCode = Type.GetTypeCode(myType1); - Console.WriteLine("TypeCode is: {0}",myTypeCode); -// -// + Console.WriteLine($"TypeCode is: {myTypeCode}"); + // + // PropertyInfo[] myPropertyInfo; // Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties(); @@ -36,33 +36,33 @@ static void Main(string[] args) { Console.WriteLine(myPropertyInfo[i].ToString()); } -// -// - Object[] myObject = new Object[3]; + // + // + object[] myObject = new object[3]; myObject[0] = 66; myObject[1] = "puri"; myObject[2] = 33.33; // Get the array of 'Type' class objects. Type[] myTypeArray = Type.GetTypeArray(myObject); Console.WriteLine("Full names of the 'Type' objects in the array are:"); - for(int h = 0; h < myTypeArray.Length ; h++) + for (int h = 0; h < myTypeArray.Length; h++) { Console.WriteLine(myTypeArray[h].FullName); } -// -// + // + // try { // Throws 'TypeLoadException' because of case-sensitive search. - Type myType2 = Type.GetType("sYSTem.iNT32",true,false); + Type myType2 = Type.GetType("sYSTem.iNT32", true, false); Console.WriteLine(myType2.FullName); } - catch(TypeLoadException e) + catch (TypeLoadException e) { Console.WriteLine(e.Message); } -// - catch(Exception e) + // + catch (Exception e) { Console.WriteLine(e.Message); } diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty1.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty1.cs index c1d1196f3c8..60794e62ad2 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty1.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty1.cs @@ -21,7 +21,7 @@ public static void Main(string[] args) PropertyInfo myPropInfo = myType.GetProperty("MyProperty"); // Display the property name. - Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.Name); + Console.WriteLine($"The {myPropInfo.Name} property exists in MyClass1."); } catch (NullReferenceException e) { diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty2.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty2.cs index 6d5fdbebbba..f543aa0017b 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty2.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty2.cs @@ -25,7 +25,7 @@ public static void Main(string[] args) ); // Display Name property to console. - Console.WriteLine("{0} is a property of MyClass2.", myPropInfo.Name); + Console.WriteLine($"{myPropInfo.Name} is a property of MyClass2."); } catch (NullReferenceException e) { diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty21.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty21.cs index 5f7ee5d3e84..4279b28123f 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty21.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty21.cs @@ -4,18 +4,12 @@ public class MyPropertyClass { - private readonly int [,] _myPropertyArray = new int[10,10]; + private readonly int[,] _myPropertyArray = new int[10, 10]; // Declare an indexer. - public int this [int i,int j] + public int this[int i, int j] { - get - { - return _myPropertyArray[i,j]; - } - set - { - _myPropertyArray[i,j] = value; - } + get => _myPropertyArray[i, j]; + set => _myPropertyArray[i, j] = value; } } @@ -25,22 +19,22 @@ public static void Main() { try { - Type myType=typeof(MyPropertyClass); + Type myType = typeof(MyPropertyClass); Type[] myTypeArray = new Type[2]; // Create an instance of the Type array representing the number, order // and type of the parameters for the property. - myTypeArray.SetValue(typeof(int),0); - myTypeArray.SetValue(typeof(int),1); + myTypeArray.SetValue(typeof(int), 0); + myTypeArray.SetValue(typeof(int), 1); // Search for the indexed property whose parameters match the // specified argument types and modifiers. PropertyInfo myPropertyInfo = myType.GetProperty("Item", - typeof(int),myTypeArray,null); + typeof(int), myTypeArray, null); Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name + " has a property type of " + myPropertyInfo.PropertyType); - } - catch(Exception ex) + } + catch (Exception ex) { Console.WriteLine("An exception occurred " + ex.Message); } diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs index b30e4da0e67..282774f6ca9 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs @@ -9,14 +9,8 @@ class MyClass3 // Declare an indexer. public int this[int i, int j] { - get - { - return _myArray[i, j]; - } - set - { - _myArray[i, j] = value; - } + get => _myArray[i, j]; + set => _myArray[i, j] = value; } } @@ -38,14 +32,13 @@ public static void Main(string[] args) PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr); // Display the property. - Console.WriteLine("The {0} property exists in MyClass3.", - myPropInfo.ToString()); + Console.WriteLine($"The {myPropInfo.ToString()} property exists in MyClass3."); } catch (NullReferenceException e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Source : {0}", e.Source); - Console.WriteLine("Message : {0}", e.Message); + Console.WriteLine($"Source : {e.Source}"); + Console.WriteLine($"Message : {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs index 5bd74bc952a..2a7433a34e7 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs @@ -19,10 +19,8 @@ static void Main() // Get the PropertyInfo object representing MyProperty1. PropertyInfo myStringProperties1 = myType.GetProperty("MyProperty1", typeof(string)); - Console.WriteLine("The name of the first property of MyPropertyTypeClass is {0}.", - myStringProperties1.Name); - Console.WriteLine("The type of the first property of MyPropertyTypeClass is {0}.", - myStringProperties1.PropertyType); + Console.WriteLine($"The name of the first property of MyPropertyTypeClass is {myStringProperties1.Name}."); + Console.WriteLine($"The type of the first property of MyPropertyTypeClass is {myStringProperties1.PropertyType}."); } catch (ArgumentNullException e) { @@ -34,12 +32,12 @@ static void Main() } catch (NullReferenceException e) { - Console.WriteLine("Source : {0}", e.Source); - Console.WriteLine("Message : {0}", e.Message); + Console.WriteLine($"Source : {e.Source}"); + Console.WriteLine($"Message : {e.Message}"); } //Output: //The name of the first property of MyPropertyTypeClass is MyProperty1. //The type of the first property of MyPropertyTypeClass is System.String. } } -// +// diff --git a/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.cs b/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.cs index 7141baf6e99..83b7a06f4be 100644 --- a/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.cs +++ b/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.cs @@ -1,6 +1,6 @@ -using System; + namespace MyNamespace { - public class MyType {} + public class MyType { } } diff --git a/snippets/csharp/System/Type/GetType/source.cs b/snippets/csharp/System/Type/GetType/source.cs index cdf553928e0..29486be664c 100644 --- a/snippets/csharp/System/Type/GetType/source.cs +++ b/snippets/csharp/System/Type/GetType/source.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; class Example diff --git a/snippets/csharp/System/Type/GetType/type_gettype.cs b/snippets/csharp/System/Type/GetType/type_gettype.cs index c0345bf6a7a..77611966ab3 100644 --- a/snippets/csharp/System/Type/GetType/type_gettype.cs +++ b/snippets/csharp/System/Type/GetType/type_gettype.cs @@ -3,27 +3,30 @@ class GetTypeExample { - public static void Main() - { - try { - // Get the type of a specified class. - Type myType1 = Type.GetType("System.Int32"); - Console.WriteLine("The full name is {0}.\n", myType1.FullName); - } - catch (TypeLoadException e) - { - Console.WriteLine("{0}: Unable to load type System.Int32", e.GetType().Name); - } + public static void Main() + { + try + { + // Get the type of a specified class. + Type myType1 = Type.GetType("System.Int32"); + Console.WriteLine($"The full name is {myType1.FullName}.\n"); + } + catch (TypeLoadException e) + { + Console.WriteLine($"{e.GetType().Name}: Unable to load type System.Int32"); + } - try { - // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException. - Type myType2 = Type.GetType("NoneSuch", true); - Console.WriteLine("The full name is {0}.", myType2.FullName); - } - catch(TypeLoadException e) { - Console.WriteLine("{0}: Unable to load type NoneSuch", e.GetType().Name); - } - } + try + { + // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException. + Type myType2 = Type.GetType("NoneSuch", true); + Console.WriteLine($"The full name is {myType2.FullName}."); + } + catch (TypeLoadException e) + { + Console.WriteLine($"{e.GetType().Name}: Unable to load type NoneSuch"); + } + } } // The example displays the following output: // The full name is System.Int32. diff --git a/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs b/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs index 66c93790914..9f275449684 100644 --- a/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs +++ b/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs @@ -7,8 +7,8 @@ namespace ConsoleApplication2 /// Class that implements IConvertible class Complex : IConvertible { - double x; - double y; + double x; + double y; public Complex(double x, double y) { @@ -16,98 +16,47 @@ public Complex(double x, double y) this.y = y; } - public TypeCode GetTypeCode() - { - return TypeCode.Object; - } + public TypeCode GetTypeCode() => TypeCode.Object; bool IConvertible.ToBoolean(IFormatProvider provider) { - if( (x != 0.0) || (y != 0.0) ) + if ((x != 0.0) || (y != 0.0)) return true; else return false; } - double GetDoubleValue() - { - return Math.Sqrt(x*x + y*y); - } + double GetDoubleValue() => Math.Sqrt(x * x + y * y); - byte IConvertible.ToByte(IFormatProvider provider) - { - return Convert.ToByte(GetDoubleValue()); - } + byte IConvertible.ToByte(IFormatProvider provider) => Convert.ToByte(GetDoubleValue()); - char IConvertible.ToChar(IFormatProvider provider) - { - return Convert.ToChar(GetDoubleValue()); - } + char IConvertible.ToChar(IFormatProvider provider) => Convert.ToChar(GetDoubleValue()); - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(GetDoubleValue()); - } + DateTime IConvertible.ToDateTime(IFormatProvider provider) => Convert.ToDateTime(GetDoubleValue()); - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - return Convert.ToDecimal(GetDoubleValue()); - } + decimal IConvertible.ToDecimal(IFormatProvider provider) => Convert.ToDecimal(GetDoubleValue()); - double IConvertible.ToDouble(IFormatProvider provider) - { - return GetDoubleValue(); - } + double IConvertible.ToDouble(IFormatProvider provider) => GetDoubleValue(); - short IConvertible.ToInt16(IFormatProvider provider) - { - return Convert.ToInt16(GetDoubleValue()); - } + short IConvertible.ToInt16(IFormatProvider provider) => Convert.ToInt16(GetDoubleValue()); - int IConvertible.ToInt32(IFormatProvider provider) - { - return Convert.ToInt32(GetDoubleValue()); - } + int IConvertible.ToInt32(IFormatProvider provider) => Convert.ToInt32(GetDoubleValue()); - long IConvertible.ToInt64(IFormatProvider provider) - { - return Convert.ToInt64(GetDoubleValue()); - } + long IConvertible.ToInt64(IFormatProvider provider) => Convert.ToInt64(GetDoubleValue()); - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - return Convert.ToSByte(GetDoubleValue()); - } + sbyte IConvertible.ToSByte(IFormatProvider provider) => Convert.ToSByte(GetDoubleValue()); - float IConvertible.ToSingle(IFormatProvider provider) - { - return Convert.ToSingle(GetDoubleValue()); - } + float IConvertible.ToSingle(IFormatProvider provider) => Convert.ToSingle(GetDoubleValue()); - string IConvertible.ToString(IFormatProvider provider) - { - return "( " + x.ToString() + " , " + y.ToString() + " )"; - } + string IConvertible.ToString(IFormatProvider provider) => "( " + x.ToString() + " , " + y.ToString() + " )"; - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(GetDoubleValue(),conversionType); - } + object IConvertible.ToType(Type conversionType, IFormatProvider provider) => Convert.ChangeType(GetDoubleValue(), conversionType); - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - return Convert.ToUInt16(GetDoubleValue()); - } + ushort IConvertible.ToUInt16(IFormatProvider provider) => Convert.ToUInt16(GetDoubleValue()); - uint IConvertible.ToUInt32(IFormatProvider provider) - { - return Convert.ToUInt32(GetDoubleValue()); - } + uint IConvertible.ToUInt32(IFormatProvider provider) => Convert.ToUInt32(GetDoubleValue()); - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - return Convert.ToUInt64(GetDoubleValue()); - } + ulong IConvertible.ToUInt64(IFormatProvider provider) => Convert.ToUInt64(GetDoubleValue()); } /// @@ -118,34 +67,34 @@ class Class1 static void Main(string[] args) { - Complex testComplex = new Complex(4,7); + Complex testComplex = new(4, 7); WriteObjectInfo(testComplex); WriteObjectInfo(Convert.ToBoolean(testComplex)); WriteObjectInfo(Convert.ToDecimal(testComplex)); WriteObjectInfo(Convert.ToString(testComplex)); } -// + // static void WriteObjectInfo(object testObject) { - TypeCode typeCode = Type.GetTypeCode( testObject.GetType() ); + TypeCode typeCode = Type.GetTypeCode(testObject.GetType()); - switch( typeCode ) + switch (typeCode) { case TypeCode.Boolean: - Console.WriteLine("Boolean: {0}", testObject); + Console.WriteLine($"Boolean: {testObject}"); break; case TypeCode.Double: - Console.WriteLine("Double: {0}", testObject); + Console.WriteLine($"Double: {testObject}"); break; default: - Console.WriteLine("{0}: {1}", typeCode.ToString(), testObject); + Console.WriteLine($"{typeCode.ToString()}: {testObject}"); break; } } -// + // } } diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs index ef6f4b99acd..8f19f58214d 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs @@ -1,26 +1,25 @@ // using System; using System.Reflection; -using System.Runtime.InteropServices; + public class Example { - private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - - public static void Main() - { - // Start an instance of the Word application. - var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID)); - Console.WriteLine("Instantiated Type object from CLSID {0}", - WORD_CLSID); - Object wordObj = Activator.CreateInstance(word); - Console.WriteLine("Instantiated {0}", - wordObj.GetType().FullName); - - // Close Word. - word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false } ); - } + private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; + + public static void Main() + { + // Start an instance of the Word application. + var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID)); + Console.WriteLine("Instantiated Type object from CLSID {0}", + WORD_CLSID); + object wordObj = Activator.CreateInstance(word); + Console.WriteLine($"Instantiated {wordObj.GetType().FullName}"); + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, + wordObj, new object[] { 0, 0, false }); + } } // The example displays the following output: // Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs index f6b20ed2b01..68ee2a8c98a 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; -[assembly:ComVisible(true)] +[assembly: ComVisible(true)] // Define two classes, and assign one an explicit GUID. [GuidAttribute("d055cba3-1f83-4bd7-ba19-e22b1b8ec3c4")] @@ -14,67 +14,65 @@ public class NoExplicitGuid public class Example { - public static void Main() - { - Type explicitType = typeof(ExplicitGuid); - Guid explicitGuid = explicitType.GUID; - - // Get type of ExplicitGuid from its GUID. - Type explicitCOM = Type.GetTypeFromCLSID(explicitGuid); - Console.WriteLine("Created {0} type from CLSID {1}", - explicitCOM.Name, explicitGuid); - - // Compare the two type objects. - Console.WriteLine("{0} and {1} equal: {2}", - explicitType.Name, explicitCOM.Name, - explicitType.Equals(explicitCOM)); - - // Instantiate an ExplicitGuid object. - try { - Object obj = Activator.CreateInstance(explicitCOM); - Console.WriteLine("Instantiated a {0} object", obj.GetType().Name); - } - catch (COMException e) { - Console.WriteLine("COM Exception:\n{0}\n", e.Message); - } - - Type notExplicit = typeof(NoExplicitGuid); - Guid notExplicitGuid = notExplicit.GUID; - - // Get type of ExplicitGuid from its GUID. - Type notExplicitCOM = Type.GetTypeFromCLSID(notExplicitGuid); - Console.WriteLine("Created {0} type from CLSID {1}", - notExplicitCOM.Name, notExplicitGuid); - - // Compare the two type objects. - Console.WriteLine("{0} and {1} equal: {2}", - notExplicit.Name, notExplicitCOM.Name, - notExplicit.Equals(notExplicitCOM)); - - // Instantiate an ExplicitGuid object. - try { - Object obj = Activator.CreateInstance(notExplicitCOM); - Console.WriteLine("Instantiated a {0} object", obj.GetType().Name); - } - catch (COMException e) { - Console.WriteLine("COM Exception:\n{0}\n", e.Message); - } - } + public static void Main() + { + Type explicitType = typeof(ExplicitGuid); + Guid explicitGuid = explicitType.GUID; + + // Get type of ExplicitGuid from its GUID. + Type explicitCOM = Type.GetTypeFromCLSID(explicitGuid); + Console.WriteLine($"Created {explicitCOM.Name} type from CLSID {explicitGuid}"); + + // Compare the two type objects. + Console.WriteLine($"{explicitType.Name} and {explicitCOM.Name} equal: {explicitType.Equals(explicitCOM)}"); + + // Instantiate an ExplicitGuid object. + try + { + object obj = Activator.CreateInstance(explicitCOM); + Console.WriteLine($"Instantiated a {obj.GetType().Name} object"); + } + catch (COMException e) + { + Console.WriteLine($"COM Exception:\n{e.Message}\n"); + } + + Type notExplicit = typeof(NoExplicitGuid); + Guid notExplicitGuid = notExplicit.GUID; + + // Get type of ExplicitGuid from its GUID. + Type notExplicitCOM = Type.GetTypeFromCLSID(notExplicitGuid); + Console.WriteLine($"Created {notExplicitCOM.Name} type from CLSID {notExplicitGuid}"); + + // Compare the two type objects. + Console.WriteLine($"{notExplicit.Name} and {notExplicitCOM.Name} equal: {notExplicit.Equals(notExplicitCOM)}"); + + // Instantiate an ExplicitGuid object. + try + { + object obj = Activator.CreateInstance(notExplicitCOM); + Console.WriteLine($"Instantiated a {obj.GetType().Name} object"); + } + catch (COMException e) + { + Console.WriteLine($"COM Exception:\n{e.Message}\n"); + } + } } // The example displays the following output: // Created __ComObject type from CLSID d055cba3-1f83-4bd7-ba19-e22b1b8ec3c4 // ExplicitGuid and __ComObject equal: False // COM Exception: -// Retrieving the COM class factory for component with CLSID -// {D055CBA3-1F83-4BD7-BA19-E22B1B8EC3C4} failed due to the following error: -// 80040154 Class not registered +// Retrieving the COM class factory for component with CLSID +// {D055CBA3-1F83-4BD7-BA19-E22B1B8EC3C4} failed due to the following error: +// 80040154 Class not registered // (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). -// +// // Created __ComObject type from CLSID 74f03346-a718-3516-ac78-f351c7459ffb // NoExplicitGuid and __ComObject equal: False // COM Exception: -// Retrieving the COM class factory for component with CLSID -// {74F03346-A718-3516-AC78-F351C7459FFB} failed due to the following error: -// 80040154 Class not registered +// Retrieving the COM class factory for component with CLSID +// {74F03346-A718-3516-AC78-F351C7459FFB} failed due to the following error: +// 80040154 Class not registered // (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). // diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs index 721c6fbd9a9..6e6a56c10dd 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs @@ -1,31 +1,33 @@ // using System; using System.Reflection; -using System.Runtime.InteropServices; + public class Example { - private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - - public static void Main() - { - try { - // Start an instance of the Word application. - var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), true); - Console.WriteLine("Instantiated Type object from CLSID {0}", - WORD_CLSID); - Object wordObj = Activator.CreateInstance(word); - Console.WriteLine("Instantiated {0}", - wordObj.GetType().FullName, WORD_CLSID); - - // Close Word. - word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false } ); - } - catch (Exception) { - Console.WriteLine("Unable to instantiate an object for {0}", WORD_CLSID); - } - } + private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; + + public static void Main() + { + try + { + // Start an instance of the Word application. + var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), true); + Console.WriteLine("Instantiated Type object from CLSID {0}", + WORD_CLSID); + object wordObj = Activator.CreateInstance(word); + Console.WriteLine("Instantiated {0}", + wordObj.GetType().FullName, WORD_CLSID); + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, + wordObj, new object[] { 0, 0, false }); + } + catch (Exception) + { + Console.WriteLine("Unable to instantiate an object for {0}", WORD_CLSID); + } + } } // The example displays the following output: // Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs index 1f82da2f08e..60faa66cbf4 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs @@ -5,27 +5,29 @@ public class Example { - private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - - public static void Main() - { - // Start an instance of the Word application. - var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), "computer17.central.contoso.com"); - Console.WriteLine("Instantiated Type object from CLSID {0}", - WORD_CLSID); - try { - Object wordObj = Activator.CreateInstance(word); - Console.WriteLine("Instantiated {0}", - wordObj.GetType().FullName, WORD_CLSID); - - // Close Word. - word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false } ); - } - catch (COMException) { - Console.WriteLine("Unable to instantiate object."); - } - } + private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; + + public static void Main() + { + // Start an instance of the Word application. + var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), "computer17.central.contoso.com"); + Console.WriteLine("Instantiated Type object from CLSID {0}", + WORD_CLSID); + try + { + object wordObj = Activator.CreateInstance(word); + Console.WriteLine("Instantiated {0}", + wordObj.GetType().FullName, WORD_CLSID); + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, + wordObj, new object[] { 0, 0, false }); + } + catch (COMException) + { + Console.WriteLine("Unable to instantiate object."); + } + } } // The example displays the following output: // Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs index ca61680bb07..df68d46282f 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs @@ -1,35 +1,37 @@ // using System; using System.Reflection; -using System.Runtime.InteropServices; + public class Example { - private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - - public static void Main() - { - try { - // Start an instance of the Word application. - var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), - "computer17.central.contoso.com", - true); - Console.WriteLine("Instantiated Type object from CLSID {0}", - WORD_CLSID); - Object wordObj = Activator.CreateInstance(word); - Console.WriteLine("Instantiated {0}", - wordObj.GetType().FullName, WORD_CLSID); - - // Close Word. - word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false } ); - } - // The method can throw any of a variety of exceptions. - catch (Exception e) { - Console.WriteLine("{0}: Unable to instantiate an object for {1}", - e.GetType().Name, WORD_CLSID); - } - } + private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; + + public static void Main() + { + try + { + // Start an instance of the Word application. + var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), + "computer17.central.contoso.com", + true); + Console.WriteLine("Instantiated Type object from CLSID {0}", + WORD_CLSID); + object wordObj = Activator.CreateInstance(word); + Console.WriteLine("Instantiated {0}", + wordObj.GetType().FullName, WORD_CLSID); + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, + wordObj, new object[] { 0, 0, false }); + } + // The method can throw any of a variety of exceptions. + catch (Exception e) + { + Console.WriteLine("{0}: Unable to instantiate an object for {1}", + e.GetType().Name, WORD_CLSID); + } + } } // The example displays the following output: // Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} diff --git a/snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs b/snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs index 5cc5c7b802a..9912d73d65b 100644 --- a/snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs +++ b/snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs @@ -9,20 +9,20 @@ returns the type referenced by the specified type handle. */ using System; -using System.Reflection; + public class MyClass1 { } public class MyClass2 { - public static void Main() - { -// - MyClass1 myClass1 = new MyClass1(); - // Get the type referenced by the specified type handle. + public static void Main() + { + // + MyClass1 myClass1 = new(); + // Get the type referenced by the specified type handle. Type myClass1Type = Type.GetTypeFromHandle(Type.GetTypeHandle(myClass1)); - Console.WriteLine("The Names of the Attributes :"+myClass1Type.Attributes); -// - } + Console.WriteLine("The Names of the Attributes :" + myClass1Type.Attributes); + // + } } diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs index 79fae7f6198..fbc9793c98d 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs @@ -7,21 +7,21 @@ public static void Main() try { // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1. - string myString1 ="DIRECT.ddPalette.3"; + string myString1 = "DIRECT.ddPalette.3"; // Use a nonexistent ProgID WrongProgID. - string myString2 ="WrongProgID"; + string myString2 = "WrongProgID"; // Make a call to the method to get the type information of the given ProgID. - Type myType1 =Type.GetTypeFromProgID(myString1,true); - Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID); + Type myType1 = Type.GetTypeFromProgID(myString1, true); + Console.WriteLine($"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}."); // Throw an exception because the ProgID is invalid and the throwOnError // parameter is set to True. - Type myType2 =Type.GetTypeFromProgID(myString2,true); + Type myType2 = Type.GetTypeFromProgID(myString2, true); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Source: {0}", e.Source); - Console.WriteLine("Message: {0}", e.Message); + Console.WriteLine($"Source: {e.Source}"); + Console.WriteLine($"Message: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs index c393f182998..1445bacb4e7 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs @@ -7,23 +7,23 @@ public static void Main() try { // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1. - string theProgramID ="DirControl.DirList.1"; + string theProgramID = "DirControl.DirList.1"; // Use the server name localhost. - string theServer="localhost"; + string theServer = "localhost"; // Make a call to the method to get the type information for the given ProgID. - Type myType =Type.GetTypeFromProgID(theProgramID,theServer); - if(myType==null) + Type myType = Type.GetTypeFromProgID(theProgramID, theServer); + if (myType == null) { throw new Exception("Invalid ProgID or Server."); } - Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID); + Console.WriteLine($"GUID for ProgID DirControl.DirList.1 is {myType.GUID}."); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("An exception occurred."); - Console.WriteLine("Source: {0}" , e.Source); - Console.WriteLine("Message: {0}" , e.Message); - } + Console.WriteLine($"Source: {e.Source}"); + Console.WriteLine($"Message: {e.Message}"); + } } } // diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs index 614ad868a87..4d6a5566f19 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs @@ -8,23 +8,23 @@ public static void Main() try { // Use server localhost. - string theServer="localhost"; + string theServer = "localhost"; // Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1. - string myString1 ="DirControl.DirList.1"; + string myString1 = "DirControl.DirList.1"; // Use a wrong ProgID WrongProgID. - string myString2 ="WrongProgID"; + string myString2 = "WrongProgID"; // Make a call to the method to get the type information for the given ProgID. - Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true); - Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID); + Type myType1 = Type.GetTypeFromProgID(myString1, theServer, true); + Console.WriteLine($"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}."); // Throw an exception because the ProgID is invalid and the throwOnError // parameter is set to True. - Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true); + Type myType2 = Type.GetTypeFromProgID(myString2, theServer, true); } - catch(Exception e) + catch (Exception e) { Console.WriteLine("An exception occurred. The ProgID is wrong."); - Console.WriteLine("Source: {0}" , e.Source); - Console.WriteLine("Message: {0}" , e.Message); + Console.WriteLine($"Source: {e.Source}"); + Console.WriteLine($"Message: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs b/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs index 72580e41191..caf6b6fb125 100644 --- a/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs +++ b/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs @@ -7,29 +7,26 @@ public class Example { // This method is for demonstration purposes. - unsafe public void Test(ref int x, out int y, int* z) - { - *z = x = y = 0; - } + unsafe public void Test(ref int x, out int y, int* z) => *z = x = y = 0; public static void Main() { // All of the following display 'True'. // Define an array, get its type, and display HasElementType. - int[] nums = {1, 1, 2, 3, 5, 8, 13}; + int[] nums = { 1, 1, 2, 3, 5, 8, 13 }; Type t = nums.GetType(); - Console.WriteLine("HasElementType is '{0}' for array types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for array types."); // Test an array type without defining an array. t = typeof(Example[]); - Console.WriteLine("HasElementType is '{0}' for array types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for array types."); // When you use Reflection Emit to emit dynamic methods and // assemblies, you can create array types using MakeArrayType. // The following creates the type 'array of Example'. t = typeof(Example).MakeArrayType(); - Console.WriteLine("HasElementType is '{0}' for array types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for array types."); // When you reflect over methods, HasElementType is true for // ref, out, and pointer parameter types. The following @@ -38,19 +35,19 @@ public static void Main() MethodInfo mi = typeof(Example).GetMethod("Test"); ParameterInfo[] parms = mi.GetParameters(); t = parms[0].ParameterType; - Console.WriteLine("HasElementType is '{0}' for ref parameter types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for ref parameter types."); t = parms[1].ParameterType; - Console.WriteLine("HasElementType is '{0}' for out parameter types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for out parameter types."); t = parms[2].ParameterType; - Console.WriteLine("HasElementType is '{0}' for pointer parameter types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for pointer parameter types."); // When you use Reflection Emit to emit dynamic methods and // assemblies, you can create pointer and ByRef types to use // when you define method parameters. t = typeof(Example).MakePointerType(); - Console.WriteLine("HasElementType is '{0}' for pointer types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for pointer types."); t = typeof(Example).MakeByRefType(); - Console.WriteLine("HasElementType is '{0}' for ByRef types.", t.HasElementType); + Console.WriteLine($"HasElementType is '{t.HasElementType}' for ByRef types."); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs b/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs index 18df3d3db3c..9dee37ed1ed 100644 --- a/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs +++ b/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs @@ -4,28 +4,25 @@ public class MyTypeDelegator : TypeDelegator { public string myElementType = null; - private Type myType = null ; - public MyTypeDelegator(Type myType) : base(myType) - { - this.myType = myType; - } + private Type myType = null; + public MyTypeDelegator(Type myType) : base(myType) => this.myType = myType; // Override Type.HasElementTypeImpl(). protected override bool HasElementTypeImpl() { // Determine whether the type is an array. - if(myType.IsArray) + if (myType.IsArray) { myElementType = "array"; return true; } // Determine whether the type is a reference. - if(myType.IsByRef) + if (myType.IsByRef) { myElementType = "reference"; return true; } // Determine whether the type is a pointer. - if(myType.IsPointer) + if (myType.IsPointer) { myElementType = "pointer"; return true; @@ -40,25 +37,25 @@ public static void Main() { try { - int myInt = 0 ; + int myInt = 0; int[] myArray = new int[5]; - MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType()); + MyTypeDelegator myType = new(myArray.GetType()); // Determine whether myType is an array, pointer, reference type. Console.WriteLine("\nDetermine whether a variable is an array, pointer, or reference type.\n"); - if( myType.HasElementType) - Console.WriteLine("The type of myArray is {0}.", myType.myElementType); + if (myType.HasElementType) + Console.WriteLine($"The type of myArray is {myType.myElementType}."); else Console.WriteLine("myArray is not an array, pointer, or reference type."); - myType = new MyTypeDelegator(myInt.GetType()); + myType = new(myInt.GetType()); // Determine whether myType is an array, pointer, reference type. - if( myType.HasElementType) - Console.WriteLine("The type of myInt is {0}.", myType.myElementType); + if (myType.HasElementType) + Console.WriteLine($"The type of myInt is {myType.myElementType}."); else Console.WriteLine("myInt is not an array, pointer, or reference type."); } - catch( Exception e ) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message); + Console.WriteLine($"Exception: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/InvokeMember/invokemem.cs b/snippets/csharp/System/Type/InvokeMember/invokemem.cs index 69618c33a7a..38a6b29507c 100644 --- a/snippets/csharp/System/Type/InvokeMember/invokemem.cs +++ b/snippets/csharp/System/Type/InvokeMember/invokemem.cs @@ -5,12 +5,12 @@ // This sample class has a field, constructor, method, and property. class MyType { - Int32 myField; - public MyType(ref Int32 x) {x *= 5;} - public override String ToString() {return myField.ToString();} - public Int32 MyProp + int myField; + public MyType(ref int x) => x *= 5; + public override string ToString() => myField.ToString(); + public int MyProp { - get {return myField;} + get => myField; set { if (value < 1) @@ -26,28 +26,28 @@ static void Main() { Type t = typeof(MyType); // Create an instance of a type. - Object[] args = new Object[] {8}; - Console.WriteLine("The value of x before the constructor is called is {0}.", args[0]); - Object obj = t.InvokeMember(null, + object[] args = new object[] { 8 }; + Console.WriteLine($"The value of x before the constructor is called is {args[0]}."); + object obj = t.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, args); Console.WriteLine("Type: " + obj.GetType().ToString()); - Console.WriteLine("The value of x after the constructor returns is {0}.", args[0]); + Console.WriteLine($"The value of x after the constructor returns is {args[0]}."); // Read and write to a field. t.InvokeMember("myField", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetField, null, obj, new Object[] {5}); - Int32 v = (Int32) t.InvokeMember("myField", + BindingFlags.Instance | BindingFlags.SetField, null, obj, new object[] { 5 }); + int v = (int)t.InvokeMember("myField", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, obj, null); Console.WriteLine("myField: " + v); // Call a method. - String s = (String) t.InvokeMember("ToString", + string s = (string)t.InvokeMember("ToString", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, null); @@ -67,7 +67,7 @@ static void Main() t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new Object[] {0}); + BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new object[] { 0 }); } catch (TargetInvocationException e) { @@ -81,12 +81,12 @@ static void Main() t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new Object[] {2}); - v = (Int32) t.InvokeMember("MyProp", + BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new object[] { 2 }); + v = (int)t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, obj, null); Console.WriteLine("MyProp: " + v); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsAbstract/isabstract1.cs b/snippets/csharp/System/Type/IsAbstract/isabstract1.cs index e8fd4bc0b3b..29b97172acb 100644 --- a/snippets/csharp/System/Type/IsAbstract/isabstract1.cs +++ b/snippets/csharp/System/Type/IsAbstract/isabstract1.cs @@ -2,43 +2,39 @@ using System; public abstract class AbstractClass -{} +{ } public class DerivedClass : AbstractClass -{} +{ } public sealed class SingleClass -{} +{ } public interface ITypeInfo { - string GetName(); + string GetName(); } public class ImplementingClass : ITypeInfo { - public string GetName() - { - return this.GetType().FullName; - } + public string GetName() => this.GetType().FullName; } delegate string InputOutput(string inp); public class Example { - public static void Main() - { - Type[] types= { typeof(AbstractClass), + public static void Main() + { + Type[] types = { typeof(AbstractClass), typeof(DerivedClass), typeof(ITypeInfo), typeof(SingleClass), typeof(ImplementingClass), typeof(InputOutput) }; - foreach (var type in types) - Console.WriteLine("{0} is abstract: {1}", - type.Name, type.IsAbstract); - } + foreach (var type in types) + Console.WriteLine($"{type.Name} is abstract: {type.IsAbstract}"); + } } // The example displays the following output: // AbstractClass is abstract: True diff --git a/snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs b/snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs index d42efe9efe2..e5b06e91157 100644 --- a/snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs +++ b/snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs @@ -3,7 +3,7 @@ using System.Reflection; public class MyClass { - protected string myField = "A sample protected field." ; + protected string myField = "A sample protected field."; } public class MyType_IsAnsiClass { @@ -11,19 +11,19 @@ public static void Main() { try { - MyClass myObject = new MyClass(); + MyClass myObject = new(); // Get the type of the 'MyClass'. Type myType = typeof(MyClass); // Get the field information and the attributes associated with MyClass. - FieldInfo myFieldInfo = myType.GetField("myField", BindingFlags.NonPublic|BindingFlags.Instance); - Console.WriteLine( "\nChecking for the AnsiClass attribute for a field.\n"); + FieldInfo myFieldInfo = myType.GetField("myField", BindingFlags.NonPublic | BindingFlags.Instance); + Console.WriteLine("\nChecking for the AnsiClass attribute for a field.\n"); // Get and display the name, field, and the AnsiClass attribute. - Console.WriteLine("Name of Class: {0} \nValue of Field: {1} \nIsAnsiClass = {2}", myType.FullName, myFieldInfo.GetValue(myObject), myType.IsAnsiClass); + Console.WriteLine($"Name of Class: {myType.FullName} \nValue of Field: {myFieldInfo.GetValue(myObject)} \nIsAnsiClass = {myType.IsAnsiClass}"); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("Exception: {0}",e.Message); + Console.WriteLine($"Exception: {e.Message}"); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsArray/isarray2.cs b/snippets/csharp/System/Type/IsArray/isarray2.cs index feed53d1423..44eb09d1f28 100644 --- a/snippets/csharp/System/Type/IsArray/isarray2.cs +++ b/snippets/csharp/System/Type/IsArray/isarray2.cs @@ -5,16 +5,15 @@ public class Example { - public static void Main() - { - Type[] types = { typeof(String), typeof(int[]), + public static void Main() + { + Type[] types = { typeof(string), typeof(int[]), typeof(ArrayList), typeof(Array), - typeof(List), - typeof(IEnumerable) }; - foreach (var t in types) - Console.WriteLine("{0,-15} IsArray = {1}", t.Name + ":", - t.IsArray); - } + typeof(List), + typeof(IEnumerable) }; + foreach (var t in types) + Console.WriteLine($"{t.Name + ":",-15} IsArray = {t.IsArray}"); + } } // The example displays the following output: // String: IsArray = False diff --git a/snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs b/snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs index bf078734e26..4b52c4981fd 100644 --- a/snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs +++ b/snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs @@ -5,15 +5,12 @@ public class MyTypeDelegator : TypeDelegator { public string myElementType = null; public Type myType; - public MyTypeDelegator(Type myType) : base(myType) - { - this.myType = myType; - } + public MyTypeDelegator(Type myType) : base(myType) => this.myType = myType; // Override IsArrayImpl(). protected override bool IsArrayImpl() { // Determine whether the type is an array. - if(myType.IsArray) + if (myType.IsArray) { myElementType = "array"; return true; @@ -28,27 +25,27 @@ public static void Main() { try { - int myInt = 0 ; + int myInt = 0; // Create an instance of an array element. int[] myArray = new int[5]; - MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType()); + MyTypeDelegator myType = new(myArray.GetType()); Console.WriteLine("\nDetermine whether the variable is an array.\n"); // Determine whether myType is an array type. - if( myType.IsArray) - Console.WriteLine("The type of myArray is {0}.", myType.myElementType); + if (myType.IsArray) + Console.WriteLine($"The type of myArray is {myType.myElementType}."); else Console.WriteLine("myArray is not an array."); - myType = new MyTypeDelegator(myInt.GetType()); + myType = new(myInt.GetType()); // Determine whether myType is an array type. - if( myType.IsArray) - Console.WriteLine("The type of myInt is {0}.", myType.myElementType); + if (myType.IsArray) + Console.WriteLine($"The type of myInt is {myType.myElementType}."); else Console.WriteLine("myInt is not an array."); } - catch( Exception e ) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message ); + Console.WriteLine($"Exception: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs index aa1219c81c6..815e50c5e75 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs @@ -4,16 +4,16 @@ public class Example { - public static void Main() - { - Type t = typeof(Stream); - Type genericT = typeof(GenericWithConstraint<>); - Type genericParam = genericT.GetGenericArguments()[0]; - Console.WriteLine(t.IsAssignableFrom(genericParam)); - // Displays True. - } + public static void Main() + { + Type t = typeof(Stream); + Type genericT = typeof(GenericWithConstraint<>); + Type genericParam = genericT.GetGenericArguments()[0]; + Console.WriteLine(t.IsAssignableFrom(genericParam)); + // Displays True. + } } public class GenericWithConstraint where T : Stream -{} +{ } // diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs index 15c10742cc7..e8878fbf2d8 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs @@ -4,17 +4,17 @@ public class Example { - public static void Main() - { - Type t = typeof(IEnumerable); - Type c = typeof(Array); - - IEnumerable instanceOfT; - int[] instanceOfC = { 1, 2, 3, 4 }; - if (t.IsAssignableFrom(c)) - // - instanceOfT = instanceOfC; - // - } + public static void Main() + { + Type t = typeof(IEnumerable); + Type c = typeof(Array); + + IEnumerable instanceOfT; + int[] instanceOfC = { 1, 2, 3, 4 }; + if (t.IsAssignableFrom(c)) + // + instanceOfT = instanceOfC; + // + } } // diff --git a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs index 51246e4ac4e..4359ce07ddd 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs @@ -4,26 +4,28 @@ using System.Reflection.Emit; public class A -{} +{ } public class Example { - public static void Main() - { - AppDomain domain = AppDomain.CurrentDomain; - AssemblyName assemName = new AssemblyName(); - assemName.Name = "TempAssembly"; + public static void Main() + { + AppDomain domain = AppDomain.CurrentDomain; + AssemblyName assemName = new() + { + Name = "TempAssembly" + }; - // Define a dynamic assembly in the current application domain. - AssemblyBuilder assemBuilder = domain.DefineDynamicAssembly(assemName, - AssemblyBuilderAccess.Run); + // Define a dynamic assembly in the current application domain. + AssemblyBuilder assemBuilder = domain.DefineDynamicAssembly(assemName, + AssemblyBuilderAccess.Run); - // Define a dynamic module in this assembly. - ModuleBuilder moduleBuilder = assemBuilder.DefineDynamicModule("TempModule"); + // Define a dynamic module in this assembly. + ModuleBuilder moduleBuilder = assemBuilder.DefineDynamicModule("TempModule"); - TypeBuilder b1 = moduleBuilder.DefineType("B", TypeAttributes.Public, typeof(A)); - Console.WriteLine(typeof(A).IsAssignableFrom(b1)); - } + TypeBuilder b1 = moduleBuilder.DefineType("B", TypeAttributes.Public, typeof(A)); + Console.WriteLine(typeof(A).IsAssignableFrom(b1)); + } } // The example displays the following output: // True diff --git a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs index eedfa2553f0..dfc60181a23 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs @@ -5,60 +5,60 @@ class Program { public static void Main() { - // Demonstrate classes: - Console.WriteLine("Defined Classes:"); - Room room1 = new Room(); - Kitchen kitchen1 = new Kitchen(); - Bedroom bedroom1 = new Bedroom(); - Guestroom guestroom1 = new Guestroom(); - MasterBedroom masterbedroom1 = new MasterBedroom(); - - Type room1Type = room1.GetType(); - Type kitchen1Type = kitchen1.GetType(); - Type bedroom1Type = bedroom1.GetType(); - Type guestroom1Type = guestroom1.GetType(); - Type masterbedroom1Type = masterbedroom1.GetType(); - - Console.WriteLine("room assignable from kitchen: {0}", room1Type.IsAssignableFrom(kitchen1Type)); - Console.WriteLine("bedroom assignable from guestroom: {0}", bedroom1Type.IsAssignableFrom(guestroom1Type)); - Console.WriteLine("kitchen assignable from masterbedroom: {0}", kitchen1Type.IsAssignableFrom(masterbedroom1Type)); - - // Demonstrate arrays: - Console.WriteLine(); - Console.WriteLine("Integer arrays:"); - - int[] array2 = new int[2]; - int[] array10 = new int[10]; - int[,] array22 = new int[2, 2]; - int[,] array24 = new int[2, 4]; - - Type array2Type = array2.GetType(); - Type array10Type = array10.GetType(); - Type array22Type = array22.GetType(); - Type array24Type = array24.GetType(); - - Console.WriteLine("int[2] assignable from int[10]: {0}", array2Type.IsAssignableFrom(array10Type)); - Console.WriteLine("int[2] assignable from int[2,4]: {0}", array2Type.IsAssignableFrom(array24Type)); - Console.WriteLine("int[2,4] assignable from int[2,2]: {0}", array24Type.IsAssignableFrom(array22Type)); - - // Demonstrate generics: - Console.WriteLine(); - Console.WriteLine("Generics:"); - - // Note that "int?[]" is the same as "Nullable[]" - int?[] arrayNull = new int?[10]; - List genIntList = new List(); - List genTList = new List(); - - Type arrayNullType = arrayNull.GetType(); - Type genIntListType = genIntList.GetType(); - Type genTListType = genTList.GetType(); - - Console.WriteLine("int[10] assignable from int?[10]: {0}", array10Type.IsAssignableFrom(arrayNullType)); - Console.WriteLine("List assignable from List: {0}", genIntListType.IsAssignableFrom(genTListType)); - Console.WriteLine("List assignable from List: {0}", genTListType.IsAssignableFrom(genIntListType)); - - Console.ReadLine(); + // Demonstrate classes: + Console.WriteLine("Defined Classes:"); + Room room1 = new(); + Kitchen kitchen1 = new(); + Bedroom bedroom1 = new(); + Guestroom guestroom1 = new(); + MasterBedroom masterbedroom1 = new(); + + Type room1Type = room1.GetType(); + Type kitchen1Type = kitchen1.GetType(); + Type bedroom1Type = bedroom1.GetType(); + Type guestroom1Type = guestroom1.GetType(); + Type masterbedroom1Type = masterbedroom1.GetType(); + + Console.WriteLine($"room assignable from kitchen: {room1Type.IsAssignableFrom(kitchen1Type)}"); + Console.WriteLine($"bedroom assignable from guestroom: {bedroom1Type.IsAssignableFrom(guestroom1Type)}"); + Console.WriteLine($"kitchen assignable from masterbedroom: {kitchen1Type.IsAssignableFrom(masterbedroom1Type)}"); + + // Demonstrate arrays: + Console.WriteLine(); + Console.WriteLine("Integer arrays:"); + + int[] array2 = new int[2]; + int[] array10 = new int[10]; + int[,] array22 = new int[2, 2]; + int[,] array24 = new int[2, 4]; + + Type array2Type = array2.GetType(); + Type array10Type = array10.GetType(); + Type array22Type = array22.GetType(); + Type array24Type = array24.GetType(); + + Console.WriteLine($"int[2] assignable from int[10]: {array2Type.IsAssignableFrom(array10Type)}"); + Console.WriteLine($"int[2] assignable from int[2,4]: {array2Type.IsAssignableFrom(array24Type)}"); + Console.WriteLine($"int[2,4] assignable from int[2,2]: {array24Type.IsAssignableFrom(array22Type)}"); + + // Demonstrate generics: + Console.WriteLine(); + Console.WriteLine("Generics:"); + + // Note that "int?[]" is the same as "Nullable[]" + int?[] arrayNull = new int?[10]; + List genIntList = new(); + List genTList = new(); + + Type arrayNullType = arrayNull.GetType(); + Type genIntListType = genIntList.GetType(); + Type genTListType = genTList.GetType(); + + Console.WriteLine($"int[10] assignable from int?[10]: {array10Type.IsAssignableFrom(arrayNullType)}"); + Console.WriteLine($"List assignable from List: {genIntListType.IsAssignableFrom(genTListType)}"); + Console.WriteLine($"List assignable from List: {genTListType.IsAssignableFrom(genIntListType)}"); + + Console.ReadLine(); } } class Room @@ -97,4 +97,4 @@ class MasterBedroom : Bedroom // int[10] assignable from int?[10]: False // List assignable from List: False // List assignable from List: False -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs b/snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs index 184d4e2dadc..906dbd9bd12 100644 --- a/snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs +++ b/snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs @@ -13,11 +13,10 @@ public class Example public static void Main() { // Create an instance of the Type class using the GetType method. - Type myType=typeof(Demo); + Type myType = typeof(Demo); // Get and display the IsAutoLayout property of the // Demoinstance. - Console.WriteLine("\nThe AutoLayout property for the Demo class is {0}.", - myType.IsAutoLayout); + Console.WriteLine($"\nThe AutoLayout property for the Demo class is {myType.IsAutoLayout}."); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsClass/type_isclass.cs b/snippets/csharp/System/Type/IsClass/type_isclass.cs index 9898d0a5235..5140bcbb8fc 100644 --- a/snippets/csharp/System/Type/IsClass/type_isclass.cs +++ b/snippets/csharp/System/Type/IsClass/type_isclass.cs @@ -1,8 +1,8 @@ // using System; -using System.Reflection; -public class MyDemoClass + +public class MyDemoClass { } @@ -12,13 +12,13 @@ public static void Main(string[] args) { try { - Type myType = typeof(MyDemoClass); + Type myType = typeof(MyDemoClass); // Get and display the 'IsClass' property of the 'MyDemoClass' instance. - Console.WriteLine("\nIs the specified type a class? {0}.", myType.IsClass); + Console.WriteLine($"\nIs the specified type a class? {myType.IsClass}."); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("\nAn exception occurred: {0}." ,e.Message); + Console.WriteLine($"\nAn exception occurred: {e.Message}."); } } } diff --git a/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs b/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs index 08ebbbb8854..c88c6521f04 100644 --- a/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs +++ b/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs @@ -1,8 +1,8 @@ // using System; -using System.Runtime.Remoting.Contexts; -public class ContextBoundClass: ContextBoundObject + +public class ContextBoundClass : ContextBoundObject { public string Value = "The Value property."; } @@ -11,23 +11,17 @@ public class Example { public static void Main() { - // Determine whether the types can be hosted in a Context. - Console.WriteLine("The IsContextful property for the {0} type is {1}.", - typeof(Example).Name, typeof(Example).IsContextful); - Console.WriteLine("The IsContextful property for the {0} type is {1}.", - typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsContextful); + // Determine whether the types can be hosted in a Context. + Console.WriteLine($"The IsContextful property for the {typeof(Example).Name} type is {typeof(Example).IsContextful}."); + Console.WriteLine($"The IsContextful property for the {typeof(ContextBoundClass).Name} type is {typeof(ContextBoundClass).IsContextful}."); - // Determine whether the types are marshalled by reference. - Console.WriteLine("The IsMarshalByRef property of {0} is {1}.", - typeof(Example).Name, typeof(Example).IsMarshalByRef); - Console.WriteLine("The IsMarshalByRef property of {0} is {1}.", - typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsMarshalByRef); + // Determine whether the types are marshalled by reference. + Console.WriteLine($"The IsMarshalByRef property of {typeof(Example).Name} is {typeof(Example).IsMarshalByRef}."); + Console.WriteLine($"The IsMarshalByRef property of {typeof(ContextBoundClass).Name} is {typeof(ContextBoundClass).IsMarshalByRef}."); - // Determine whether the types are primitive datatypes. - Console.WriteLine("{0} is a primitive data type: {1}.", - typeof(int).Name, typeof(int).IsPrimitive); - Console.WriteLine("{0} is a primitive data type: {1}.", - typeof(string).Name, typeof(string).IsPrimitive); + // Determine whether the types are primitive datatypes. + Console.WriteLine($"{typeof(int).Name} is a primitive data type: {typeof(int).IsPrimitive}."); + Console.WriteLine($"{typeof(string).Name} is a primitive data type: {typeof(string).IsPrimitive}."); } } // The example displays the following output: diff --git a/snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs b/snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs index fc0890ba3af..1e1e69c06ee 100644 --- a/snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs +++ b/snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs @@ -4,17 +4,14 @@ public class MyTypeDelegatorClass : TypeDelegator { public string myElementType = null; - private Type myType = null ; + private Type myType = null; - public MyTypeDelegatorClass(Type myType) : base(myType) - { - this.myType = myType; - } + public MyTypeDelegatorClass(Type myType) : base(myType) => this.myType = myType; // Override IsContextfulImpl. protected override bool IsContextfulImpl() { // Check whether the type is contextful. - if(myType.IsContextful) + if (myType.IsContextful) { myElementType = " is contextful "; return true; @@ -29,10 +26,10 @@ public static void Main() try { MyTypeDelegatorClass myType; - Console.WriteLine ("Check whether MyContextBoundClass can be hosted in a context."); + Console.WriteLine("Check whether MyContextBoundClass can be hosted in a context."); // Check whether MyContextBoundClass is contextful. - myType = new MyTypeDelegatorClass(typeof(MyContextBoundClass)); - if( myType.IsContextful) + myType = new(typeof(MyContextBoundClass)); + if (myType.IsContextful) { Console.WriteLine(typeof(MyContextBoundClass) + " can be hosted in a context."); } @@ -41,9 +38,9 @@ public static void Main() Console.WriteLine(typeof(MyContextBoundClass) + " cannot be hosted in a context."); } // Check whether the int type is contextful. - myType = new MyTypeDelegatorClass(typeof(MyTypeDemoClass)); - Console.WriteLine ("\nCheck whether MyTypeDemoClass can be hosted in a context."); - if( myType.IsContextful) + myType = new(typeof(MyTypeDemoClass)); + Console.WriteLine("\nCheck whether MyTypeDemoClass can be hosted in a context."); + if (myType.IsContextful) { Console.WriteLine(typeof(MyTypeDemoClass) + " can be hosted in a context."); } @@ -52,9 +49,9 @@ public static void Main() Console.WriteLine(typeof(MyTypeDemoClass) + " cannot be hosted in a context."); } } - catch( Exception e ) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message); + Console.WriteLine($"Exception: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/IsEnum/testisenum.cs b/snippets/csharp/System/Type/IsEnum/testisenum.cs index e084641434e..9881e6d3d21 100644 --- a/snippets/csharp/System/Type/IsEnum/testisenum.cs +++ b/snippets/csharp/System/Type/IsEnum/testisenum.cs @@ -7,13 +7,13 @@ class TestIsEnum { public static void Main() { - Type colorType = typeof(Color); - Type enumType = typeof(Enum); - Console.WriteLine("Is Color an enum? {0}.", colorType.IsEnum); - Console.WriteLine("Is Color a value type? {0}.", colorType.IsValueType); - Console.WriteLine("Is Enum an enum Type? {0}.", enumType.IsEnum); - Console.WriteLine("Is Enum a value type? {0}.", enumType.IsValueType); - } + Type colorType = typeof(Color); + Type enumType = typeof(Enum); + Console.WriteLine($"Is Color an enum? {colorType.IsEnum}."); + Console.WriteLine($"Is Color a value type? {colorType.IsValueType}."); + Console.WriteLine($"Is Enum an enum Type? {enumType.IsEnum}."); + Console.WriteLine($"Is Enum a value type? {enumType.IsValueType}."); + } } // The example displays the following output: // Is Color an enum? True. diff --git a/snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs b/snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs index 7993cb6d7b3..2ba10268f88 100644 --- a/snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs +++ b/snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs @@ -1,21 +1,21 @@ // using System; -using System.Reflection; -using System.ComponentModel; + + using System.Runtime.InteropServices; // Class to test for the ExplicitLayout property. -[StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)] +[StructLayout(LayoutKind.Explicit, Size = 16, CharSet = CharSet.Ansi)] public class MySystemTime { - [FieldOffset(0)]public ushort wYear; - [FieldOffset(2)]public ushort wMonth; - [FieldOffset(4)]public ushort wDayOfWeek; - [FieldOffset(6)]public ushort wDay; - [FieldOffset(8)]public ushort wHour; - [FieldOffset(10)]public ushort wMinute; - [FieldOffset(12)]public ushort wSecond; - [FieldOffset(14)]public ushort wMilliseconds; + [FieldOffset(0)] public ushort wYear; + [FieldOffset(2)] public ushort wMonth; + [FieldOffset(4)] public ushort wDayOfWeek; + [FieldOffset(6)] public ushort wDay; + [FieldOffset(8)] public ushort wHour; + [FieldOffset(10)] public ushort wMinute; + [FieldOffset(12)] public ushort wSecond; + [FieldOffset(14)] public ushort wMilliseconds; } public class Program @@ -23,10 +23,9 @@ public class Program public static void Main(string[] args) { // Create an instance of the type using the GetType method. - Type t = typeof(MySystemTime); + Type t = typeof(MySystemTime); // Get and display the IsExplicitLayout property. - Console.WriteLine("\nIsExplicitLayout for MySystemTime is {0}.", - t.IsExplicitLayout); + Console.WriteLine($"\nIsExplicitLayout for MySystemTime is {t.IsExplicitLayout}."); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsGenericParameter/source.cs b/snippets/csharp/System/Type/IsGenericParameter/source.cs index aff8b688c19..b129230bb08 100644 --- a/snippets/csharp/System/Type/IsGenericParameter/source.cs +++ b/snippets/csharp/System/Type/IsGenericParameter/source.cs @@ -1,19 +1,17 @@ // using System; -using System.Reflection; + using System.Collections.Generic; public class Test { private static void DisplayGenericTypeInfo(Type t) { - Console.WriteLine("\r\n{0}", t); + Console.WriteLine($"\r\n{t}"); - Console.WriteLine("\tIs this a generic type definition? {0}", - t.IsGenericTypeDefinition); + Console.WriteLine($"\tIs this a generic type definition? {t.IsGenericTypeDefinition}"); - Console.WriteLine("\tIs it a generic type? {0}", - t.IsGenericType); + Console.WriteLine($"\tIs it a generic type? {t.IsGenericType}"); // if (t.IsGenericType) @@ -22,8 +20,7 @@ private static void DisplayGenericTypeInfo(Type t) // Type[] typeArguments = t.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", - typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { @@ -32,13 +29,11 @@ private static void DisplayGenericTypeInfo(Type t) // if (tParam.IsGenericParameter) { - Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})", - tParam, - tParam.GenericParameterPosition); + Console.WriteLine($"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})"); } else { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } @@ -51,8 +46,8 @@ public static void Main() Console.WriteLine(" generic type definition, and an ordinary type."); // Create a Dictionary of Test objects, using strings for the - // keys. - Dictionary d = new Dictionary(); + // keys. + Dictionary d = new(); // Display information for the constructed type and its generic // type definition. diff --git a/snippets/csharp/System/Type/IsGenericType/remarks.cs b/snippets/csharp/System/Type/IsGenericType/remarks.cs index bfa44897d58..7eb2ddd091c 100644 --- a/snippets/csharp/System/Type/IsGenericType/remarks.cs +++ b/snippets/csharp/System/Type/IsGenericType/remarks.cs @@ -1,17 +1,17 @@ -using System; -using System.Reflection; + + // -public class Base {} +public class Base { } public class Derived : Base { - public G> F; + public G> F; - public class Nested {} + public class Nested { } } -public class G {} +public class G { } // class Example @@ -19,4 +19,4 @@ class Example public static void Main() { } -} \ No newline at end of file +} diff --git a/snippets/csharp/System/Type/IsGenericType/source.cs b/snippets/csharp/System/Type/IsGenericType/source.cs index da802f2948b..3525ca2d4ab 100644 --- a/snippets/csharp/System/Type/IsGenericType/source.cs +++ b/snippets/csharp/System/Type/IsGenericType/source.cs @@ -1,17 +1,17 @@ // using System; -using System.Reflection; -public class Base {} + +public class Base { } public class Derived : Base { - public G> F; + public G> F; - public class Nested {} + public class Nested { } } -public class G {} +public class G { } class Example { @@ -48,17 +48,13 @@ public static void Main() public static void DisplayGenericType(Type t, string caption) { - Console.WriteLine("\n{0}", caption); - Console.WriteLine(" Type: {0}", t); - - Console.WriteLine("\t IsGenericType: {0}", - t.IsGenericType); - Console.WriteLine("\t IsGenericTypeDefinition: {0}", - t.IsGenericTypeDefinition); - Console.WriteLine("\tContainsGenericParameters: {0}", - t.ContainsGenericParameters); - Console.WriteLine("\t IsGenericParameter: {0}", - t.IsGenericParameter); + Console.WriteLine($"\n{caption}"); + Console.WriteLine($" Type: {t}"); + + Console.WriteLine($"\t IsGenericType: {t.IsGenericType}"); + Console.WriteLine($"\t IsGenericTypeDefinition: {t.IsGenericTypeDefinition}"); + Console.WriteLine($"\tContainsGenericParameters: {t.ContainsGenericParameters}"); + Console.WriteLine($"\t IsGenericParameter: {t.IsGenericParameter}"); } } diff --git a/snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs b/snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs index 580f0dd5afa..04423ff0798 100644 --- a/snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs +++ b/snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs @@ -1,11 +1,11 @@ // using System; -public interface IExample {} +public interface IExample { } -public class BaseClass : IExample {} +public class BaseClass : IExample { } -public class DerivedClass : BaseClass {} +public class DerivedClass : BaseClass { } public class Example { @@ -18,16 +18,11 @@ public static void Main() var derived1Type = derived1.GetType(); int[] arr = new int[11]; - Console.WriteLine("Is int[] an instance of the Array class? {0}.", - typeof(Array).IsInstanceOfType(arr)); - Console.WriteLine("Is base1 an instance of BaseClass? {0}.", - base1Type.IsInstanceOfType(base1)); - Console.WriteLine("Is derived1 an instance of BaseClass? {0}.", - base1Type.IsInstanceOfType(derived1)); - Console.WriteLine("Is base1 an instance of IExample? {0}.", - interfaceType.IsInstanceOfType(base1)); - Console.WriteLine("Is derived1 an instance of IExample? {0}.", - interfaceType.IsInstanceOfType(derived1)); + Console.WriteLine($"Is int[] an instance of the Array class? {typeof(Array).IsInstanceOfType(arr)}."); + Console.WriteLine($"Is base1 an instance of BaseClass? {base1Type.IsInstanceOfType(base1)}."); + Console.WriteLine($"Is derived1 an instance of BaseClass? {base1Type.IsInstanceOfType(derived1)}."); + Console.WriteLine($"Is base1 an instance of IExample? {interfaceType.IsInstanceOfType(base1)}."); + Console.WriteLine($"Is derived1 an instance of IExample? {interfaceType.IsInstanceOfType(derived1)}."); } } // The example displays the following output: @@ -36,4 +31,4 @@ public static void Main() // Is derived1 an instance of BaseClass? True. // Is base1 an instance of IExample? True. // Is derived1 an instance of IExample? True. -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsInterface/type_isinterface.cs b/snippets/csharp/System/Type/IsInterface/type_isinterface.cs index 555886437f5..da7ae8eca29 100644 --- a/snippets/csharp/System/Type/IsInterface/type_isinterface.cs +++ b/snippets/csharp/System/Type/IsInterface/type_isinterface.cs @@ -6,22 +6,22 @@ interface myIFace } class MyIsInterface { - public static void Main(string []args) + public static void Main(string[] args) { try { // Get the IsInterface attribute for myIFace. bool myBool1 = typeof(myIFace).IsInterface; //Display the IsInterface attribute for myIFace. - Console.WriteLine("Is the specified type an interface? {0}.", myBool1); + Console.WriteLine($"Is the specified type an interface? {myBool1}."); // Get the attribute IsInterface for MyIsInterface. bool myBool2 = typeof(MyIsInterface).IsInterface; //Display the IsInterface attribute for MyIsInterface. - Console.WriteLine("Is the specified type an interface? {0}.", myBool2); + Console.WriteLine($"Is the specified type an interface? {myBool2}."); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("\nAn exception occurred: {0}.", e.Message); + Console.WriteLine($"\nAn exception occurred: {e.Message}."); } } } @@ -30,4 +30,4 @@ public static void Main(string []args) Is the specified type an interface? True. Is the specified type an interface? False. */ -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs b/snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs index 1b37af41198..efb0c46cf9f 100644 --- a/snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs +++ b/snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs @@ -1,7 +1,7 @@ // using System; -using System.Reflection; -using System.ComponentModel; + + using System.Runtime.InteropServices; class MyTypeSequential1 { @@ -9,24 +9,24 @@ class MyTypeSequential1 [StructLayoutAttribute(LayoutKind.Sequential)] class MyTypeSequential2 { - public static void Main(string []args) + public static void Main(string[] args) { try { // Create an instance of myTypeSeq1. - MyTypeSequential1 myObj1 = new MyTypeSequential1(); + MyTypeSequential1 myObj1 = new(); Type myTypeObj1 = myObj1.GetType(); // Check for and display the SequentialLayout attribute. - Console.WriteLine("\nThe object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential); + Console.WriteLine($"\nThe object myObj1 has IsLayoutSequential: {myObj1.GetType().IsLayoutSequential}."); // Create an instance of 'myTypeSeq2' class. - MyTypeSequential2 myObj2 = new MyTypeSequential2(); + MyTypeSequential2 myObj2 = new(); Type myTypeObj2 = myObj2.GetType(); // Check for and display the SequentialLayout attribute. - Console.WriteLine("\nThe object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential); + Console.WriteLine($"\nThe object myObj2 has IsLayoutSequential: {myObj2.GetType().IsLayoutSequential}."); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("\nAn exception occurred: {0}", e.Message); + Console.WriteLine($"\nAn exception occurred: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs b/snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs index 02eb5237740..1a46e14a2a4 100644 --- a/snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs +++ b/snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs @@ -4,16 +4,13 @@ public class MyTypeDelegatorClass : TypeDelegator { public string myElementType = null; - private Type myType = null ; - public MyTypeDelegatorClass(Type myType) : base(myType) - { - this.myType = myType; - } + private Type myType = null; + public MyTypeDelegatorClass(Type myType) : base(myType) => this.myType = myType; // Override IsMarshalByRefImpl. protected override bool IsMarshalByRefImpl() { // Determine whether the type is marshalled by reference. - if(myType.IsMarshalByRef) + if (myType.IsMarshalByRef) { myElementType = " marshalled by reference"; return true; @@ -28,10 +25,10 @@ public static void Main() try { MyTypeDelegatorClass myType; - Console.WriteLine ("Determine whether MyContextBoundClass is marshalled by reference."); + Console.WriteLine("Determine whether MyContextBoundClass is marshalled by reference."); // Determine whether MyContextBoundClass type is marshalled by reference. - myType = new MyTypeDelegatorClass(typeof(MyContextBoundClass)); - if( myType.IsMarshalByRef ) + myType = new(typeof(MyContextBoundClass)); + if (myType.IsMarshalByRef) { Console.WriteLine(typeof(MyContextBoundClass) + " is marshalled by reference."); } @@ -41,9 +38,9 @@ public static void Main() } // Determine whether int type is marshalled by reference. - myType = new MyTypeDelegatorClass(typeof(int)); - Console.WriteLine ("\nDetermine whether int is marshalled by reference."); - if( myType.IsMarshalByRef) + myType = new(typeof(int)); + Console.WriteLine("\nDetermine whether int is marshalled by reference."); + if (myType.IsMarshalByRef) { Console.WriteLine(typeof(int) + " is marshalled by reference."); } @@ -52,9 +49,9 @@ public static void Main() Console.WriteLine(typeof(int) + " is not marshalled by reference."); } } - catch( Exception e ) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message); + Console.WriteLine($"Exception: {e.Message}"); } } } diff --git a/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs b/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs index 46513f3d2d6..b1f485a179a 100644 --- a/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs +++ b/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs @@ -5,19 +5,19 @@ public class OuterClass { private class PrivateClass - {} + { } protected class ProtectedClass - {} + { } internal class InternalClass - {} + { } protected internal class ProtectedInternalClass - {} + { } public class PublicClass - {} + { } public static void Main() { @@ -29,17 +29,18 @@ public static void Main() typeof(OuterClass.InternalClass), typeof(OuterClass.ProtectedInternalClass) }; // Display the property values of each nested class. - foreach (var type in types) { - Console.WriteLine("\n{0} property values:", type.Name); - Console.WriteLine(" Public Class: {0}", type.IsPublic); - Console.WriteLine(" Not a Public Class: {0}", type.IsNotPublic); - Console.WriteLine(" Nested Class: {0}", type.IsNested); - Console.WriteLine(" Nested Private Class: {0}", type.IsNestedPrivate); - Console.WriteLine(" Nested Internal Class: {0}", type.IsNestedAssembly); - Console.WriteLine(" Nested Protected Class: {0}", type.IsNestedFamily); - Console.WriteLine(" Nested Family Or Assembly Class: {0}", type.IsNestedFamORAssem); - Console.WriteLine(" Nested Family And Assembly Class: {0}", type.IsNestedFamANDAssem); - Console.WriteLine(" Nested Public Class: {0}", type.IsNestedPublic); + foreach (var type in types) + { + Console.WriteLine($"\n{type.Name} property values:"); + Console.WriteLine($" Public Class: {type.IsPublic}"); + Console.WriteLine($" Not a Public Class: {type.IsNotPublic}"); + Console.WriteLine($" Nested Class: {type.IsNested}"); + Console.WriteLine($" Nested Private Class: {type.IsNestedPrivate}"); + Console.WriteLine($" Nested Internal Class: {type.IsNestedAssembly}"); + Console.WriteLine($" Nested Protected Class: {type.IsNestedFamily}"); + Console.WriteLine($" Nested Family Or Assembly Class: {type.IsNestedFamORAssem}"); + Console.WriteLine($" Nested Family And Assembly Class: {type.IsNestedFamANDAssem}"); + Console.WriteLine($" Nested Public Class: {type.IsNestedPublic}"); } } } @@ -109,4 +110,4 @@ public static void Main() // Nested Family Or Assembly Class: True // Nested Family And Assembly Class: False // Nested Public Class: False -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsNotPublic/source.cs b/snippets/csharp/System/Type/IsNotPublic/source.cs index 2076d9f9ff1..7f12663f242 100644 --- a/snippets/csharp/System/Type/IsNotPublic/source.cs +++ b/snippets/csharp/System/Type/IsNotPublic/source.cs @@ -1,6 +1,6 @@ // using System; -using System.IO; + using System.Reflection; class Example @@ -11,10 +11,8 @@ public static void Main() Type t = Type.GetType("System.IO.File"); MemberInfo[] members = t.GetMembers(); // Get and display the DeclaringType method. - Console.WriteLine("\nThere are {0} members in {1}.", - members.Length, t.FullName); - Console.WriteLine("Is {0} non-public? {1}", - t.FullName, t.IsNotPublic); + Console.WriteLine($"\nThere are {members.Length} members in {t.FullName}."); + Console.WriteLine($"Is {t.FullName} non-public? {t.IsNotPublic}"); } } // The example displays output like the following: diff --git a/snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs b/snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs index 9dd4c38e560..9d4072cffe3 100644 --- a/snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs +++ b/snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs @@ -4,16 +4,13 @@ public class MyTypeDelegatorClass : TypeDelegator { public string myElementType = null; - private Type myType = null ; - public MyTypeDelegatorClass(Type myType) : base(myType) - { - this.myType = myType; - } + private Type myType = null; + public MyTypeDelegatorClass(Type myType) : base(myType) => this.myType = myType; // Override the IsPrimitiveImpl. protected override bool IsPrimitiveImpl() { // Determine whether the type is a primitive type. - if(myType.IsPrimitive) + if (myType.IsPrimitive) { myElementType = "primitive"; return true; @@ -27,11 +24,11 @@ public static void Main() { try { - Console.WriteLine ("Determine whether int is a primitive type."); + Console.WriteLine("Determine whether int is a primitive type."); MyTypeDelegatorClass myType; - myType = new MyTypeDelegatorClass(typeof(int)); + myType = new(typeof(int)); // Determine whether int is a primitive type. - if( myType.IsPrimitive) + if (myType.IsPrimitive) { Console.WriteLine(typeof(int) + " is a primitive type."); } @@ -39,10 +36,10 @@ public static void Main() { Console.WriteLine(typeof(int) + " is not a primitive type."); } - Console.WriteLine ("\nDetermine whether string is a primitive type."); - myType = new MyTypeDelegatorClass(typeof(string)); + Console.WriteLine("\nDetermine whether string is a primitive type."); + myType = new(typeof(string)); // Determine if string is a primitive type. - if( myType.IsPrimitive) + if (myType.IsPrimitive) { Console.WriteLine(typeof(string) + " is a primitive type."); } @@ -51,10 +48,10 @@ public static void Main() Console.WriteLine(typeof(string) + " is not a primitive type."); } } - catch( Exception e ) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message); + Console.WriteLine($"Exception: {e.Message}"); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsPublic/type_ispublic.cs b/snippets/csharp/System/Type/IsPublic/type_ispublic.cs index 40c87ffc257..ad92c0f08e9 100644 --- a/snippets/csharp/System/Type/IsPublic/type_ispublic.cs +++ b/snippets/csharp/System/Type/IsPublic/type_ispublic.cs @@ -7,15 +7,15 @@ public class TestClass public class Example { - public static void Main() - { - TestClass testClassInstance = new TestClass(); - // Get the type of myTestClassInstance. - Type testType = testClassInstance.GetType(); - // Get the IsPublic property of testClassInstance. - bool isPublic = testType.IsPublic; - Console.WriteLine("Is {0} public? {1}", testType.FullName, isPublic); - } + public static void Main() + { + TestClass testClassInstance = new(); + // Get the type of myTestClassInstance. + Type testType = testClassInstance.GetType(); + // Get the IsPublic property of testClassInstance. + bool isPublic = testType.IsPublic; + Console.WriteLine($"Is {testType.FullName} public? {isPublic}"); + } } // The example displays the following output: // Is TestClass public? True diff --git a/snippets/csharp/System/Type/IsSealed/type_issealed.cs b/snippets/csharp/System/Type/IsSealed/type_issealed.cs index 90ddf688fc3..587338a1280 100644 --- a/snippets/csharp/System/Type/IsSealed/type_issealed.cs +++ b/snippets/csharp/System/Type/IsSealed/type_issealed.cs @@ -1,23 +1,23 @@ // using System; - public class Example - { - // Declare InnerClass as sealed. - sealed public class InnerClass - { - } +public class Example +{ + // Declare InnerClass as sealed. + sealed public class InnerClass + { + } - public static void Main() - { - InnerClass inner = new InnerClass(); - // Get the type of InnerClass. - Type innerType = inner.GetType(); - // Get the IsSealed property of innerClass. - bool isSealed = innerType.IsSealed; - Console.WriteLine("{0} is sealed: {1}.", innerType.FullName, isSealed); - } + public static void Main() + { + InnerClass inner = new(); + // Get the type of InnerClass. + Type innerType = inner.GetType(); + // Get the IsSealed property of innerClass. + bool isSealed = innerType.IsSealed; + Console.WriteLine($"{innerType.FullName} is sealed: {isSealed}."); + } } // The example displays the following output: // Example+InnerClass is sealed: True. -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs b/snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs index 37ff4c1c38c..eecfa854b24 100644 --- a/snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs +++ b/snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs @@ -3,28 +3,23 @@ public interface IInterface { - void Display(); + void Display(); } public class Implementation : IInterface { - public void Display() - { - Console.WriteLine("The implementation..."); - } + public void Display() => Console.WriteLine("The implementation..."); } public class Example { - public static void Main() - { - Console.WriteLine("Implementation is a subclass of IInterface: {0}", - typeof(Implementation).IsSubclassOf(typeof(IInterface))); - Console.WriteLine("IInterface is assignable from Implementation: {0}", - typeof(IInterface).IsAssignableFrom(typeof(Implementation))); - } + public static void Main() + { + Console.WriteLine($"Implementation is a subclass of IInterface: {typeof(Implementation).IsSubclassOf(typeof(IInterface))}"); + Console.WriteLine($"IInterface is assignable from Implementation: {typeof(IInterface).IsAssignableFrom(typeof(Implementation))}"); + } } // The example displays the following output: // Implementation is a subclass of IInterface: False // IInterface is assignable from Implementation: True -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs b/snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs index 24d67175f8c..45b923c27ac 100644 --- a/snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs +++ b/snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs @@ -6,12 +6,8 @@ public class DerivedC1 : Class1 { } class IsSubclassTest { - public static void Main() - { - Console.WriteLine("DerivedC1 subclass of Class1: {0}", - typeof(DerivedC1).IsSubclassOf(typeof(Class1))); - } + public static void Main() => Console.WriteLine($"DerivedC1 subclass of Class1: {typeof(DerivedC1).IsSubclassOf(typeof(Class1))}"); } // The example displays the following output: // DerivedC1 subclass of Class1: True -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/IsValueType/type_isvaluetype.cs b/snippets/csharp/System/Type/IsValueType/type_isvaluetype.cs index 79ba552d617..07c9ff64260 100644 --- a/snippets/csharp/System/Type/IsValueType/type_isvaluetype.cs +++ b/snippets/csharp/System/Type/IsValueType/type_isvaluetype.cs @@ -7,7 +7,7 @@ enum NumEnum { One, Two } public class Example { - public static void Main(string []args) + public static void Main(string[] args) { bool flag = false; NumEnum testEnum = NumEnum.One; @@ -15,7 +15,7 @@ public static void Main(string []args) Type t = testEnum.GetType(); // Get the IsValueType property of the testEnum variable. flag = t.IsValueType; - Console.WriteLine("{0} is a value type: {1}", t.FullName, flag); + Console.WriteLine($"{t.FullName} is a value type: {flag}"); } } // The example displays the following output: diff --git a/snippets/csharp/System/Type/IsVisible/source.cs b/snippets/csharp/System/Type/IsVisible/source.cs index 66278859ddc..39fc211220f 100644 --- a/snippets/csharp/System/Type/IsVisible/source.cs +++ b/snippets/csharp/System/Type/IsVisible/source.cs @@ -1,30 +1,22 @@ // using System; -internal class InternalOnly +internal class InternalOnly { - public class Nested {} + public class Nested { } } public class Example { - public class Nested {} + public class Nested { } public static void Main() { Type t = typeof(InternalOnly.Nested); - Console.WriteLine( - "Is the {0} class visible outside the assembly? {1}", - t.FullName, - t.IsVisible - ); + Console.WriteLine($"Is the {t.FullName} class visible outside the assembly? {t.IsVisible}"); t = typeof(Example.Nested); - Console.WriteLine( - "Is the {0} class visible outside the assembly? {1}", - t.FullName, - t.IsVisible - ); + Console.WriteLine($"Is the {t.FullName} class visible outside the assembly? {t.IsVisible}"); } } diff --git a/snippets/csharp/System/Type/MakeByRefType/source.cs b/snippets/csharp/System/Type/MakeByRefType/source.cs index 7a9ee920685..d58029186c5 100644 --- a/snippets/csharp/System/Type/MakeByRefType/source.cs +++ b/snippets/csharp/System/Type/MakeByRefType/source.cs @@ -9,12 +9,12 @@ public static void Main() // Create a Type object that represents a one-dimensional // array of Example objects. Type t = typeof(Example).MakeArrayType(); - Console.WriteLine("\r\nArray of Example: {0}", t); + Console.WriteLine($"\r\nArray of Example: {t}"); // Create a Type object that represents a two-dimensional // array of Example objects. t = typeof(Example).MakeArrayType(2); - Console.WriteLine("\r\nTwo-dimensional array of Example: {0}", t); + Console.WriteLine($"\r\nTwo-dimensional array of Example: {t}"); // Demonstrate an exception when an invalid array rank is // specified. @@ -22,15 +22,15 @@ public static void Main() { t = typeof(Example).MakeArrayType(-1); } - catch(Exception ex) + catch (Exception ex) { - Console.WriteLine("\r\n{0}", ex); + Console.WriteLine($"\r\n{ex}"); } // Create a Type object that represents a ByRef parameter // of type Example. t = typeof(Example).MakeByRefType(); - Console.WriteLine("\r\nByRef Example: {0}", t); + Console.WriteLine($"\r\nByRef Example: {t}"); // Get a Type object representing the Example class, a // MethodInfo representing the "Test" method, a ParameterInfo @@ -42,12 +42,12 @@ public static void Main() MethodInfo mi = t2.GetMethod("Test"); ParameterInfo pi = mi.GetParameters()[0]; Type pt = pi.ParameterType; - Console.WriteLine("Are the ByRef types equal? {0}", (t == pt)); + Console.WriteLine($"Are the ByRef types equal? {(t == pt)}"); // Create a Type object that represents a pointer to an // Example object. t = typeof(Example).MakePointerType(); - Console.WriteLine("\r\nPointer to Example: {0}", t); + Console.WriteLine($"\r\nPointer to Example: {t}"); } // A sample method with a ByRef parameter. diff --git a/snippets/csharp/System/Type/MakeGenericType/remarks.cs b/snippets/csharp/System/Type/MakeGenericType/remarks.cs index a9f8c04adb2..a6e7734a444 100644 --- a/snippets/csharp/System/Type/MakeGenericType/remarks.cs +++ b/snippets/csharp/System/Type/MakeGenericType/remarks.cs @@ -1,4 +1,4 @@ -using System; + // public class Base { } @@ -10,13 +10,13 @@ public class Outermost { public class Inner { - public class Innermost1 {} - public class Innermost2 {} + public class Innermost1 { } + public class Innermost2 { } } } // class ProgStubClass { - public static void Main() {} -} \ No newline at end of file + public static void Main() { } +} diff --git a/snippets/csharp/System/Type/MakeGenericType/source.cs b/snippets/csharp/System/Type/MakeGenericType/source.cs index 38ecc20de1c..05b829cf3fb 100644 --- a/snippets/csharp/System/Type/MakeGenericType/source.cs +++ b/snippets/csharp/System/Type/MakeGenericType/source.cs @@ -1,6 +1,6 @@ // using System; -using System.Reflection; + using System.Collections.Generic; public class Test @@ -9,10 +9,10 @@ public static void Main() { Console.WriteLine("\r\n--- Create a constructed type from the generic Dictionary type."); - // Create a type object representing the generic Dictionary - // type, by omitting the type arguments (but keeping the + // Create a type object representing the generic Dictionary + // type, by omitting the type arguments (but keeping the // comma that separates them, so the compiler can infer the - // number of type parameters). + // number of type parameters). Type generic = typeof(Dictionary<,>); DisplayTypeInfo(generic); @@ -30,27 +30,24 @@ public static void Main() // obtained using typeof() and GetGenericTypeDefinition(). Console.WriteLine("\r\n--- Compare types obtained by different methods:"); - Type t = typeof(Dictionary); - Console.WriteLine("\tAre the constructed types equal? {0}", t == constructed); - Console.WriteLine("\tAre the generic types equal? {0}", - t.GetGenericTypeDefinition() == generic); + Type t = typeof(Dictionary); + Console.WriteLine($"\tAre the constructed types equal? {t == constructed}"); + Console.WriteLine($"\tAre the generic types equal? {t.GetGenericTypeDefinition() == generic}"); } private static void DisplayTypeInfo(Type t) { - Console.WriteLine("\r\n{0}", t); + Console.WriteLine($"\r\n{t}"); - Console.WriteLine("\tIs this a generic type definition? {0}", - t.IsGenericTypeDefinition); + Console.WriteLine($"\tIs this a generic type definition? {t.IsGenericTypeDefinition}"); - Console.WriteLine("\tIs it a generic type? {0}", - t.IsGenericType); + Console.WriteLine($"\tIs it a generic type? {t.IsGenericType}"); Type[] typeArguments = t.GetGenericArguments(); - Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length); + Console.WriteLine($"\tList type arguments ({typeArguments.Length}):"); foreach (Type tParam in typeArguments) { - Console.WriteLine("\t\t{0}", tParam); + Console.WriteLine($"\t\t{tParam}"); } } } diff --git a/snippets/csharp/System/Type/Missing/source.cs b/snippets/csharp/System/Type/Missing/source.cs index 76b60861815..008aed87a8d 100644 --- a/snippets/csharp/System/Type/Missing/source.cs +++ b/snippets/csharp/System/Type/Missing/source.cs @@ -27,9 +27,9 @@ public static void Main() BindingFlags bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding; - t.InvokeMember("MyMethod", bf, null, o, new object[] {10, 55.3, 12}); - t.InvokeMember("MyMethod", bf, null, o, new object[] {10, 1.3, Type.Missing}); - t.InvokeMember("MyMethod", bf, null, o, new object[] {10, Type.Missing, Type.Missing}); + t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, 55.3, 12 }); + t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, 1.3, Type.Missing }); + t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, Type.Missing, Type.Missing }); } private static object GenerateObjectFromSource(string objectName, @@ -37,10 +37,11 @@ private static object GenerateObjectFromSource(string objectName, { object genObject = null; CodeDomProvider codeProvider = CodeDomProvider.CreateProvider(providerName); - CompilerParameters cp = new CompilerParameters(); - - cp.GenerateExecutable = false; - cp.GenerateInMemory = true; + CompilerParameters cp = new() + { + GenerateExecutable = false, + GenerateInMemory = true + }; CompilerResults results = codeProvider.CompileAssemblyFromSource(cp, sourceLines); @@ -52,4 +53,4 @@ private static object GenerateObjectFromSource(string objectName, return genObject; } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/Type/Module/type_tostring.cs b/snippets/csharp/System/Type/Module/type_tostring.cs index fe2b9678d35..2e82bf67882 100644 --- a/snippets/csharp/System/Type/Module/type_tostring.cs +++ b/snippets/csharp/System/Type/Module/type_tostring.cs @@ -1,4 +1,4 @@ -// +// using System; namespace MyNamespace @@ -12,14 +12,14 @@ public class Example { public static void Main() { - Type myType = typeof(MyNamespace.MyClass); - Console.WriteLine("Displaying information about {0}:", myType); - // Get the namespace of the myClass class. - Console.WriteLine(" Namespace: {0}.", myType.Namespace); - // Get the name of the module. - Console.WriteLine(" Module: {0}.", myType.Module); - // Get the fully qualified type name. - Console.WriteLine(" Fully qualified name: {0}.", myType.ToString()); + Type myType = typeof(MyNamespace.MyClass); + Console.WriteLine($"Displaying information about {myType}:"); + // Get the namespace of the myClass class. + Console.WriteLine($" Namespace: {myType.Namespace}."); + // Get the name of the module. + Console.WriteLine($" Module: {myType.Module}."); + // Get the fully qualified type name. + Console.WriteLine($" Fully qualified name: {myType.ToString()}."); } } // The example displays the following output: @@ -27,4 +27,4 @@ public static void Main() // Namespace: MyNamespace. // Module: type_tostring.exe. // Fully qualified name: MyNamespace.MyClass. -// +// diff --git a/snippets/csharp/System/Type/Overview/Equals1.cs b/snippets/csharp/System/Type/Overview/Equals1.cs index e3a44d20d3f..ea5f7fc2644 100644 --- a/snippets/csharp/System/Type/Overview/Equals1.cs +++ b/snippets/csharp/System/Type/Overview/Equals1.cs @@ -1,4 +1,4 @@ -using System; +using System; public class Example1 { @@ -14,9 +14,9 @@ public static void Main() Type t = number1.GetType(); // Compare types of all objects with number1. - Console.WriteLine($"Type of number1 and number2 are equal: {Object.ReferenceEquals(t, number2.GetType())}"); - Console.WriteLine($"Type of number1 and number3 are equal: {Object.ReferenceEquals(t, number3.GetType())}"); - Console.WriteLine($"Type of number1 and number4 are equal: {Object.ReferenceEquals(t, number4.GetType())}"); + Console.WriteLine($"Type of number1 and number2 are equal: {object.ReferenceEquals(t, number2.GetType())}"); + Console.WriteLine($"Type of number1 and number3 are equal: {object.ReferenceEquals(t, number3.GetType())}"); + Console.WriteLine($"Type of number1 and number4 are equal: {object.ReferenceEquals(t, number4.GetType())}"); // The example displays the following output: // Type of number1 and number2 are equal: False diff --git a/snippets/csharp/System/Type/Overview/GetType1.cs b/snippets/csharp/System/Type/Overview/GetType1.cs index ecf2365b6d1..45414f8bb6a 100644 --- a/snippets/csharp/System/Type/Overview/GetType1.cs +++ b/snippets/csharp/System/Type/Overview/GetType1.cs @@ -1,4 +1,4 @@ -using System; +using System; public class Example2 { @@ -6,7 +6,7 @@ public static void Main() { // object[] values = { "word", true, 120, 136.34, 'a' }; - foreach (var value in values) + foreach (object value in values) Console.WriteLine($"{value} - type {value.GetType().Name}"); // The example displays the following output: diff --git a/snippets/csharp/System/Type/Overview/source.cs b/snippets/csharp/System/Type/Overview/source.cs index 2e479978b80..89e4f8a55bf 100644 --- a/snippets/csharp/System/Type/Overview/source.cs +++ b/snippets/csharp/System/Type/Overview/source.cs @@ -9,14 +9,14 @@ class Example3 { static void Main() { - Type t = typeof(String); + Type t = typeof(string); MethodInfo substr = t.GetMethod("Substring", new Type[] { typeof(int), typeof(int) }); - Object result = - substr.Invoke("Hello, World!", new Object[] { 7, 5 }); - Console.WriteLine("{0} returned \"{1}\".", substr, result); + object result = + substr.Invoke("Hello, World!", new object[] { 7, 5 }); + Console.WriteLine($"{substr} returned \"{result}\"."); } } diff --git a/snippets/csharp/System/Type/ReflectedType/source.cs b/snippets/csharp/System/Type/ReflectedType/source.cs index bf060d9a664..fb57e57ee7a 100644 --- a/snippets/csharp/System/Type/ReflectedType/source.cs +++ b/snippets/csharp/System/Type/ReflectedType/source.cs @@ -1,6 +1,6 @@ // using System; -using System.Reflection; + public abstract class MyClassA { @@ -11,8 +11,7 @@ public abstract class MyClassB public static void Main(string[] args) { - Console.WriteLine("Reflected type of MyClassB is {0}", - typeof(MyClassB).ReflectedType); //outputs MyClassA, the enclosing class + Console.WriteLine($"Reflected type of MyClassB is {typeof(MyClassB).ReflectedType}"); //outputs MyClassA, the enclosing class } } // diff --git a/snippets/csharp/System/Type/StructLayoutAttribute/source.cs b/snippets/csharp/System/Type/StructLayoutAttribute/source.cs index 6d97f7ca5cc..f8c6f75589e 100644 --- a/snippets/csharp/System/Type/StructLayoutAttribute/source.cs +++ b/snippets/csharp/System/Type/StructLayoutAttribute/source.cs @@ -11,17 +11,15 @@ public static void Main() DisplayLayoutAttribute(typeof(Test2).StructLayoutAttribute); } - private static void DisplayLayoutAttribute(StructLayoutAttribute sla) - { - Console.WriteLine("\r\nCharSet: "+sla.CharSet.ToString()+"\r\n Pack: "+sla.Pack.ToString()+"\r\n Size: "+sla.Size.ToString()+"\r\n Value: "+sla.Value.ToString()); - } + private static void DisplayLayoutAttribute(StructLayoutAttribute sla) => Console.WriteLine("\r\nCharSet: " + sla.CharSet.ToString() + "\r\n Pack: " + sla.Pack.ToString() + "\r\n Size: " + sla.Size.ToString() + "\r\n Value: " + sla.Value.ToString()); public struct Test1 { public byte B1; public short S; public byte B2; } - [StructLayout(LayoutKind.Explicit, Pack=1)] public struct Test2 + [StructLayout(LayoutKind.Explicit, Pack = 1)] + public struct Test2 { [FieldOffset(0)] public byte B1; [FieldOffset(1)] public short S; diff --git a/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs b/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs index b734d2c81a9..bd7c070a57f 100644 --- a/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs +++ b/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs @@ -1,6 +1,6 @@ -// +// using System; -using System.Reflection; + class MyClass { public int myField = 10; @@ -12,7 +12,7 @@ public static void Main() { try { - MyClass myClass = new MyClass(); + MyClass myClass = new(); // Get the type of MyClass. Type myClassType = myClass.GetType(); @@ -22,9 +22,9 @@ public static void Main() DisplayTypeHandle(myClassHandle); } - catch(Exception e) + catch (Exception e) { - Console.WriteLine("Exception: {0}", e.Message ); + Console.WriteLine($"Exception: {e.Message}"); } } @@ -34,7 +34,7 @@ public static void DisplayTypeHandle(RuntimeTypeHandle myTypeHandle) Type myType = Type.GetTypeFromHandle(myTypeHandle); // Display the type. Console.WriteLine("\nDisplaying the type from the handle:\n"); - Console.WriteLine("The type is {0}.", myType.ToString()); + Console.WriteLine($"The type is {myType.ToString()}."); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs b/snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs index b6d72e3e237..dd617df1297 100644 --- a/snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs +++ b/snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs @@ -5,7 +5,7 @@ public class MissingEx1 { public static void Main() { - Person p = new Person("John", "Doe"); + Person p = new("John", "Doe"); Console.WriteLine(p); } } @@ -17,10 +17,7 @@ public class Person readonly string _fName; readonly string _lName; - static Person() - { - s_infoModule = new InfoModule(DateTime.UtcNow); - } + static Person() => s_infoModule = new(DateTime.UtcNow); public Person(string fName, string lName) { @@ -29,16 +26,13 @@ public Person(string fName, string lName) s_infoModule.Increment(); } - public override string ToString() - { - return string.Format("{0} {1}", _fName, _lName); - } + public override string ToString() => $"{_fName} {_lName}"; } // The example displays the following output if missing1a.dll is renamed or removed: -// Unhandled Exception: System.TypeInitializationException: -// The type initializer for 'Person' threw an exception. ---> -// System.IO.FileNotFoundException: Could not load file or assembly -// 'Missing1a, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' +// Unhandled Exception: System.TypeInitializationException: +// The type initializer for 'Person' threw an exception. ---> +// System.IO.FileNotFoundException: Could not load file or assembly +// 'Missing1a, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' // or one of its dependencies. The system cannot find the file specified. // at Person..cctor() // --- End of inner exception stack trace --- diff --git a/snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs b/snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs index 56903779fba..cbefba5bd3b 100644 --- a/snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs +++ b/snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs @@ -3,22 +3,13 @@ public class InfoModule { - private DateTime firstUse; - private int ctr = 0; + private DateTime firstUse; + private int ctr = 0; - public InfoModule(DateTime dat) - { - firstUse = dat; - } - - public int Increment() - { - return ++ctr; - } - - public DateTime GetInitializationTime() - { - return firstUse; - } + public InfoModule(DateTime dat) => firstUse = dat; + + public int Increment() => ++ctr; + + public DateTime GetInitializationTime() => firstUse; } // diff --git a/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs b/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs index dfeda845b44..18511876f80 100644 --- a/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs +++ b/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs @@ -1,7 +1,7 @@ // using System; using System.Text.RegularExpressions; -using static System.Net.Mime.MediaTypeNames; + public class RegexEx1 { @@ -11,7 +11,7 @@ public static void Run() // Set a timeout interval of -2 seconds. domain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(-2)); - Regex rgx = new Regex("[aeiouy]"); + Regex rgx = new("[aeiouy]"); Console.WriteLine($"Regular expression pattern: {rgx.ToString()}"); Console.WriteLine($"Timeout interval for this regex: {rgx.MatchTimeout.TotalSeconds} seconds"); } diff --git a/snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs b/snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs index ac866e10443..4a0392148a4 100644 --- a/snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs +++ b/snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs @@ -3,28 +3,28 @@ public class Example { - private static TestClass test = new TestClass(3); - - public static void Main() - { - Example ex = new Example(); - Console.WriteLine(test.Value); - } + private static TestClass test = new(3); + + public static void Main() + { + Example ex = new(); + Console.WriteLine(test.Value); + } } public class TestClass { - public readonly int Value; - - public TestClass(int value) - { - if (value < 0 || value > 1) throw new ArgumentOutOfRangeException(nameof(value)); - Value = value; - } + public readonly int Value; + + public TestClass(int value) + { + if (value < 0 || value > 1) throw new ArgumentOutOfRangeException(nameof(value)); + Value = value; + } } // The example displays the following output: -// Unhandled Exception: System.TypeInitializationException: -// The type initializer for 'Example' threw an exception. ---> +// Unhandled Exception: System.TypeInitializationException: +// The type initializer for 'Example' threw an exception. ---> // System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. // at TestClass..ctor(Int32 value) // at Example..cctor() diff --git a/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs b/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs index b8b4effd96b..1cbe390c379 100644 --- a/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs +++ b/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs @@ -3,25 +3,27 @@ public class Example { - public static void Main() - { - try { - // Call a method that throws an exception. - TypeLoadExceptionDemoClass.GenerateException(); - } - catch (TypeLoadException e) { - Console.WriteLine("TypeLoadException:\n {0}", e.Message); - } - } + public static void Main() + { + try + { + // Call a method that throws an exception. + TypeLoadExceptionDemoClass.GenerateException(); + } + catch (TypeLoadException e) + { + Console.WriteLine($"TypeLoadException:\n {e.Message}"); + } + } } class TypeLoadExceptionDemoClass { - public static bool GenerateException() - { - // Throw a TypeLoadException with a custom defined message. - throw new TypeLoadException("This is a custom TypeLoadException error message."); - } + public static bool GenerateException() + { + // Throw a TypeLoadException with a custom defined message. + throw new TypeLoadException("This is a custom TypeLoadException error message."); + } } // The example displays the following output: // TypeLoadException: diff --git a/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs b/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs index 51589e8ee66..5bb423a9c2d 100644 --- a/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs +++ b/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs @@ -12,42 +12,42 @@ as an inner exception.*/ public class TypeLoadException_Constructor3 { - public static void Main() - { - Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException."); - try - { - TypeLoadExceptionDemoClass3.GenerateException(); - } - catch (TypeLoadException e) - { - Console.WriteLine ("TypeLoadException: \n\tError Message = " + e.Message); - Console.WriteLine ("TypeLoadException: \n\tInnerException Message = " + e.InnerException.Message ); - } - catch (Exception e) - { - Console.WriteLine ("Exception: \n\tError Message = " + e.Message); - } - } + public static void Main() + { + Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException."); + try + { + TypeLoadExceptionDemoClass3.GenerateException(); + } + catch (TypeLoadException e) + { + Console.WriteLine("TypeLoadException: \n\tError Message = " + e.Message); + Console.WriteLine("TypeLoadException: \n\tInnerException Message = " + e.InnerException.Message); + } + catch (Exception e) + { + Console.WriteLine("Exception: \n\tError Message = " + e.Message); + } + } } class TypeLoadExceptionDemoClass3 { - // A call to this method will raise a TypeLoadException. - [DllImport("NonExistentDLL.DLL", EntryPoint="MethodNotExists")] - public static extern void NonExistentMethod(); + // A call to this method will raise a TypeLoadException. + [DllImport("NonExistentDLL.DLL", EntryPoint = "MethodNotExists")] + public static extern void NonExistentMethod(); - public static void GenerateException() - { - try - { - NonExistentMethod(); - } - catch (TypeLoadException e) - { - // Rethrow exception with the exception as inner exception - throw new TypeLoadException("This exception was raised due to a call to an invalid method.", e); - } - } + public static void GenerateException() + { + try + { + NonExistentMethod(); + } + catch (TypeLoadException e) + { + // Rethrow exception with the exception as inner exception + throw new TypeLoadException("This exception was raised due to a call to an invalid method.", e); + } + } } // diff --git a/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs b/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs index 0a4080a9a92..bc3ff020e9e 100644 --- a/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs +++ b/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs @@ -14,28 +14,27 @@ values are displayed. public class TypeLoadException_TypeName { - public static void Main() - { - // Get a reference to the assembly mscorlib.dll, which is always - // loaded. (System.String is defined in mscorlib.) - Assembly mscorlib = typeof(string).Assembly; + public static void Main() + { + // Get a reference to the assembly mscorlib.dll, which is always + // loaded. (System.String is defined in mscorlib.) + Assembly mscorlib = typeof(string).Assembly; - try - { - Console.WriteLine("Attempting to load a type that does not exist in mscorlib."); - // The boolean parameter causes an exception to be thrown if the - // type is not found. - Type myType = mscorlib.GetType("System.NonExistentType", true); - } - catch (TypeLoadException ex) - { - // Display the name of the type that was not found, and the - // exception message. - Console.WriteLine("TypeLoadException was caught. Type = '{0}'.", - ex.TypeName); - Console.WriteLine("Error Message = '{0}'", ex.Message); - } - } + try + { + Console.WriteLine("Attempting to load a type that does not exist in mscorlib."); + // The boolean parameter causes an exception to be thrown if the + // type is not found. + Type myType = mscorlib.GetType("System.NonExistentType", true); + } + catch (TypeLoadException ex) + { + // Display the name of the type that was not found, and the + // exception message. + Console.WriteLine($"TypeLoadException was caught. Type = '{ex.TypeName}'."); + Console.WriteLine($"Error Message = '{ex.Message}'"); + } + } } /* This code example produces output similar to the following: diff --git a/snippets/csharp/System/TypedReference/Overview/source.cs b/snippets/csharp/System/TypedReference/Overview/source.cs index 412e3377f61..70684dc3408 100644 --- a/snippets/csharp/System/TypedReference/Overview/source.cs +++ b/snippets/csharp/System/TypedReference/Overview/source.cs @@ -3,18 +3,18 @@ class TypedReferenceArray { - public static void Main() + public static void Main() + { + try { - try - { -// - Assembly.Load("mscorlib.dll").GetType("System.TypedReference[]"); -// - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } -} \ No newline at end of file + // + Assembly.Load("mscorlib.dll").GetType("System.TypedReference[]"); + // + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } +} From b3929dc14b293d616c23b465735eb7b9f925d7b4 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:47:33 -0700 Subject: [PATCH 2/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- snippets/csharp/System/Type/GetInterface/type_getinterface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs index 79809770bc2..171c6d29df4 100644 --- a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs +++ b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs @@ -37,7 +37,7 @@ public static void Main() Console.WriteLine(methodInfo); //Get the Interface methods for 'IDictionary' interface - InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary)); + InterfaceMapping interfaceMappingObj = objType.GetInterfaceMap(typeof(IDictionary)); arrayMemberInfo = interfaceMappingObj.InterfaceMethods; Console.WriteLine("\nHashtable class Implements the following IDictionary Interface methods :"); foreach (MemberInfo memberInfo in arrayMemberInfo) From bc577823518798a89c59ae49dd51c764e663b575 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 12 Aug 2026 17:11:12 -0700 Subject: [PATCH 3/4] add missing snippets --- .../System/Type/Attributes/attributes1.cs | 4 +-- .../System/Type/DeclaringMethod/source.cs | 2 +- .../Type/DefaultBinder/type_defaultbinder.cs | 2 +- .../System/Type/EmptyTypes/source.csproj | 10 +++++++ .../System/Type/Equals/EqualsEx1.csproj | 10 +++++++ .../csharp/System/Type/Equals/source.csproj | 10 +++++++ .../FilterAttribute/type_filterattribute.cs | 2 +- .../System/Type/FilterName/source.csproj | 10 +++++++ .../type_filternameignorecase.cs | 2 +- .../FindInterfaces/type_findinterfaces.cs | 10 +++---- .../Type/FindMembers/type_findmembers.cs | 6 ++--- .../csharp/System/Type/FullName/Fullname3.cs | 2 +- .../System/Type/FullName/Fullname3.csproj | 10 +++++++ .../csharp/System/Type/FullName/Fullname4.cs | 2 +- .../System/Type/FullName/Fullname4.csproj | 10 +++++++ .../csharp/System/Type/FullName/Fullname5.cs | 2 +- .../System/Type/FullName/Fullname5.csproj | 10 +++++++ .../System/Type/FullName/fullnameex1.csproj | 10 +++++++ .../System/Type/FullName/testfullname.csproj | 10 +++++++ snippets/csharp/System/Type/GUID/type_guid.cs | 2 +- .../Type/GetConstructors/source1.csproj | 10 +++++++ .../Type/GetConstructors/source2.csproj | 10 +++++++ .../type_getdefaultmembers.cs | 2 +- .../Type/GetElementType/testgetelementtype.cs | 4 +-- .../System/Type/GetEvent/type_getevent.cs | 2 +- .../System/Type/GetEvent/type_getevent.csproj | 11 ++++++++ .../System/Type/GetEvent/type_getevent1.cs | 2 +- .../Type/GetEvent/type_getevent1.csproj | 11 ++++++++ .../System/Type/GetEvents/type_getevents1.cs | 2 +- .../Type/GetEvents/type_getevents1.csproj | 11 ++++++++ .../System/Type/GetEvents/type_getevents2.cs | 2 +- .../Type/GetEvents/type_getevents2.csproj | 11 ++++++++ .../GetHashCode/type_gethashcode_getfields.cs | 4 +-- .../type_gethashcode_getfields.csproj | 11 ++++++++ .../Type/GetInterface/type_getinterface.cs | 4 +-- .../GetInterface/type_getinterface.csproj | 10 +++++++ .../Type/GetInterfaceMap/interfacemapping1.cs | 27 +++---------------- .../GetInterfaceMap/interfacemapping1.csproj | 10 +++++++ .../System/Type/GetMember/type_getmember.cs | 6 ++--- .../Type/GetMembers/type_getmembers1.csproj | 10 +++++++ .../Type/GetMembers/type_getmembers2.csproj | 10 +++++++ .../System/Type/GetMethod/GetMethod1.cs | 2 +- .../System/Type/GetMethod/type_getmethod3.cs | 10 +++---- .../System/Type/GetMethod/type_getmethod4.cs | 10 +++---- .../System/Type/GetMethod/type_getmethod5.cs | 10 +++---- .../GetNestedTypes/type_getnestedtypes.cs | 2 +- .../Type/GetProperties/type_gettypecode.cs | 2 +- .../Type/GetProperty/type_getproperty3.cs | 2 +- .../csharp/System/Type/GetType/Project.csproj | 4 +++ .../GetType/mypath/v5.0/myassembly.csproj | 10 +++++++ .../System/Type/GetTypeCode/iconvertible.cs | 4 +-- .../GetTypeFromCLSID/gettypefromclsid1.cs | 2 +- .../GetTypeFromCLSID/gettypefromclsid1.csproj | 10 +++++++ .../gettypefromclsid11.csproj | 10 +++++++ .../GetTypeFromCLSID/gettypefromclsid_ex2.cs | 2 +- .../gettypefromclsid_ex2.csproj | 10 +++++++ .../GetTypeFromCLSID/gettypefromclsid_ex3.cs | 2 +- .../gettypefromclsid_ex3.csproj | 10 +++++++ .../GetTypeFromCLSID/gettypefromclsid_ex4.cs | 2 +- .../gettypefromclsid_ex4.csproj | 10 +++++++ .../type_gettypefromprogid2.csproj | 10 +++++++ .../type_gettypefromprogid3.csproj | 10 +++++++ .../type_gettypefromprogid4.csproj | 10 +++++++ .../HasElementType/type_haselementtype.cs | 2 +- .../HasElementType/type_haselementtype.csproj | 11 ++++++++ .../System/Type/InvokeMember/invokemem.cs | 10 +++---- .../System/Type/IsAbstract/isabstract1.cs | 12 ++++----- .../csharp/System/Type/IsArray/isarray2.cs | 8 +++--- .../IsAssignableFrom/IsAssignableFrom2.csproj | 10 +++++++ .../IsAssignableFrom/IsAssignableFrom3.cs | 2 +- .../IsAssignableFrom/IsAssignableFrom3.csproj | 10 +++++++ .../IsAssignableFrom/isassignablefrom_ex1.cs | 7 +++-- .../isassignablefrom_ex1.csproj | 10 +++++++ .../testisassignablefrom.csproj | 10 +++++++ .../IsContextful/type_iscontextful.csproj | 10 +++++++ .../System/Type/IsGenericType/remarks.csproj | 10 +++++++ .../System/Type/IsGenericType/source.csproj | 10 +++++++ .../IsNested/isnestedfamilyandassembly1.cs | 12 ++++----- .../System/Type/MakeGenericType/source.cs | 2 +- snippets/csharp/System/Type/Missing/source.cs | 6 ++--- .../csharp/System/Type/Missing/source.csproj | 13 +++++++++ .../System/Type/Module/type_tostring.cs | 2 +- .../csharp/System/Type/Overview/GetType1.cs | 2 +- .../csharp/System/Type/Overview/source.cs | 4 +-- .../Type/StructLayoutAttribute/source.cs | 2 +- .../System/Type/TypeHandle/type_typehandle.cs | 2 +- .../Overview/Regex1.cs | 2 +- 87 files changed, 491 insertions(+), 118 deletions(-) create mode 100644 snippets/csharp/System/Type/EmptyTypes/source.csproj create mode 100644 snippets/csharp/System/Type/Equals/EqualsEx1.csproj create mode 100644 snippets/csharp/System/Type/Equals/source.csproj create mode 100644 snippets/csharp/System/Type/FilterName/source.csproj create mode 100644 snippets/csharp/System/Type/FullName/Fullname3.csproj create mode 100644 snippets/csharp/System/Type/FullName/Fullname4.csproj create mode 100644 snippets/csharp/System/Type/FullName/Fullname5.csproj create mode 100644 snippets/csharp/System/Type/FullName/fullnameex1.csproj create mode 100644 snippets/csharp/System/Type/FullName/testfullname.csproj create mode 100644 snippets/csharp/System/Type/GetConstructors/source1.csproj create mode 100644 snippets/csharp/System/Type/GetConstructors/source2.csproj create mode 100644 snippets/csharp/System/Type/GetEvent/type_getevent.csproj create mode 100644 snippets/csharp/System/Type/GetEvent/type_getevent1.csproj create mode 100644 snippets/csharp/System/Type/GetEvents/type_getevents1.csproj create mode 100644 snippets/csharp/System/Type/GetEvents/type_getevents2.csproj create mode 100644 snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj create mode 100644 snippets/csharp/System/Type/GetInterface/type_getinterface.csproj create mode 100644 snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj create mode 100644 snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj create mode 100644 snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj create mode 100644 snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj create mode 100644 snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj create mode 100644 snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj create mode 100644 snippets/csharp/System/Type/IsGenericType/remarks.csproj create mode 100644 snippets/csharp/System/Type/IsGenericType/source.csproj create mode 100644 snippets/csharp/System/Type/Missing/source.csproj diff --git a/snippets/csharp/System/Type/Attributes/attributes1.cs b/snippets/csharp/System/Type/Attributes/attributes1.cs index c56eed168b8..290499fb41e 100644 --- a/snippets/csharp/System/Type/Attributes/attributes1.cs +++ b/snippets/csharp/System/Type/Attributes/attributes1.cs @@ -16,8 +16,8 @@ public interface INested { } public static void Main() { // Create an array of types. - Type[] types = { typeof(Example), typeof(NestedClass), - typeof(INested), typeof(S) }; + Type[] types = [typeof(Example), typeof(NestedClass), + typeof(INested), typeof(S)]; foreach (var t in types) { diff --git a/snippets/csharp/System/Type/DeclaringMethod/source.cs b/snippets/csharp/System/Type/DeclaringMethod/source.cs index a0f5bf9f23a..391fd17f392 100644 --- a/snippets/csharp/System/Type/DeclaringMethod/source.cs +++ b/snippets/csharp/System/Type/DeclaringMethod/source.cs @@ -34,7 +34,7 @@ public static void Main() // // Invoke the method. - object[] args = { 42 }; + object[] args = [42]; miConstructed.Invoke(null, args); // Invoke the method normally. diff --git a/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs b/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs index 8ee5ffdc6f4..79837db8991 100644 --- a/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs +++ b/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs @@ -12,7 +12,7 @@ public static void Main() MyClass myClass = new(); // Invoke the HelloWorld method of MyClass. myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, - defaultBinder, myClass, new object[] { }); + defaultBinder, myClass, []); } catch (Exception e) { diff --git a/snippets/csharp/System/Type/EmptyTypes/source.csproj b/snippets/csharp/System/Type/EmptyTypes/source.csproj new file mode 100644 index 00000000000..0cff88c0d29 --- /dev/null +++ b/snippets/csharp/System/Type/EmptyTypes/source.csproj @@ -0,0 +1,10 @@ + + + Library + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/Equals/EqualsEx1.csproj b/snippets/csharp/System/Type/Equals/EqualsEx1.csproj new file mode 100644 index 00000000000..bb6239672aa --- /dev/null +++ b/snippets/csharp/System/Type/Equals/EqualsEx1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/Equals/source.csproj b/snippets/csharp/System/Type/Equals/source.csproj new file mode 100644 index 00000000000..15e841d2cb3 --- /dev/null +++ b/snippets/csharp/System/Type/Equals/source.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs b/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs index 1d0b7d0f6b7..178b7278b03 100644 --- a/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs +++ b/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs @@ -17,7 +17,7 @@ public static void Main() foreach (MemberInfo myMemberinfo in myMemberInfoArray) { Console.Write("\n" + myMemberinfo.Name); - Console.Write(" is a " + myMemberinfo.MemberType.ToString()); + Console.Write(" is a " + myMemberinfo.MemberType); } } catch (ArgumentNullException e) diff --git a/snippets/csharp/System/Type/FilterName/source.csproj b/snippets/csharp/System/Type/FilterName/source.csproj new file mode 100644 index 00000000000..0cff88c0d29 --- /dev/null +++ b/snippets/csharp/System/Type/FilterName/source.csproj @@ -0,0 +1,10 @@ + + + Library + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs b/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs index 8f5fe976b6e..39d5c5df732 100644 --- a/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs +++ b/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs @@ -17,7 +17,7 @@ public static void Main() { Console.Write("\n" + myMemberinfo2.Name); MemberTypes Mymembertypes = myMemberinfo2.MemberType; - Console.WriteLine(" is a " + Mymembertypes.ToString()); + Console.WriteLine(" is a " + Mymembertypes); } } catch (ArgumentNullException e) diff --git a/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs b/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs index abee4581f12..896ac2b0612 100644 --- a/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs +++ b/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs @@ -17,9 +17,9 @@ public static void Main() // Specify the TypeFilter delegate that compares the // interfaces against filter criteria. TypeFilter myFilter = new(MyInterfaceFilter); - string[] myInterfaceList = new string[2] - {"System.Collections.IEnumerable", - "System.Collections.ICollection"}; + string[] myInterfaceList = + ["System.Collections.IEnumerable", + "System.Collections.ICollection"]; for (int index = 0; index < myInterfaceList.Length; index++) { Type[] myInterfaces = myType.FindInterfaces(myFilter, @@ -28,7 +28,7 @@ public static void Main() { Console.WriteLine($"\n{myType} implements the interface {myInterfaceList[index]}."); for (int j = 0; j < myInterfaces.Length; j++) - Console.WriteLine($"Interfaces supported: {myInterfaces[j].ToString()}."); + Console.WriteLine($"Interfaces supported: {myInterfaces[j]}."); } else Console.WriteLine($"\n{myType} does not implement the interface {myInterfaceList[index]}."); @@ -50,7 +50,7 @@ public static void Main() public static bool MyInterfaceFilter(Type typeObj, object criteriaObj) { - if (typeObj.ToString() == criteriaObj.ToString()) + if (typeObj.FullName == criteriaObj as string) return true; else return false; diff --git a/snippets/csharp/System/Type/FindMembers/type_findmembers.cs b/snippets/csharp/System/Type/FindMembers/type_findmembers.cs index ef595523385..5caae3e13b4 100644 --- a/snippets/csharp/System/Type/FindMembers/type_findmembers.cs +++ b/snippets/csharp/System/Type/FindMembers/type_findmembers.cs @@ -18,17 +18,17 @@ public static void Main() "ReferenceEquals"); for (int index = 0; index < arrayMemberInfo.Length; index++) - Console.WriteLine("Result of FindMembers -\t" + arrayMemberInfo[index].ToString() + "\n"); + Console.WriteLine("Result of FindMembers -\t" + arrayMemberInfo[index] + "\n"); } catch (Exception e) { - Console.WriteLine("Exception : " + e.ToString()); + Console.WriteLine("Exception : " + e); } } public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, object objSearch) { // Compare the name of the member function with the filter criteria. - if (objMemberInfo.Name.ToString() == objSearch.ToString()) + if (objMemberInfo.Name == objSearch as string) return true; else return false; diff --git a/snippets/csharp/System/Type/FullName/Fullname3.cs b/snippets/csharp/System/Type/FullName/Fullname3.cs index a62b34c701a..0385925ad77 100644 --- a/snippets/csharp/System/Type/FullName/Fullname3.cs +++ b/snippets/csharp/System/Type/FullName/Fullname3.cs @@ -15,7 +15,7 @@ public static void Main() for (int ctr = 0; ctr < gtArgs.Length; ctr++) { Console.WriteLine(gtArgs[ctr].FullName ?? - "(unassigned) " + gtArgs[ctr].ToString()); + "(unassigned) " + gtArgs[ctr]); } Console.WriteLine(); } diff --git a/snippets/csharp/System/Type/FullName/Fullname3.csproj b/snippets/csharp/System/Type/FullName/Fullname3.csproj new file mode 100644 index 00000000000..944cc6d6896 --- /dev/null +++ b/snippets/csharp/System/Type/FullName/Fullname3.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FullName/Fullname4.cs b/snippets/csharp/System/Type/FullName/Fullname4.cs index 69dc72938eb..fa4c9da183a 100644 --- a/snippets/csharp/System/Type/FullName/Fullname4.cs +++ b/snippets/csharp/System/Type/FullName/Fullname4.cs @@ -31,7 +31,7 @@ public static void Main() if (method.Name == "HandleT") paramType = paramType.MakePointerType(); Console.WriteLine($" Parameter: {paramType.FullName ?? - paramType.ToString() + " (unassigned)"}"); + paramType + " (unassigned)"}"); } } } diff --git a/snippets/csharp/System/Type/FullName/Fullname4.csproj b/snippets/csharp/System/Type/FullName/Fullname4.csproj new file mode 100644 index 00000000000..80fe1043218 --- /dev/null +++ b/snippets/csharp/System/Type/FullName/Fullname4.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FullName/Fullname5.cs b/snippets/csharp/System/Type/FullName/Fullname5.cs index ce7fca7452a..b47f43cc77b 100644 --- a/snippets/csharp/System/Type/FullName/Fullname5.cs +++ b/snippets/csharp/System/Type/FullName/Fullname5.cs @@ -17,7 +17,7 @@ public static void Main() Type baseType = t.BaseType; Console.WriteLine($"Its Base Class: {baseType.FullName ?? - "(unassigned) " + baseType.ToString()}"); + "(unassigned) " + baseType}"); Console.WriteLine($" Contains Generic Paramters: {baseType.ContainsGenericParameters}"); Console.WriteLine($" Generic Type Definition: {baseType.IsGenericTypeDefinition}"); Console.WriteLine($" Full Name: {baseType.GetGenericTypeDefinition().FullName}\n"); diff --git a/snippets/csharp/System/Type/FullName/Fullname5.csproj b/snippets/csharp/System/Type/FullName/Fullname5.csproj new file mode 100644 index 00000000000..ba755001bea --- /dev/null +++ b/snippets/csharp/System/Type/FullName/Fullname5.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FullName/fullnameex1.csproj b/snippets/csharp/System/Type/FullName/fullnameex1.csproj new file mode 100644 index 00000000000..ac5235c6d00 --- /dev/null +++ b/snippets/csharp/System/Type/FullName/fullnameex1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/FullName/testfullname.csproj b/snippets/csharp/System/Type/FullName/testfullname.csproj new file mode 100644 index 00000000000..5f08cae1e1f --- /dev/null +++ b/snippets/csharp/System/Type/FullName/testfullname.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GUID/type_guid.cs b/snippets/csharp/System/Type/GUID/type_guid.cs index 43a2706f8c6..338f32dcfee 100644 --- a/snippets/csharp/System/Type/GUID/type_guid.cs +++ b/snippets/csharp/System/Type/GUID/type_guid.cs @@ -15,7 +15,7 @@ public static void Main() Type myType = typeof(MyClass1); // Get the object of the Guid. Guid myGuid = (Guid)myType.GUID; - Console.WriteLine("The name of the class is " + myType.ToString()); + Console.WriteLine("The name of the class is " + myType); Console.WriteLine("The ClassId of MyClass is " + myType.GUID); } } diff --git a/snippets/csharp/System/Type/GetConstructors/source1.csproj b/snippets/csharp/System/Type/GetConstructors/source1.csproj new file mode 100644 index 00000000000..fba6a4ef0af --- /dev/null +++ b/snippets/csharp/System/Type/GetConstructors/source1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetConstructors/source2.csproj b/snippets/csharp/System/Type/GetConstructors/source2.csproj new file mode 100644 index 00000000000..7d18a5f3a1e --- /dev/null +++ b/snippets/csharp/System/Type/GetConstructors/source2.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs b/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs index 8b419322a02..2d6817171e9 100644 --- a/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs +++ b/snippets/csharp/System/Type/GetDefaultMembers/type_getdefaultmembers.cs @@ -18,7 +18,7 @@ public static void Main() { foreach (MemberInfo memberInfoObj in memberInfoArray) { - Console.WriteLine("The default member name is: " + memberInfoObj.ToString()); + Console.WriteLine("The default member name is: " + memberInfoObj); } } else diff --git a/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs b/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs index a14ca67e520..acc79ca852e 100644 --- a/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs +++ b/snippets/csharp/System/Type/GetElementType/testgetelementtype.cs @@ -4,10 +4,10 @@ class TestGetElementType { public static void Main() { - int[] array = { 1, 2, 3 }; + int[] array = [1, 2, 3]; Type t = array.GetType(); Type t2 = t.GetElementType(); - Console.WriteLine($"The element type of {array} is {t2.ToString()}."); + Console.WriteLine($"The element type of {array} is {t2}."); TestGetElementType newMe = new(); t = newMe.GetType(); t2 = t.GetElementType(); diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent.cs b/snippets/csharp/System/Type/GetEvent/type_getevent.cs index 276518eadde..53ded61f156 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent.cs @@ -15,7 +15,7 @@ public static void Main() if (myEvent != null) { Console.WriteLine("Looking for the Click event in the Button class."); - Console.WriteLine(myEvent.ToString()); + Console.WriteLine(myEvent); } else { diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent.csproj b/snippets/csharp/System/Type/GetEvent/type_getevent.csproj new file mode 100644 index 00000000000..a6f0080cd39 --- /dev/null +++ b/snippets/csharp/System/Type/GetEvent/type_getevent.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0-windows + true + false + + + + + diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs index e140ca49f54..22f61449883 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs @@ -17,7 +17,7 @@ public static void Main() if (myEventBindingFlags != null) { Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags."); - Console.WriteLine(myEventBindingFlags.ToString()); + Console.WriteLine(myEventBindingFlags); } else { diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent1.csproj b/snippets/csharp/System/Type/GetEvent/type_getevent1.csproj new file mode 100644 index 00000000000..9d383f26ae6 --- /dev/null +++ b/snippets/csharp/System/Type/GetEvent/type_getevent1.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0-windows + true + false + + + + + diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs index 8bc140dfcbb..6a9e01b5597 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs @@ -16,7 +16,7 @@ public static void Main() Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are : "); for (int index = 0; index < myEventsBindingFlags.Length; index++) { - Console.WriteLine(myEventsBindingFlags[index].ToString()); + Console.WriteLine(myEventsBindingFlags[index]); } } catch (SecurityException e) diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents1.csproj b/snippets/csharp/System/Type/GetEvents/type_getevents1.csproj new file mode 100644 index 00000000000..5f634a74bfa --- /dev/null +++ b/snippets/csharp/System/Type/GetEvents/type_getevents1.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0-windows + true + false + + + + + diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs index c733e6d7ebe..f6248dd7d2a 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs @@ -16,7 +16,7 @@ public static void Main() Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are:"); for (int index = 0; index < myEventsBindingFlags.Length; index++) { - Console.WriteLine(myEventsBindingFlags[index].ToString()); + Console.WriteLine(myEventsBindingFlags[index]); } } catch (SecurityException e) diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj b/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj new file mode 100644 index 00000000000..7b4518cbdbc --- /dev/null +++ b/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0-windows + true + false + + + + + diff --git a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs index a1aea2695df..9dd0048525b 100644 --- a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs +++ b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs @@ -12,14 +12,14 @@ public static void Main() Console.WriteLine("\nThe IPAddress class has the following nonpublic fields: "); foreach (FieldInfo myField in myFields) { - Console.WriteLine(myField.ToString()); + Console.WriteLine(myField); } Type myType1 = typeof(System.Net.IPAddress); FieldInfo[] myFields1 = myType1.GetFields(); Console.WriteLine("\nThe IPAddress class has the following public fields: "); foreach (FieldInfo myField in myFields1) { - Console.WriteLine(myField.ToString()); + Console.WriteLine(myField); } try { diff --git a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj new file mode 100644 index 00000000000..478812b7139 --- /dev/null +++ b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0-windows + true + false + + + + + diff --git a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs index 79809770bc2..72060d5ddd9 100644 --- a/snippets/csharp/System/Type/GetInterface/type_getinterface.cs +++ b/snippets/csharp/System/Type/GetInterface/type_getinterface.cs @@ -37,7 +37,7 @@ public static void Main() Console.WriteLine(methodInfo); //Get the Interface methods for 'IDictionary' interface - InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary)); + InterfaceMapping interfaceMappingObj = objType.GetInterfaceMap(typeof(IDictionary)); arrayMemberInfo = interfaceMappingObj.InterfaceMethods; Console.WriteLine("\nHashtable class Implements the following IDictionary Interface methods :"); foreach (MemberInfo memberInfo in arrayMemberInfo) @@ -45,7 +45,7 @@ public static void Main() } catch (Exception e) { - Console.WriteLine("Exception : " + e.ToString()); + Console.WriteLine("Exception : " + e); } } // diff --git a/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj b/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj new file mode 100644 index 00000000000..bf36592624a --- /dev/null +++ b/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs index f21c29e20c2..aa607622e13 100644 --- a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs +++ b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs @@ -7,8 +7,8 @@ public class Example { public static void Main() { - Type[] interf = { typeof(IFormatProvider), typeof(IAppDomainSetup) }; - Type[] impl = { typeof(CultureInfo), typeof(AppDomainSetup) }; + Type[] interf = [typeof(IFormatProvider), typeof(IFormattable)]; + Type[] impl = [typeof(CultureInfo), typeof(DateTime)]; for (int ctr = 0; ctr < interf.Length; ctr++) ShowInterfaceMapping(interf[ctr], impl[ctr]); @@ -31,25 +31,6 @@ private static void ShowInterfaceMapping(Type intType, Type implType) // Mapping of System.IFormatProvider to System.Globalization.CultureInfo: // GetFormat --> GetFormat // -// Mapping of System.IAppDomainSetup to System.AppDomainSetup: -// get_ApplicationBase --> get_ApplicationBase -// set_ApplicationBase --> set_ApplicationBase -// get_ApplicationName --> get_ApplicationName -// set_ApplicationName --> set_ApplicationName -// get_CachePath --> get_CachePath -// set_CachePath --> set_CachePath -// get_ConfigurationFile --> get_ConfigurationFile -// set_ConfigurationFile --> set_ConfigurationFile -// get_DynamicBase --> get_DynamicBase -// set_DynamicBase --> set_DynamicBase -// get_LicenseFile --> get_LicenseFile -// set_LicenseFile --> set_LicenseFile -// get_PrivateBinPath --> get_PrivateBinPath -// set_PrivateBinPath --> set_PrivateBinPath -// get_PrivateBinPathProbe --> get_PrivateBinPathProbe -// set_PrivateBinPathProbe --> set_PrivateBinPathProbe -// get_ShadowCopyDirectories --> get_ShadowCopyDirectories -// set_ShadowCopyDirectories --> set_ShadowCopyDirectories -// get_ShadowCopyFiles --> get_ShadowCopyFiles -// set_ShadowCopyFiles --> set_ShadowCopyFiles +// Mapping of System.IFormattable to System.DateTime: +// ToString --> ToString // diff --git a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj new file mode 100644 index 00000000000..5365ebdae6a --- /dev/null +++ b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetMember/type_getmember.cs b/snippets/csharp/System/Type/GetMember/type_getmember.cs index e6df4edaf53..e9df7340968 100644 --- a/snippets/csharp/System/Type/GetMember/type_getmember.cs +++ b/snippets/csharp/System/Type/GetMember/type_getmember.cs @@ -52,7 +52,7 @@ public void GetMemberInfo() { Console.WriteLine($"\nThe member(s) starting with the letter C for type {myType}:"); for (int index = 0; index < myMembers.Length; index++) - Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); + Console.WriteLine($"Member {index + 1}: {myMembers[index]}"); } else { @@ -73,7 +73,7 @@ public void GetPublicStaticMemberInfo() { Console.WriteLine($"\nThe public static member(s) starting with the letter C for type {myType}:"); for (int index = 0; index < myMembers.Length; index++) - Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); + Console.WriteLine($"Member {index + 1}: {myMembers[index]}"); } else { @@ -94,7 +94,7 @@ public void GetPublicInstanceMethodMemberInfo() { Console.WriteLine($"\nThe public instance method(s) starting with the letter C for type {myType}:"); for (int index = 0; index < myMembers.Length; index++) - Console.WriteLine($"Member {index + 1}: {myMembers[index].ToString()}"); + Console.WriteLine($"Member {index + 1}: {myMembers[index]}"); } else { diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj b/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj new file mode 100644 index 00000000000..834a719826b --- /dev/null +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj b/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj new file mode 100644 index 00000000000..b8828e48e35 --- /dev/null +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetMethod/GetMethod1.cs b/snippets/csharp/System/Type/GetMethod/GetMethod1.cs index 638f394e65e..2dba736e77e 100644 --- a/snippets/csharp/System/Type/GetMethod/GetMethod1.cs +++ b/snippets/csharp/System/Type/GetMethod/GetMethod1.cs @@ -37,7 +37,7 @@ private static void GetAddMethod(Type typ) // This is not a generic type. else { - method = typ.GetMethod("Add", new Type[] { typeof(object) }); + method = typ.GetMethod("Add", [typeof(object)]); } // Test if an Add method was found. diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs index 27fec6818c1..ff7b8bdf725 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod3.cs @@ -27,7 +27,7 @@ static void Main(string[] args) BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, - new Type[] { typeof(int), typeof(int) }, + [typeof(int), typeof(int)], null); Console.WriteLine($"Found method: {mInfo}"); @@ -36,7 +36,7 @@ static void Main(string[] args) BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, - new Type[] { typeof(int[]) }, + [typeof(int[])], null); Console.WriteLine($"Found method: {mInfo}"); @@ -45,7 +45,7 @@ static void Main(string[] args) BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, - new Type[] { typeof(int).MakePointerType() }, + [typeof(int).MakePointerType()], null); Console.WriteLine($"Found method: {mInfo}"); @@ -54,7 +54,7 @@ static void Main(string[] args) BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, - new Type[] { typeof(int).MakeByRefType() }, + [typeof(int).MakeByRefType()], null); Console.WriteLine($"Found method: {mInfo}"); @@ -63,7 +63,7 @@ static void Main(string[] args) BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, - new Type[] { typeof(int), typeof(int).MakeByRefType() }, + [typeof(int), typeof(int).MakeByRefType()], null); Console.WriteLine($"Found method: {mInfo}"); } diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs index 7877f930328..c22aec78060 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs @@ -24,27 +24,27 @@ static void Main(string[] args) // Get MethodA(int i, int i) mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int), typeof(int) }); + [typeof(int), typeof(int)]); Console.WriteLine($"Found method: {mInfo}"); // Get MethodA(int[] i) mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int[]) }); + [typeof(int[])]); Console.WriteLine($"Found method: {mInfo}"); // Get MethodA(int* i) mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int).MakePointerType() }); + [typeof(int).MakePointerType()]); Console.WriteLine($"Found method: {mInfo}"); // Get MethodA(ref int r) mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int).MakeByRefType() }); + [typeof(int).MakeByRefType()]); Console.WriteLine($"Found method: {mInfo}"); // Get MethodA(int i, out int o) mInfo = typeof(Program).GetMethod("MethodA", - new Type[] { typeof(int), typeof(int).MakeByRefType() }); + [typeof(int), typeof(int).MakeByRefType()]); Console.WriteLine($"Found method: {mInfo}"); } } diff --git a/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs b/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs index 56d72d7fd0c..b130195db1e 100644 --- a/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs +++ b/snippets/csharp/System/Type/GetMethod/type_getmethod5.cs @@ -26,7 +26,7 @@ static void Main(string[] args) mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance, null, - new Type[] { typeof(int), typeof(int) }, + [typeof(int), typeof(int)], null); Console.WriteLine($"Found method: {mInfo}"); @@ -34,7 +34,7 @@ static void Main(string[] args) mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance, null, - new Type[] { typeof(int[]) }, + [typeof(int[])], null); Console.WriteLine($"Found method: {mInfo}"); @@ -42,7 +42,7 @@ static void Main(string[] args) mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance, null, - new Type[] { typeof(int).MakePointerType() }, + [typeof(int).MakePointerType()], null); Console.WriteLine($"Found method: {mInfo}"); @@ -50,7 +50,7 @@ static void Main(string[] args) mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance, null, - new Type[] { typeof(int).MakeByRefType() }, + [typeof(int).MakeByRefType()], null); Console.WriteLine($"Found method: {mInfo}"); @@ -58,7 +58,7 @@ static void Main(string[] args) mInfo = typeof(Program).GetMethod("MethodA", BindingFlags.Public | BindingFlags.Instance, null, - new Type[] { typeof(int), typeof(int).MakeByRefType() }, + [typeof(int), typeof(int).MakeByRefType()], null); Console.WriteLine($"Found method: {mInfo}"); } diff --git a/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs b/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs index 8cae9b676a7..dc0981e5a4d 100644 --- a/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs +++ b/snippets/csharp/System/Type/GetNestedTypes/type_getnestedtypes.cs @@ -25,7 +25,7 @@ public static void Main() Type[] nestType = myType.GetNestedTypes(); Console.WriteLine($"The number of nested types is {nestType.Length}."); foreach (Type t in nestType) - Console.WriteLine($"Nested type is {t.ToString()}."); + Console.WriteLine($"Nested type is {t}."); } catch (Exception e) { diff --git a/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs b/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs index 6374d82f853..be9dba71888 100644 --- a/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs +++ b/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs @@ -34,7 +34,7 @@ static void Main(string[] args) Console.WriteLine("Properties of System.Type are:"); for (int i = 0; i < myPropertyInfo.Length; i++) { - Console.WriteLine(myPropertyInfo[i].ToString()); + Console.WriteLine(myPropertyInfo[i]); } // // diff --git a/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs b/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs index 282774f6ca9..c29675280b8 100644 --- a/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs +++ b/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs @@ -32,7 +32,7 @@ public static void Main(string[] args) PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr); // Display the property. - Console.WriteLine($"The {myPropInfo.ToString()} property exists in MyClass3."); + Console.WriteLine($"The {myPropInfo} property exists in MyClass3."); } catch (NullReferenceException e) { diff --git a/snippets/csharp/System/Type/GetType/Project.csproj b/snippets/csharp/System/Type/GetType/Project.csproj index 874c98f3477..70857082ef9 100644 --- a/snippets/csharp/System/Type/GetType/Project.csproj +++ b/snippets/csharp/System/Type/GetType/Project.csproj @@ -5,4 +5,8 @@ net10.0 + + + + diff --git a/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj b/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj new file mode 100644 index 00000000000..ca162699d3f --- /dev/null +++ b/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj @@ -0,0 +1,10 @@ + + + Library + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs b/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs index 9f275449684..c9396ce0e7b 100644 --- a/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs +++ b/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs @@ -48,7 +48,7 @@ bool IConvertible.ToBoolean(IFormatProvider provider) float IConvertible.ToSingle(IFormatProvider provider) => Convert.ToSingle(GetDoubleValue()); - string IConvertible.ToString(IFormatProvider provider) => "( " + x.ToString() + " , " + y.ToString() + " )"; + string IConvertible.ToString(IFormatProvider provider) => "( " + x + " , " + y + " )"; object IConvertible.ToType(Type conversionType, IFormatProvider provider) => Convert.ChangeType(GetDoubleValue(), conversionType); @@ -90,7 +90,7 @@ static void WriteObjectInfo(object testObject) break; default: - Console.WriteLine($"{typeCode.ToString()}: {testObject}"); + Console.WriteLine($"{typeCode}: {testObject}"); break; } } diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs index 8f19f58214d..c4bc974258c 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs @@ -18,7 +18,7 @@ public static void Main() // Close Word. word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false }); + wordObj, [0, 0, false]); } } // The example displays the following output: diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj new file mode 100644 index 00000000000..ee05b3ec3fe --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj new file mode 100644 index 00000000000..609a5c5ba62 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs index 6e6a56c10dd..1242352f6d4 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs @@ -21,7 +21,7 @@ public static void Main() // Close Word. word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false }); + wordObj, [0, 0, false]); } catch (Exception) { diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj new file mode 100644 index 00000000000..81d1c95abd2 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs index 60faa66cbf4..910d280ca8b 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs @@ -21,7 +21,7 @@ public static void Main() // Close Word. word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false }); + wordObj, [0, 0, false]); } catch (COMException) { diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj new file mode 100644 index 00000000000..aab2dea9380 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs index df68d46282f..be4acc831d5 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs @@ -23,7 +23,7 @@ public static void Main() // Close Word. word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, - wordObj, new object[] { 0, 0, false }); + wordObj, [0, 0, false]); } // The method can throw any of a variety of exceptions. catch (Exception e) diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj new file mode 100644 index 00000000000..ec610ea9823 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj new file mode 100644 index 00000000000..4ad4056a4ce --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj new file mode 100644 index 00000000000..e25540c4396 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj new file mode 100644 index 00000000000..ab649fb843a --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs b/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs index caf6b6fb125..4217e994597 100644 --- a/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs +++ b/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs @@ -14,7 +14,7 @@ public static void Main() // All of the following display 'True'. // Define an array, get its type, and display HasElementType. - int[] nums = { 1, 1, 2, 3, 5, 8, 13 }; + int[] nums = [1, 1, 2, 3, 5, 8, 13]; Type t = nums.GetType(); Console.WriteLine($"HasElementType is '{t.HasElementType}' for array types."); diff --git a/snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj b/snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj new file mode 100644 index 00000000000..cf21b2a610c --- /dev/null +++ b/snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj @@ -0,0 +1,11 @@ + + + Exe + net10.0 + true + false + + + + + diff --git a/snippets/csharp/System/Type/InvokeMember/invokemem.cs b/snippets/csharp/System/Type/InvokeMember/invokemem.cs index 38a6b29507c..b9b9282fb9c 100644 --- a/snippets/csharp/System/Type/InvokeMember/invokemem.cs +++ b/snippets/csharp/System/Type/InvokeMember/invokemem.cs @@ -26,20 +26,20 @@ static void Main() { Type t = typeof(MyType); // Create an instance of a type. - object[] args = new object[] { 8 }; + object[] args = [8]; Console.WriteLine($"The value of x before the constructor is called is {args[0]}."); object obj = t.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, args); - Console.WriteLine("Type: " + obj.GetType().ToString()); + Console.WriteLine("Type: " + obj.GetType()); Console.WriteLine($"The value of x after the constructor returns is {args[0]}."); // Read and write to a field. t.InvokeMember("myField", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetField, null, obj, new object[] { 5 }); + BindingFlags.Instance | BindingFlags.SetField, null, obj, [5]); int v = (int)t.InvokeMember("myField", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | @@ -67,7 +67,7 @@ static void Main() t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new object[] { 0 }); + BindingFlags.Instance | BindingFlags.SetProperty, null, obj, [0]); } catch (TargetInvocationException e) { @@ -81,7 +81,7 @@ static void Main() t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new object[] { 2 }); + BindingFlags.Instance | BindingFlags.SetProperty, null, obj, [2]); v = (int)t.InvokeMember("MyProp", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | diff --git a/snippets/csharp/System/Type/IsAbstract/isabstract1.cs b/snippets/csharp/System/Type/IsAbstract/isabstract1.cs index 29b97172acb..795f13a3810 100644 --- a/snippets/csharp/System/Type/IsAbstract/isabstract1.cs +++ b/snippets/csharp/System/Type/IsAbstract/isabstract1.cs @@ -26,12 +26,12 @@ public class Example { public static void Main() { - Type[] types = { typeof(AbstractClass), - typeof(DerivedClass), - typeof(ITypeInfo), - typeof(SingleClass), - typeof(ImplementingClass), - typeof(InputOutput) }; + Type[] types = [typeof(AbstractClass), + typeof(DerivedClass), + typeof(ITypeInfo), + typeof(SingleClass), + typeof(ImplementingClass), + typeof(InputOutput)]; foreach (var type in types) Console.WriteLine($"{type.Name} is abstract: {type.IsAbstract}"); } diff --git a/snippets/csharp/System/Type/IsArray/isarray2.cs b/snippets/csharp/System/Type/IsArray/isarray2.cs index 44eb09d1f28..66907266053 100644 --- a/snippets/csharp/System/Type/IsArray/isarray2.cs +++ b/snippets/csharp/System/Type/IsArray/isarray2.cs @@ -7,10 +7,10 @@ public class Example { public static void Main() { - Type[] types = { typeof(string), typeof(int[]), - typeof(ArrayList), typeof(Array), - typeof(List), - typeof(IEnumerable) }; + Type[] types = [typeof(string), typeof(int[]), + typeof(ArrayList), typeof(Array), + typeof(List), + typeof(IEnumerable)]; foreach (var t in types) Console.WriteLine($"{t.Name + ":",-15} IsArray = {t.IsArray}"); } diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj new file mode 100644 index 00000000000..716b1d65a5d --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs index e8878fbf2d8..0d6b53d8333 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs @@ -10,7 +10,7 @@ public static void Main() Type c = typeof(Array); IEnumerable instanceOfT; - int[] instanceOfC = { 1, 2, 3, 4 }; + int[] instanceOfC = [1, 2, 3, 4]; if (t.IsAssignableFrom(c)) // instanceOfT = instanceOfC; diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj new file mode 100644 index 00000000000..7ce6f5a79b5 --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs index 4359ce07ddd..15aff23aaf5 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs @@ -10,15 +10,14 @@ public class Example { public static void Main() { - AppDomain domain = AppDomain.CurrentDomain; AssemblyName assemName = new() { Name = "TempAssembly" }; - // Define a dynamic assembly in the current application domain. - AssemblyBuilder assemBuilder = domain.DefineDynamicAssembly(assemName, - AssemblyBuilderAccess.Run); + // Define a dynamic assembly. + AssemblyBuilder assemBuilder = AssemblyBuilder.DefineDynamicAssembly( + assemName, AssemblyBuilderAccess.Run); // Define a dynamic module in this assembly. ModuleBuilder moduleBuilder = assemBuilder.DefineDynamicModule("TempModule"); diff --git a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj new file mode 100644 index 00000000000..0f07dffe875 --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj new file mode 100644 index 00000000000..33e0c615fac --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj b/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj new file mode 100644 index 00000000000..5ce7d2fd55c --- /dev/null +++ b/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsGenericType/remarks.csproj b/snippets/csharp/System/Type/IsGenericType/remarks.csproj new file mode 100644 index 00000000000..e1447dfcdae --- /dev/null +++ b/snippets/csharp/System/Type/IsGenericType/remarks.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsGenericType/source.csproj b/snippets/csharp/System/Type/IsGenericType/source.csproj new file mode 100644 index 00000000000..15e841d2cb3 --- /dev/null +++ b/snippets/csharp/System/Type/IsGenericType/source.csproj @@ -0,0 +1,10 @@ + + + Exe + net10.0 + false + + + + + diff --git a/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs b/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs index b1f485a179a..ef1cedea827 100644 --- a/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs +++ b/snippets/csharp/System/Type/IsNested/isnestedfamilyandassembly1.cs @@ -22,12 +22,12 @@ public class PublicClass public static void Main() { // Create an array of Type objects for all the classes. - Type[] types = { typeof(OuterClass), - typeof(OuterClass.PublicClass), - typeof(OuterClass.PrivateClass), - typeof(OuterClass.ProtectedClass), - typeof(OuterClass.InternalClass), - typeof(OuterClass.ProtectedInternalClass) }; + Type[] types = [typeof(OuterClass), + typeof(OuterClass.PublicClass), + typeof(OuterClass.PrivateClass), + typeof(OuterClass.ProtectedClass), + typeof(OuterClass.InternalClass), + typeof(OuterClass.ProtectedInternalClass)]; // Display the property values of each nested class. foreach (var type in types) { diff --git a/snippets/csharp/System/Type/MakeGenericType/source.cs b/snippets/csharp/System/Type/MakeGenericType/source.cs index 05b829cf3fb..357c5c9b176 100644 --- a/snippets/csharp/System/Type/MakeGenericType/source.cs +++ b/snippets/csharp/System/Type/MakeGenericType/source.cs @@ -19,7 +19,7 @@ public static void Main() // Create an array of types to substitute for the type // parameters of Dictionary. The key is of type string, and // the type to be contained in the Dictionary is Test. - Type[] typeArgs = { typeof(string), typeof(Test) }; + Type[] typeArgs = [typeof(string), typeof(Test)]; // Create a Type object representing the constructed generic // type. diff --git a/snippets/csharp/System/Type/Missing/source.cs b/snippets/csharp/System/Type/Missing/source.cs index 008aed87a8d..4f718aac1fd 100644 --- a/snippets/csharp/System/Type/Missing/source.cs +++ b/snippets/csharp/System/Type/Missing/source.cs @@ -27,9 +27,9 @@ public static void Main() BindingFlags bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding; - t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, 55.3, 12 }); - t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, 1.3, Type.Missing }); - t.InvokeMember("MyMethod", bf, null, o, new object[] { 10, Type.Missing, Type.Missing }); + t.InvokeMember("MyMethod", bf, null, o, [10, 55.3, 12]); + t.InvokeMember("MyMethod", bf, null, o, [10, 1.3, Type.Missing]); + t.InvokeMember("MyMethod", bf, null, o, [10, Type.Missing, Type.Missing]); } private static object GenerateObjectFromSource(string objectName, diff --git a/snippets/csharp/System/Type/Missing/source.csproj b/snippets/csharp/System/Type/Missing/source.csproj new file mode 100644 index 00000000000..da0b79f627a --- /dev/null +++ b/snippets/csharp/System/Type/Missing/source.csproj @@ -0,0 +1,13 @@ + + + Exe + net10.0 + false + + + + + + + + diff --git a/snippets/csharp/System/Type/Module/type_tostring.cs b/snippets/csharp/System/Type/Module/type_tostring.cs index 2e82bf67882..842d6a8883c 100644 --- a/snippets/csharp/System/Type/Module/type_tostring.cs +++ b/snippets/csharp/System/Type/Module/type_tostring.cs @@ -19,7 +19,7 @@ public static void Main() // Get the name of the module. Console.WriteLine($" Module: {myType.Module}."); // Get the fully qualified type name. - Console.WriteLine($" Fully qualified name: {myType.ToString()}."); + Console.WriteLine($" Fully qualified name: {myType}."); } } // The example displays the following output: diff --git a/snippets/csharp/System/Type/Overview/GetType1.cs b/snippets/csharp/System/Type/Overview/GetType1.cs index 45414f8bb6a..9bb0daa8f7e 100644 --- a/snippets/csharp/System/Type/Overview/GetType1.cs +++ b/snippets/csharp/System/Type/Overview/GetType1.cs @@ -5,7 +5,7 @@ public class Example2 public static void Main() { // - object[] values = { "word", true, 120, 136.34, 'a' }; + object[] values = ["word", true, 120, 136.34, 'a']; foreach (object value in values) Console.WriteLine($"{value} - type {value.GetType().Name}"); diff --git a/snippets/csharp/System/Type/Overview/source.cs b/snippets/csharp/System/Type/Overview/source.cs index 89e4f8a55bf..303403b32fd 100644 --- a/snippets/csharp/System/Type/Overview/source.cs +++ b/snippets/csharp/System/Type/Overview/source.cs @@ -12,10 +12,10 @@ static void Main() Type t = typeof(string); MethodInfo substr = t.GetMethod("Substring", - new Type[] { typeof(int), typeof(int) }); + [typeof(int), typeof(int)]); object result = - substr.Invoke("Hello, World!", new object[] { 7, 5 }); + substr.Invoke("Hello, World!", [7, 5]); Console.WriteLine($"{substr} returned \"{result}\"."); } } diff --git a/snippets/csharp/System/Type/StructLayoutAttribute/source.cs b/snippets/csharp/System/Type/StructLayoutAttribute/source.cs index f8c6f75589e..66a8afe89b8 100644 --- a/snippets/csharp/System/Type/StructLayoutAttribute/source.cs +++ b/snippets/csharp/System/Type/StructLayoutAttribute/source.cs @@ -11,7 +11,7 @@ public static void Main() DisplayLayoutAttribute(typeof(Test2).StructLayoutAttribute); } - private static void DisplayLayoutAttribute(StructLayoutAttribute sla) => Console.WriteLine("\r\nCharSet: " + sla.CharSet.ToString() + "\r\n Pack: " + sla.Pack.ToString() + "\r\n Size: " + sla.Size.ToString() + "\r\n Value: " + sla.Value.ToString()); + private static void DisplayLayoutAttribute(StructLayoutAttribute sla) => Console.WriteLine("\r\nCharSet: " + sla.CharSet + "\r\n Pack: " + sla.Pack + "\r\n Size: " + sla.Size + "\r\n Value: " + sla.Value); public struct Test1 { public byte B1; diff --git a/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs b/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs index bd7c070a57f..3c3fcad33a9 100644 --- a/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs +++ b/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs @@ -34,7 +34,7 @@ public static void DisplayTypeHandle(RuntimeTypeHandle myTypeHandle) Type myType = Type.GetTypeFromHandle(myTypeHandle); // Display the type. Console.WriteLine("\nDisplaying the type from the handle:\n"); - Console.WriteLine($"The type is {myType.ToString()}."); + Console.WriteLine($"The type is {myType}."); } } // diff --git a/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs b/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs index 18511876f80..0a82b45d2ec 100644 --- a/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs +++ b/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs @@ -12,7 +12,7 @@ public static void Run() domain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(-2)); Regex rgx = new("[aeiouy]"); - Console.WriteLine($"Regular expression pattern: {rgx.ToString()}"); + Console.WriteLine($"Regular expression pattern: {rgx}"); Console.WriteLine($"Timeout interval for this regex: {rgx.MatchTimeout.TotalSeconds} seconds"); } } From f64e246e5fc0c7cb5117a6450842578e254cf7e8 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 13 Aug 2026 09:37:24 -0700 Subject: [PATCH 4/4] fix multiple project files --- .../EmptyTypes/{source.csproj => Project.csproj} | 4 ---- snippets/csharp/System/Type/Equals/EqualsEx1.cs | 4 ++-- snippets/csharp/System/Type/Equals/EqualsEx1.csproj | 10 ---------- snippets/csharp/System/Type/Equals/Program.cs | 2 ++ .../source.csproj => Equals/Project.csproj} | 4 ---- snippets/csharp/System/Type/Equals/source.cs | 8 ++++---- .../FilterName/{source.csproj => Project.csproj} | 4 ---- snippets/csharp/System/Type/FullName/Fullname3.cs | 4 ++-- .../csharp/System/Type/FullName/Fullname3.csproj | 10 ---------- snippets/csharp/System/Type/FullName/Fullname4.cs | 4 ++-- .../csharp/System/Type/FullName/Fullname4.csproj | 10 ---------- snippets/csharp/System/Type/FullName/Fullname5.cs | 4 ++-- .../csharp/System/Type/FullName/Fullname5.csproj | 10 ---------- snippets/csharp/System/Type/FullName/Program.cs | 5 +++++ .../source.csproj => FullName/Project.csproj} | 4 ---- snippets/csharp/System/Type/FullName/fullnameex1.cs | 4 ++-- .../csharp/System/Type/FullName/fullnameex1.csproj | 10 ---------- .../csharp/System/Type/FullName/testfullname.cs | 2 +- .../csharp/System/Type/FullName/testfullname.csproj | 10 ---------- .../csharp/System/Type/GetConstructors/Program.cs | 2 ++ .../{source2.csproj => Project.csproj} | 4 ---- .../csharp/System/Type/GetConstructors/source1.cs | 13 ++++++------- .../System/Type/GetConstructors/source1.csproj | 10 ---------- .../csharp/System/Type/GetConstructors/source2.cs | 13 ++++++------- snippets/csharp/System/Type/GetEvent/Program.cs | 2 ++ .../{type_getevent.csproj => Project.csproj} | 4 ---- .../csharp/System/Type/GetEvent/type_getevent.cs | 4 ++-- .../csharp/System/Type/GetEvent/type_getevent1.cs | 4 ++-- snippets/csharp/System/Type/GetEvents/Program.cs | 2 ++ .../Project.csproj} | 4 ---- .../csharp/System/Type/GetEvents/type_getevents1.cs | 4 ++-- .../csharp/System/Type/GetEvents/type_getevents2.cs | 4 ++-- .../System/Type/GetEvents/type_getevents2.csproj | 11 ----------- .../Project.csproj} | 4 ---- .../GetHashCode/type_gethashcode_getfields.csproj | 11 ----------- .../remarks.csproj => GetInterface/Project.csproj} | 4 ---- .../Type/GetInterface/type_getinterface.csproj | 10 ---------- .../System/Type/GetInterfaceMap/Project.csproj | 6 ++++++ .../Type/GetInterfaceMap/interfacemapping1.csproj | 10 ---------- snippets/csharp/System/Type/GetMembers/Program.cs | 2 ++ .../csharp/System/Type/GetMembers/Project.csproj | 6 ++++++ .../System/Type/GetMembers/type_getmembers1.cs | 8 ++++---- .../System/Type/GetMembers/type_getmembers1.csproj | 10 ---------- .../System/Type/GetMembers/type_getmembers2.cs | 8 ++++---- .../System/Type/GetMembers/type_getmembers2.csproj | 10 ---------- snippets/csharp/System/Type/GetType/Project.csproj | 8 +------- .../Type/GetType/mypath/v5.0/myassembly.csproj | 10 ---------- .../csharp/System/Type/GetTypeFromCLSID/Program.cs | 5 +++++ .../System/Type/GetTypeFromCLSID/Project.csproj | 6 ++++++ .../Type/GetTypeFromCLSID/gettypefromclsid1.cs | 4 ++-- .../Type/GetTypeFromCLSID/gettypefromclsid1.csproj | 10 ---------- .../Type/GetTypeFromCLSID/gettypefromclsid11.cs | 4 ++-- .../Type/GetTypeFromCLSID/gettypefromclsid11.csproj | 10 ---------- .../Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs | 4 ++-- .../GetTypeFromCLSID/gettypefromclsid_ex2.csproj | 10 ---------- .../Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs | 4 ++-- .../GetTypeFromCLSID/gettypefromclsid_ex3.csproj | 10 ---------- .../Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs | 4 ++-- .../GetTypeFromCLSID/gettypefromclsid_ex4.csproj | 10 ---------- .../csharp/System/Type/GetTypeFromProgID/Program.cs | 3 +++ .../System/Type/GetTypeFromProgID/Project.csproj | 6 ++++++ .../GetTypeFromProgID/type_gettypefromprogid2.cs | 4 ++-- .../type_gettypefromprogid2.csproj | 10 ---------- .../GetTypeFromProgID/type_gettypefromprogid3.cs | 4 ++-- .../type_gettypefromprogid3.csproj | 10 ---------- .../GetTypeFromProgID/type_gettypefromprogid4.cs | 4 ++-- .../type_gettypefromprogid4.csproj | 10 ---------- .../{type_haselementtype.csproj => Project.csproj} | 4 ---- .../Type/IsAssignableFrom/IsAssignableFrom2.cs | 4 ++-- .../Type/IsAssignableFrom/IsAssignableFrom2.csproj | 10 ---------- .../Type/IsAssignableFrom/IsAssignableFrom3.cs | 4 ++-- .../Type/IsAssignableFrom/IsAssignableFrom3.csproj | 10 ---------- .../csharp/System/Type/IsAssignableFrom/Program.cs | 4 ++++ .../System/Type/IsAssignableFrom/Project.csproj | 6 ++++++ .../Type/IsAssignableFrom/isassignablefrom_ex1.cs | 4 ++-- .../IsAssignableFrom/isassignablefrom_ex1.csproj | 10 ---------- .../Type/IsAssignableFrom/testisassignablefrom.cs | 4 ++-- .../IsAssignableFrom/testisassignablefrom.csproj | 10 ---------- .../csharp/System/Type/IsContextful/Project.csproj | 6 ++++++ .../Type/IsContextful/type_iscontextful.csproj | 10 ---------- .../csharp/System/Type/IsGenericType/Program.cs | 2 ++ .../csharp/System/Type/IsGenericType/Project.csproj | 6 ++++++ .../csharp/System/Type/IsGenericType/remarks.cs | 12 ++++++------ snippets/csharp/System/Type/IsGenericType/source.cs | 4 ++-- .../Type/Missing/{source.csproj => Project.csproj} | 4 ---- 85 files changed, 147 insertions(+), 400 deletions(-) rename snippets/csharp/System/Type/EmptyTypes/{source.csproj => Project.csproj} (56%) delete mode 100644 snippets/csharp/System/Type/Equals/EqualsEx1.csproj create mode 100644 snippets/csharp/System/Type/Equals/Program.cs rename snippets/csharp/System/Type/{IsGenericType/source.csproj => Equals/Project.csproj} (55%) rename snippets/csharp/System/Type/FilterName/{source.csproj => Project.csproj} (56%) delete mode 100644 snippets/csharp/System/Type/FullName/Fullname3.csproj delete mode 100644 snippets/csharp/System/Type/FullName/Fullname4.csproj delete mode 100644 snippets/csharp/System/Type/FullName/Fullname5.csproj create mode 100644 snippets/csharp/System/Type/FullName/Program.cs rename snippets/csharp/System/Type/{Equals/source.csproj => FullName/Project.csproj} (55%) delete mode 100644 snippets/csharp/System/Type/FullName/fullnameex1.csproj delete mode 100644 snippets/csharp/System/Type/FullName/testfullname.csproj create mode 100644 snippets/csharp/System/Type/GetConstructors/Program.cs rename snippets/csharp/System/Type/GetConstructors/{source2.csproj => Project.csproj} (55%) delete mode 100644 snippets/csharp/System/Type/GetConstructors/source1.csproj create mode 100644 snippets/csharp/System/Type/GetEvent/Program.cs rename snippets/csharp/System/Type/GetEvent/{type_getevent.csproj => Project.csproj} (60%) create mode 100644 snippets/csharp/System/Type/GetEvents/Program.cs rename snippets/csharp/System/Type/{GetEvent/type_getevent1.csproj => GetEvents/Project.csproj} (60%) delete mode 100644 snippets/csharp/System/Type/GetEvents/type_getevents2.csproj rename snippets/csharp/System/Type/{GetEvents/type_getevents1.csproj => GetHashCode/Project.csproj} (60%) delete mode 100644 snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj rename snippets/csharp/System/Type/{IsGenericType/remarks.csproj => GetInterface/Project.csproj} (55%) delete mode 100644 snippets/csharp/System/Type/GetInterface/type_getinterface.csproj create mode 100644 snippets/csharp/System/Type/GetInterfaceMap/Project.csproj delete mode 100644 snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj create mode 100644 snippets/csharp/System/Type/GetMembers/Program.cs create mode 100644 snippets/csharp/System/Type/GetMembers/Project.csproj delete mode 100644 snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj delete mode 100644 snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj delete mode 100644 snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/Program.cs create mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/Project.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj create mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/Program.cs create mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/Project.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj delete mode 100644 snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj rename snippets/csharp/System/Type/HasElementType/{type_haselementtype.csproj => Project.csproj} (59%) delete mode 100644 snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj delete mode 100644 snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/Program.cs create mode 100644 snippets/csharp/System/Type/IsAssignableFrom/Project.csproj delete mode 100644 snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj delete mode 100644 snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj create mode 100644 snippets/csharp/System/Type/IsContextful/Project.csproj delete mode 100644 snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj create mode 100644 snippets/csharp/System/Type/IsGenericType/Program.cs create mode 100644 snippets/csharp/System/Type/IsGenericType/Project.csproj rename snippets/csharp/System/Type/Missing/{source.csproj => Project.csproj} (66%) diff --git a/snippets/csharp/System/Type/EmptyTypes/source.csproj b/snippets/csharp/System/Type/EmptyTypes/Project.csproj similarity index 56% rename from snippets/csharp/System/Type/EmptyTypes/source.csproj rename to snippets/csharp/System/Type/EmptyTypes/Project.csproj index 0cff88c0d29..1eddf5e00ac 100644 --- a/snippets/csharp/System/Type/EmptyTypes/source.csproj +++ b/snippets/csharp/System/Type/EmptyTypes/Project.csproj @@ -2,9 +2,5 @@ Library net10.0 - false - - - diff --git a/snippets/csharp/System/Type/Equals/EqualsEx1.cs b/snippets/csharp/System/Type/Equals/EqualsEx1.cs index aa41ba7847b..acb0ad6a5d3 100644 --- a/snippets/csharp/System/Type/Equals/EqualsEx1.cs +++ b/snippets/csharp/System/Type/Equals/EqualsEx1.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Reflection; -public class Example +public class EqualsEx1Example { - public static void Main() + public static void Run() { Type t = typeof(int); object obj1 = typeof(int).GetTypeInfo(); diff --git a/snippets/csharp/System/Type/Equals/EqualsEx1.csproj b/snippets/csharp/System/Type/Equals/EqualsEx1.csproj deleted file mode 100644 index bb6239672aa..00000000000 --- a/snippets/csharp/System/Type/Equals/EqualsEx1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/Equals/Program.cs b/snippets/csharp/System/Type/Equals/Program.cs new file mode 100644 index 00000000000..eee72699813 --- /dev/null +++ b/snippets/csharp/System/Type/Equals/Program.cs @@ -0,0 +1,2 @@ +EqualsEx1Example.Run(); +EqualsSourceExample.Run(); diff --git a/snippets/csharp/System/Type/IsGenericType/source.csproj b/snippets/csharp/System/Type/Equals/Project.csproj similarity index 55% rename from snippets/csharp/System/Type/IsGenericType/source.csproj rename to snippets/csharp/System/Type/Equals/Project.csproj index 15e841d2cb3..36a29620edb 100644 --- a/snippets/csharp/System/Type/IsGenericType/source.csproj +++ b/snippets/csharp/System/Type/Equals/Project.csproj @@ -2,9 +2,5 @@ Exe net10.0 - false - - - diff --git a/snippets/csharp/System/Type/Equals/source.cs b/snippets/csharp/System/Type/Equals/source.cs index ec0d404e1e9..e8abbf1e765 100644 --- a/snippets/csharp/System/Type/Equals/source.cs +++ b/snippets/csharp/System/Type/Equals/source.cs @@ -3,9 +3,9 @@ using System; -class Example +class EqualsSourceExample { - public static void Main() + public static void Run() { Type a = typeof(string); @@ -16,8 +16,8 @@ public static void Main() // The Type objects in a and b are not equal, // because they represent different types. - a = typeof(Example); - b = new Example().GetType(); + a = typeof(EqualsSourceExample); + b = new EqualsSourceExample().GetType(); Console.WriteLine($"{a} is equal to {b}: {a.Equals(b)}"); diff --git a/snippets/csharp/System/Type/FilterName/source.csproj b/snippets/csharp/System/Type/FilterName/Project.csproj similarity index 56% rename from snippets/csharp/System/Type/FilterName/source.csproj rename to snippets/csharp/System/Type/FilterName/Project.csproj index 0cff88c0d29..1eddf5e00ac 100644 --- a/snippets/csharp/System/Type/FilterName/source.csproj +++ b/snippets/csharp/System/Type/FilterName/Project.csproj @@ -2,9 +2,5 @@ Library net10.0 - false - - - diff --git a/snippets/csharp/System/Type/FullName/Fullname3.cs b/snippets/csharp/System/Type/FullName/Fullname3.cs index 0385925ad77..edae78a295d 100644 --- a/snippets/csharp/System/Type/FullName/Fullname3.cs +++ b/snippets/csharp/System/Type/FullName/Fullname3.cs @@ -2,9 +2,9 @@ using System; -public class Example +public class FullName3Example { - public static void Main() + public static void Run() { Type t = typeof(Nullable<>); Console.WriteLine(t.FullName); diff --git a/snippets/csharp/System/Type/FullName/Fullname3.csproj b/snippets/csharp/System/Type/FullName/Fullname3.csproj deleted file mode 100644 index 944cc6d6896..00000000000 --- a/snippets/csharp/System/Type/FullName/Fullname3.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/FullName/Fullname4.cs b/snippets/csharp/System/Type/FullName/Fullname4.cs index fa4c9da183a..759c08a48a0 100644 --- a/snippets/csharp/System/Type/FullName/Fullname4.cs +++ b/snippets/csharp/System/Type/FullName/Fullname4.cs @@ -13,9 +13,9 @@ public void HandleT(T obj) public bool ChangeValue(ref T arg) => true; } -public class Example +public class FullName4Example { - public static void Main() + public static void Run() { Type t = typeof(GenericType1<>); Console.WriteLine($"Type Name: {t.FullName}"); diff --git a/snippets/csharp/System/Type/FullName/Fullname4.csproj b/snippets/csharp/System/Type/FullName/Fullname4.csproj deleted file mode 100644 index 80fe1043218..00000000000 --- a/snippets/csharp/System/Type/FullName/Fullname4.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/FullName/Fullname5.cs b/snippets/csharp/System/Type/FullName/Fullname5.cs index b47f43cc77b..90538136f52 100644 --- a/snippets/csharp/System/Type/FullName/Fullname5.cs +++ b/snippets/csharp/System/Type/FullName/Fullname5.cs @@ -6,9 +6,9 @@ public class Base { } public class Derived : Base { } -public class Example +public class FullName5Example { - public static void Main() + public static void Run() { Type t = typeof(Derived<>); Console.WriteLine($"Generic Class: {t.FullName}"); diff --git a/snippets/csharp/System/Type/FullName/Fullname5.csproj b/snippets/csharp/System/Type/FullName/Fullname5.csproj deleted file mode 100644 index ba755001bea..00000000000 --- a/snippets/csharp/System/Type/FullName/Fullname5.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/FullName/Program.cs b/snippets/csharp/System/Type/FullName/Program.cs new file mode 100644 index 00000000000..7356154ae2f --- /dev/null +++ b/snippets/csharp/System/Type/FullName/Program.cs @@ -0,0 +1,5 @@ +FullName3Example.Run(); +FullName4Example.Run(); +FullName5Example.Run(); +FullNameEx1Example.Run(); +TestFullName.Run(); diff --git a/snippets/csharp/System/Type/Equals/source.csproj b/snippets/csharp/System/Type/FullName/Project.csproj similarity index 55% rename from snippets/csharp/System/Type/Equals/source.csproj rename to snippets/csharp/System/Type/FullName/Project.csproj index 15e841d2cb3..36a29620edb 100644 --- a/snippets/csharp/System/Type/Equals/source.csproj +++ b/snippets/csharp/System/Type/FullName/Project.csproj @@ -2,9 +2,5 @@ Exe net10.0 - false - - - diff --git a/snippets/csharp/System/Type/FullName/fullnameex1.cs b/snippets/csharp/System/Type/FullName/fullnameex1.cs index c62f05b4a07..612ee255318 100644 --- a/snippets/csharp/System/Type/FullName/fullnameex1.cs +++ b/snippets/csharp/System/Type/FullName/fullnameex1.cs @@ -2,9 +2,9 @@ using System; using System.Collections.Generic; -public class Example +public class FullNameEx1Example { - public static void Main() + public static void Run() { Type t = typeof(List<>); Console.WriteLine(t.FullName); diff --git a/snippets/csharp/System/Type/FullName/fullnameex1.csproj b/snippets/csharp/System/Type/FullName/fullnameex1.csproj deleted file mode 100644 index ac5235c6d00..00000000000 --- a/snippets/csharp/System/Type/FullName/fullnameex1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/FullName/testfullname.cs b/snippets/csharp/System/Type/FullName/testfullname.cs index 0ca5eea2e2e..770a078fd45 100644 --- a/snippets/csharp/System/Type/FullName/testfullname.cs +++ b/snippets/csharp/System/Type/FullName/testfullname.cs @@ -2,7 +2,7 @@ using System; class TestFullName { - public static void Main() + public static void Run() { Type t = typeof(Array); Console.WriteLine($"The full name of the Array type is {t.FullName}."); diff --git a/snippets/csharp/System/Type/FullName/testfullname.csproj b/snippets/csharp/System/Type/FullName/testfullname.csproj deleted file mode 100644 index 5f08cae1e1f..00000000000 --- a/snippets/csharp/System/Type/FullName/testfullname.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetConstructors/Program.cs b/snippets/csharp/System/Type/GetConstructors/Program.cs new file mode 100644 index 00000000000..4c65e4bcd95 --- /dev/null +++ b/snippets/csharp/System/Type/GetConstructors/Program.cs @@ -0,0 +1,2 @@ +ConstructorSample1.Run(); +ConstructorSample2.Run(); diff --git a/snippets/csharp/System/Type/GetConstructors/source2.csproj b/snippets/csharp/System/Type/GetConstructors/Project.csproj similarity index 55% rename from snippets/csharp/System/Type/GetConstructors/source2.csproj rename to snippets/csharp/System/Type/GetConstructors/Project.csproj index 7d18a5f3a1e..36a29620edb 100644 --- a/snippets/csharp/System/Type/GetConstructors/source2.csproj +++ b/snippets/csharp/System/Type/GetConstructors/Project.csproj @@ -2,9 +2,5 @@ Exe net10.0 - false - - - diff --git a/snippets/csharp/System/Type/GetConstructors/source1.cs b/snippets/csharp/System/Type/GetConstructors/source1.cs index d4fb3c07cce..884433d1674 100644 --- a/snippets/csharp/System/Type/GetConstructors/source1.cs +++ b/snippets/csharp/System/Type/GetConstructors/source1.cs @@ -2,15 +2,14 @@ using System; using System.Reflection; -public class t +public class ConstructorSample1 { - public t() { } - static t() { } - public t(int i) { } - - public static void Main() + public ConstructorSample1() { } + static ConstructorSample1() { } + public ConstructorSample1(int i) { } + public static void Run() { - ConstructorInfo[] p = typeof(t).GetConstructors(); + ConstructorInfo[] p = typeof(ConstructorSample1).GetConstructors(); Console.WriteLine(p.Length); for (int i = 0; i < p.Length; i++) diff --git a/snippets/csharp/System/Type/GetConstructors/source1.csproj b/snippets/csharp/System/Type/GetConstructors/source1.csproj deleted file mode 100644 index fba6a4ef0af..00000000000 --- a/snippets/csharp/System/Type/GetConstructors/source1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetConstructors/source2.cs b/snippets/csharp/System/Type/GetConstructors/source2.cs index 8ae22826118..ebecc5c5ca9 100644 --- a/snippets/csharp/System/Type/GetConstructors/source2.cs +++ b/snippets/csharp/System/Type/GetConstructors/source2.cs @@ -2,15 +2,14 @@ using System; using System.Reflection; -public class t +public class ConstructorSample2 { - public t() { } - static t() { } - public t(int i) { } - - public static void Main() + public ConstructorSample2() { } + static ConstructorSample2() { } + public ConstructorSample2(int i) { } + public static void Run() { - ConstructorInfo[] p = typeof(t).GetConstructors( + ConstructorInfo[] p = typeof(ConstructorSample2).GetConstructors( BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); Console.WriteLine(p.Length); diff --git a/snippets/csharp/System/Type/GetEvent/Program.cs b/snippets/csharp/System/Type/GetEvent/Program.cs new file mode 100644 index 00000000000..d36c4a66d43 --- /dev/null +++ b/snippets/csharp/System/Type/GetEvent/Program.cs @@ -0,0 +1,2 @@ +EventExample.Run(); +EventExample1.Run(); diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent.csproj b/snippets/csharp/System/Type/GetEvent/Project.csproj similarity index 60% rename from snippets/csharp/System/Type/GetEvent/type_getevent.csproj rename to snippets/csharp/System/Type/GetEvent/Project.csproj index a6f0080cd39..1ef5ac9aa71 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent.csproj +++ b/snippets/csharp/System/Type/GetEvent/Project.csproj @@ -3,9 +3,5 @@ Exe net10.0-windows true - false - - - diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent.cs b/snippets/csharp/System/Type/GetEvent/type_getevent.cs index 53ded61f156..a9a65b4ef60 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent.cs @@ -3,9 +3,9 @@ using System.Reflection; using System.Security; -class MyEventExample +class EventExample { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs index 22f61449883..b15ee9b115d 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent1.cs +++ b/snippets/csharp/System/Type/GetEvent/type_getevent1.cs @@ -3,9 +3,9 @@ using System.Reflection; using System.Security; -class MyEventExample +class EventExample1 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetEvents/Program.cs b/snippets/csharp/System/Type/GetEvents/Program.cs new file mode 100644 index 00000000000..25e38f87f7b --- /dev/null +++ b/snippets/csharp/System/Type/GetEvents/Program.cs @@ -0,0 +1,2 @@ +EventsSample1.Run(); +EventsSample2.Run(); diff --git a/snippets/csharp/System/Type/GetEvent/type_getevent1.csproj b/snippets/csharp/System/Type/GetEvents/Project.csproj similarity index 60% rename from snippets/csharp/System/Type/GetEvent/type_getevent1.csproj rename to snippets/csharp/System/Type/GetEvents/Project.csproj index 9d383f26ae6..1ef5ac9aa71 100644 --- a/snippets/csharp/System/Type/GetEvent/type_getevent1.csproj +++ b/snippets/csharp/System/Type/GetEvents/Project.csproj @@ -3,9 +3,5 @@ Exe net10.0-windows true - false - - - diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs index 6a9e01b5597..0ef51c21f60 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents1.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents1.cs @@ -3,9 +3,9 @@ using System.Reflection; using System.Security; -class EventsSample +class EventsSample1 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs index f6248dd7d2a..741a70c984b 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents2.cs +++ b/snippets/csharp/System/Type/GetEvents/type_getevents2.cs @@ -3,9 +3,9 @@ using System.Reflection; using System.Security; -class EventsSample +class EventsSample2 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj b/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj deleted file mode 100644 index 7b4518cbdbc..00000000000 --- a/snippets/csharp/System/Type/GetEvents/type_getevents2.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - Exe - net10.0-windows - true - false - - - - - diff --git a/snippets/csharp/System/Type/GetEvents/type_getevents1.csproj b/snippets/csharp/System/Type/GetHashCode/Project.csproj similarity index 60% rename from snippets/csharp/System/Type/GetEvents/type_getevents1.csproj rename to snippets/csharp/System/Type/GetHashCode/Project.csproj index 5f634a74bfa..1ef5ac9aa71 100644 --- a/snippets/csharp/System/Type/GetEvents/type_getevents1.csproj +++ b/snippets/csharp/System/Type/GetHashCode/Project.csproj @@ -3,9 +3,5 @@ Exe net10.0-windows true - false - - - diff --git a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj b/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj deleted file mode 100644 index 478812b7139..00000000000 --- a/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - Exe - net10.0-windows - true - false - - - - - diff --git a/snippets/csharp/System/Type/IsGenericType/remarks.csproj b/snippets/csharp/System/Type/GetInterface/Project.csproj similarity index 55% rename from snippets/csharp/System/Type/IsGenericType/remarks.csproj rename to snippets/csharp/System/Type/GetInterface/Project.csproj index e1447dfcdae..36a29620edb 100644 --- a/snippets/csharp/System/Type/IsGenericType/remarks.csproj +++ b/snippets/csharp/System/Type/GetInterface/Project.csproj @@ -2,9 +2,5 @@ Exe net10.0 - false - - - diff --git a/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj b/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj deleted file mode 100644 index bf36592624a..00000000000 --- a/snippets/csharp/System/Type/GetInterface/type_getinterface.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetInterfaceMap/Project.csproj b/snippets/csharp/System/Type/GetInterfaceMap/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/GetInterfaceMap/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj b/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj deleted file mode 100644 index 5365ebdae6a..00000000000 --- a/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetMembers/Program.cs b/snippets/csharp/System/Type/GetMembers/Program.cs new file mode 100644 index 00000000000..5407163430d --- /dev/null +++ b/snippets/csharp/System/Type/GetMembers/Program.cs @@ -0,0 +1,2 @@ +Type_GetMembers.Run(); +Type_GetMembers_BindingFlags.Run(); diff --git a/snippets/csharp/System/Type/GetMembers/Project.csproj b/snippets/csharp/System/Type/GetMembers/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/GetMembers/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs b/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs index 98c0a533269..f95358629b9 100644 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs @@ -11,12 +11,12 @@ of the class 'MyClass' and displays the same to the console. using System.Security; // -class MyClass +class MembersSampleClass { public int myInt = 0; public string myString = null; - public MyClass() + public MembersSampleClass() { } public void Myfunction() @@ -26,11 +26,11 @@ public void Myfunction() class Type_GetMembers { - public static void Main() + public static void Run() { try { - MyClass myObject = new(); + MembersSampleClass myObject = new(); MemberInfo[] myMemberInfo; // Get the type of 'MyClass'. diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj b/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj deleted file mode 100644 index 834a719826b..00000000000 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs b/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs index 14998f975df..7f941571765 100644 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs +++ b/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs @@ -13,12 +13,12 @@ the console. // -class MyClass +class MembersBindingFlagsSampleClass { public int myInt = 0; public string myString = null; - public MyClass() + public MembersBindingFlagsSampleClass() { } public void Myfunction() @@ -28,11 +28,11 @@ public void Myfunction() class Type_GetMembers_BindingFlags { - public static void Main() + public static void Run() { try { - MyClass MyObject = new(); + MembersBindingFlagsSampleClass MyObject = new(); MemberInfo[] myMemberInfo; // Get the type of the class 'MyClass'. diff --git a/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj b/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj deleted file mode 100644 index b8828e48e35..00000000000 --- a/snippets/csharp/System/Type/GetMembers/type_getmembers2.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetType/Project.csproj b/snippets/csharp/System/Type/GetType/Project.csproj index 70857082ef9..1eddf5e00ac 100644 --- a/snippets/csharp/System/Type/GetType/Project.csproj +++ b/snippets/csharp/System/Type/GetType/Project.csproj @@ -1,12 +1,6 @@ - Library net10.0 - - - - - - + diff --git a/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj b/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj deleted file mode 100644 index ca162699d3f..00000000000 --- a/snippets/csharp/System/Type/GetType/mypath/v5.0/myassembly.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Library - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/Program.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/Program.cs new file mode 100644 index 00000000000..e5bc219e3f2 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/Program.cs @@ -0,0 +1,5 @@ +GetTypeFromClsidExample1.Run(); +GetTypeFromClsidExample11.Run(); +GetTypeFromClsidExample2.Run(); +GetTypeFromClsidExample3.Run(); +GetTypeFromClsidExample4.Run(); diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/Project.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs index c4bc974258c..af508f946cc 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs @@ -3,11 +3,11 @@ using System.Reflection; -public class Example +public class GetTypeFromClsidExample1 { private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - public static void Main() + public static void Run() { // Start an instance of the Word application. var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID)); diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj deleted file mode 100644 index ee05b3ec3fe..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs index 68ee2a8c98a..cd4851d6a74 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs @@ -12,9 +12,9 @@ public class ExplicitGuid public class NoExplicitGuid { } -public class Example +public class GetTypeFromClsidExample11 { - public static void Main() + public static void Run() { Type explicitType = typeof(ExplicitGuid); Guid explicitGuid = explicitType.GUID; diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj deleted file mode 100644 index 609a5c5ba62..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs index 1242352f6d4..a1f9728aad0 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs @@ -3,11 +3,11 @@ using System.Reflection; -public class Example +public class GetTypeFromClsidExample2 { private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj deleted file mode 100644 index 81d1c95abd2..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs index 910d280ca8b..f5f2672cb1d 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs @@ -3,11 +3,11 @@ using System.Reflection; using System.Runtime.InteropServices; -public class Example +public class GetTypeFromClsidExample3 { private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - public static void Main() + public static void Run() { // Start an instance of the Word application. var word = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), "computer17.central.contoso.com"); diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj deleted file mode 100644 index aab2dea9380..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs index be4acc831d5..2f5f32e40bf 100644 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs +++ b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs @@ -3,11 +3,11 @@ using System.Reflection; -public class Example +public class GetTypeFromClsidExample4 { private const string WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}"; - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj b/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj deleted file mode 100644 index ec610ea9823..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/Program.cs b/snippets/csharp/System/Type/GetTypeFromProgID/Program.cs new file mode 100644 index 00000000000..20ffc263a18 --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromProgID/Program.cs @@ -0,0 +1,3 @@ +ProgIdExample2.Run(); +ProgIdExample3.Run(); +ProgIdExample4.Run(); diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/Project.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/GetTypeFromProgID/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs index fbc9793c98d..d319b5442c5 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs @@ -1,8 +1,8 @@ // using System; -class MainApp +class ProgIdExample2 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj deleted file mode 100644 index 4ad4056a4ce..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs index 1445bacb4e7..ee9e294fe37 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs @@ -1,8 +1,8 @@ // using System; -class MainApp +class ProgIdExample3 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj deleted file mode 100644 index e25540c4396..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs index 4d6a5566f19..8f2b49274f7 100644 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs +++ b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs @@ -1,9 +1,9 @@ // using System; -class MainApp +class ProgIdExample4 { - public static void Main() + public static void Run() { try { diff --git a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj b/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj deleted file mode 100644 index ab649fb843a..00000000000 --- a/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj b/snippets/csharp/System/Type/HasElementType/Project.csproj similarity index 59% rename from snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj rename to snippets/csharp/System/Type/HasElementType/Project.csproj index cf21b2a610c..44b6b69ca6f 100644 --- a/snippets/csharp/System/Type/HasElementType/type_haselementtype.csproj +++ b/snippets/csharp/System/Type/HasElementType/Project.csproj @@ -3,9 +3,5 @@ Exe net10.0 true - false - - - diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs index 815e50c5e75..1571176e7ab 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs @@ -2,9 +2,9 @@ using System; using System.IO; -public class Example +public class IsAssignableFromExample2 { - public static void Main() + public static void Run() { Type t = typeof(Stream); Type genericT = typeof(GenericWithConstraint<>); diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj deleted file mode 100644 index 716b1d65a5d..00000000000 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs index 0d6b53d8333..8e946b32725 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs @@ -2,9 +2,9 @@ using System; using System.Collections; -public class Example +public class IsAssignableFromExample3 { - public static void Main() + public static void Run() { Type t = typeof(IEnumerable); Type c = typeof(Array); diff --git a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj b/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj deleted file mode 100644 index 7ce6f5a79b5..00000000000 --- a/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/IsAssignableFrom/Program.cs b/snippets/csharp/System/Type/IsAssignableFrom/Program.cs new file mode 100644 index 00000000000..b26637a8463 --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/Program.cs @@ -0,0 +1,4 @@ +IsAssignableFromExample1.Run(); +IsAssignableFromExample2.Run(); +IsAssignableFromExample3.Run(); +IsAssignableFromTest.Run(); diff --git a/snippets/csharp/System/Type/IsAssignableFrom/Project.csproj b/snippets/csharp/System/Type/IsAssignableFrom/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/IsAssignableFrom/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs index 15aff23aaf5..a3bde43aec2 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs @@ -6,9 +6,9 @@ public class A { } -public class Example +public class IsAssignableFromExample1 { - public static void Main() + public static void Run() { AssemblyName assemName = new() { diff --git a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj b/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj deleted file mode 100644 index 0f07dffe875..00000000000 --- a/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs index dfc60181a23..3c7161f9043 100644 --- a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs +++ b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs @@ -1,9 +1,9 @@ // using System; using System.Collections.Generic; -class Program +class IsAssignableFromTest { - public static void Main() + public static void Run() { // Demonstrate classes: Console.WriteLine("Defined Classes:"); diff --git a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj b/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj deleted file mode 100644 index 33e0c615fac..00000000000 --- a/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/IsContextful/Project.csproj b/snippets/csharp/System/Type/IsContextful/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/IsContextful/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj b/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj deleted file mode 100644 index 5ce7d2fd55c..00000000000 --- a/snippets/csharp/System/Type/IsContextful/type_iscontextful.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net10.0 - false - - - - - diff --git a/snippets/csharp/System/Type/IsGenericType/Program.cs b/snippets/csharp/System/Type/IsGenericType/Program.cs new file mode 100644 index 00000000000..dd1327fdd6d --- /dev/null +++ b/snippets/csharp/System/Type/IsGenericType/Program.cs @@ -0,0 +1,2 @@ +IsGenericTypeRemarksExample.Run(); +IsGenericTypeSourceExample.Run(); diff --git a/snippets/csharp/System/Type/IsGenericType/Project.csproj b/snippets/csharp/System/Type/IsGenericType/Project.csproj new file mode 100644 index 00000000000..36a29620edb --- /dev/null +++ b/snippets/csharp/System/Type/IsGenericType/Project.csproj @@ -0,0 +1,6 @@ + + + Exe + net10.0 + + diff --git a/snippets/csharp/System/Type/IsGenericType/remarks.cs b/snippets/csharp/System/Type/IsGenericType/remarks.cs index 7eb2ddd091c..ec533145f53 100644 --- a/snippets/csharp/System/Type/IsGenericType/remarks.cs +++ b/snippets/csharp/System/Type/IsGenericType/remarks.cs @@ -2,21 +2,21 @@ // -public class Base { } +public class RemarksBase { } -public class Derived : Base +public class RemarksDerived : RemarksBase { - public G> F; + public RemarksG> F; public class Nested { } } -public class G { } +public class RemarksG { } // -class Example +class IsGenericTypeRemarksExample { - public static void Main() + public static void Run() { } } diff --git a/snippets/csharp/System/Type/IsGenericType/source.cs b/snippets/csharp/System/Type/IsGenericType/source.cs index 3525ca2d4ab..a2b5dc7a56f 100644 --- a/snippets/csharp/System/Type/IsGenericType/source.cs +++ b/snippets/csharp/System/Type/IsGenericType/source.cs @@ -13,9 +13,9 @@ public class Nested { } public class G { } -class Example +class IsGenericTypeSourceExample { - public static void Main() + public static void Run() { // Get the generic type definition for Derived, and the base // type for Derived. diff --git a/snippets/csharp/System/Type/Missing/source.csproj b/snippets/csharp/System/Type/Missing/Project.csproj similarity index 66% rename from snippets/csharp/System/Type/Missing/source.csproj rename to snippets/csharp/System/Type/Missing/Project.csproj index da0b79f627a..fca009c3149 100644 --- a/snippets/csharp/System/Type/Missing/source.csproj +++ b/snippets/csharp/System/Type/Missing/Project.csproj @@ -2,11 +2,7 @@ Exe net10.0 - false - - -