public static void TestUseCase(Assert assert) { assert.Expect(7); var t1 = new Type(); assert.Ok(t1 != null, "#565 t1"); var t2 = new ValueType(); assert.Ok(t2 != null, "#565 t2"); var t3 = new IntPtr(); assert.Ok(t3.GetType() == typeof(IntPtr), "#565 t3"); var t4 = new UIntPtr(); assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4"); var t5 = new ParamArrayAttribute(); assert.Ok(t5 != null, "#565 t5"); var t6 = new RuntimeTypeHandle(); assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6"); var t7 = new RuntimeFieldHandle(); assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7"); }
internal static bool IsParamsParameter(ParameterInfo pi) { ParamArrayAttribute attr = (ParamArrayAttribute) CliHelper.GetCustomAttribute(typeof(ParamArrayAttribute), pi); return(attr != null); }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type ParamArrayAttribute via default constructor"; string errorDesc; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ParamArrayAttribute paramArrayAtt = new ParamArrayAttribute(); if (null == paramArrayAtt) { errorDesc = "Failed to initialize an instance of type ParamArrayAttribute via default constructor."; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type ParamArrayAttribute via default constructor"; string errorDesc; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ParamArrayAttribute paramArrayAtt = new ParamArrayAttribute(); if (null == paramArrayAtt) { errorDesc = "Failed to initialize an instance of type ParamArrayAttribute via default constructor."; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public static bool IsVarArgs(this MethodBase method) { ParameterInfo[] paramInfos = method.GetParameters(); if (paramInfos.Length == 0) { return(false); } ParameterInfo last = paramInfos[paramInfos.Length - 1]; ParamArrayAttribute paAttr = last.GetSingleAttribute <ParamArrayAttribute>(); return(paAttr != null); }
static void ShowAttributeTypeIds( ) { // Get the class type, and then get the MethodInfo object // for TestMethod to access its metadata. Type clsType = typeof(TestClass); MethodInfo mInfo = clsType.GetMethod("TestMethod"); // There will be two elements in pInfoArray, one for each parameter. ParameterInfo[] pInfoArray = mInfo.GetParameters(); if (pInfoArray != null) { // Create an instance of the param array attribute on strList. ParamArrayAttribute listArrayAttr = (ParamArrayAttribute) Attribute.GetCustomAttribute(pInfoArray[1], typeof(ParamArrayAttribute)); // Create an instance of the argument usage attribute on strArray. ArgumentUsageAttribute arrayUsageAttr1 = (ArgumentUsageAttribute) Attribute.GetCustomAttribute(pInfoArray[0], typeof(ArgumentUsageAttribute)); // Create another instance of the argument usage attribute // on strArray. ArgumentUsageAttribute arrayUsageAttr2 = (ArgumentUsageAttribute) Attribute.GetCustomAttribute(pInfoArray[0], typeof(ArgumentUsageAttribute)); // Create an instance of the argument usage attribute on strList. ArgumentUsageAttribute listUsageAttr = (ArgumentUsageAttribute) Attribute.GetCustomAttribute(pInfoArray[1], typeof(ArgumentUsageAttribute)); // Display the attributes and corresponding TypeId values. Console.WriteLine("\n\"{0}\" \nTypeId: {1}", listArrayAttr.ToString(), listArrayAttr.TypeId); Console.WriteLine("\n\"{0}\" \nTypeId: {1}", arrayUsageAttr1.ToString(), arrayUsageAttr1.TypeId); Console.WriteLine("\n\"{0}\" \nTypeId: {1}", arrayUsageAttr2.ToString(), arrayUsageAttr2.TypeId); Console.WriteLine("\n\"{0}\" \nTypeId: {1}", listUsageAttr.ToString(), listUsageAttr.TypeId); } else { Console.WriteLine("The parameters information could " + "not be retrieved for method {0}.", mInfo.Name); } }
public static Type GetVarArgElementType(this MethodBase method) { ParameterInfo[] paramInfos = method.GetParameters(); if (paramInfos.Length == 0) { return(null); } ParameterInfo last = paramInfos[paramInfos.Length - 1]; ParamArrayAttribute paAttr = last.GetSingleAttribute <ParamArrayAttribute>(); if (paAttr == null) { return(null); } else { Type elementType = last.ParameterType.GetElementType(); return(elementType); } }
public static void Ctor() { var attribute = new ParamArrayAttribute(); }
/// <summary> /// Process a TilemapContent instance to prepare it for in-game use /// </summary> /// <param name="input">The TilemapContent instance to process</param> /// <param name="context">The context to process it within</param> /// <returns>The processed TilemapContent instance</returns> public override TilemapContent Process(TilemapContent input, ContentProcessorContext context) { // Build the textures used in this tilemap foreach (string path in input.ImagePaths) { input.Textures.Add(context.BuildAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(path), "")); } // Process the layers in this tilemap for (int i = 0; i < input.LayerCount; i++) { // Convert Properties to fields on the Layer foreach (string property in input.Layers[i].Properties.Keys) { switch (property) { case "ScrollingSpeed": input.Layers[i].ScrollingSpeed = float.Parse(input.Layers[i].Properties["ScrollingSpeed"]); break; case "ScrollOffset": input.Layers[i].ScrollOffset = float.Parse(input.Layers[i].Properties["ScrollOffset"]); break; case "LayerDepth": input.Layers[i].LayerDepth = float.Parse(input.Layers[i].Properties["LayerDepth"]); break; default: ParamArrayAttribute[] attrs = new ParamArrayAttribute[0]; context.Logger.LogMessage("Unknown property " + property + " in tilemap", attrs); break; } } } // Process the game object groups in this tilemap for (int i = 0; i < input.GameObjectGroupCount; i++) { // Convert Properties to fields on the GameObjectGroup foreach (string property in input.GameObjectGroups[i].Properties.Keys) { switch (property) { case "ScrollingSpeed": input.GameObjectGroups[i].ScrollingSpeed = float.Parse(input.GameObjectGroups[i].Properties["ScrollingSpeed"]); break; case "ScrollOffset": input.GameObjectGroups[i].ScrollOffset = float.Parse(input.GameObjectGroups[i].Properties["ScrollOffset"]); break; case "LayerDepth": input.GameObjectGroups[i].LayerDepth = float.Parse(input.GameObjectGroups[i].Properties["LayerDepth"]); break; default: ParamArrayAttribute[] attrs = new ParamArrayAttribute[0]; context.Logger.LogMessage("Unknown property " + property + " in tilemap", attrs); break; } // Find the player starting position, and store it in the tilemap foreach (GameObjectData goData in input.GameObjectGroups[i].GameObjectData) { if (goData.Category == "PlayerStart") { input.PlayerStart = new Microsoft.Xna.Framework.Vector2(goData.Position.Center.X, goData.Position.Center.Y); input.PlayerLayer = i; } } } } return(input); }
/// <summary> /// Process a TilemapContent instance to prepare it for in-game use /// </summary> /// <param name="input">The TilemapContent instance to process</param> /// <param name="context">The context to process it within</param> /// <returns>The processed TilemapContent instance</returns> public override TilemapContent Process(TilemapContent input, ContentProcessorContext context) { // Process the properties of this tilemap foreach (string property in input.Properties.Keys) { switch (property) { case "Music": input.MusicTitle = input.Properties[property]; break; case "WallWidth": input.WallWidth = Convert.ToInt32(input.Properties[property]); break; default: ParamArrayAttribute[] attrs = new ParamArrayAttribute[0]; context.Logger.LogMessage("Unknown property " + property + " in tilemap", attrs); break; } } // Restructure the image paths used in this tilemap for (int i = 0; i < input.ImagePaths.Length; i++) { string filename = Path.GetFileNameWithoutExtension(input.ImagePaths[i]); string[] directory = Path.GetDirectoryName(input.ImagePaths[i]).Split(Path.DirectorySeparatorChar); input.ImagePaths[i] = Path.Combine(directory[directory.Length - 1], filename); } // Process the layers in this tilemap for (int i = 0; i < input.LayerCount; i++) { // Convert Properties to fields on the Layer foreach (string property in input.Layers[i].Properties.Keys) { switch (property) { //case "ScrollingSpeed": // input.Layers[i].ScrollingSpeed = float.Parse(input.Layers[i].Properties["ScrollingSpeed"]); // break; //case "ScrollOffset": // input.Layers[i].ScrollOffset = float.Parse(input.Layers[i].Properties["ScrollOffset"]); // break; case "LayerDepth": input.Layers[i].LayerDepth = float.Parse(input.Layers[i].Properties["LayerDepth"]); break; default: ParamArrayAttribute[] attrs = new ParamArrayAttribute[0]; context.Logger.LogMessage("Unknown property " + property + " in tilemap", attrs); break; } } } // Process the game object groups in this tilemap for (int i = 0; i < input.GameObjectGroupCount; i++) { // Convert Properties to fields on the GameObjectGroup foreach (string property in input.GameObjectGroups[i].Properties.Keys) { switch (property) { //case "ScrollingSpeed": // input.GameObjectGroups[i].ScrollingSpeed = float.Parse(input.GameObjectGroups[i].Properties["ScrollingSpeed"]); // break; //case "ScrollOffset": // input.GameObjectGroups[i].ScrollOffset = float.Parse(input.GameObjectGroups[i].Properties["ScrollOffset"]); // break; case "LayerDepth": input.GameObjectGroups[i].LayerDepth = float.Parse(input.GameObjectGroups[i].Properties["LayerDepth"]); break; default: ParamArrayAttribute[] attrs = new ParamArrayAttribute[0]; context.Logger.LogMessage("Unknown property " + property + " in tilemap", attrs); break; } // Find the player starting position, and store it in the tilemap foreach (GameObjectData goData in input.GameObjectGroups[i].GameObjectData) { if (goData.Category == "PlayerStart") { input.PlayerStart = new Microsoft.Xna.Framework.Vector2(goData.Position.Center.X, goData.Position.Center.Y); input.PlayerLayer = i; } } } } return(input); }