private void simulateRecord() { for (int i = 0; i < ClickPriotity.Count - 2;) //取消(clrl+F2)會再算2次keydown,故減2 { Thread.Sleep(1000); if (Object.ReferenceEquals(ClickPriotity[i + 1].GetType(), pt.GetType())) { Cursor.Position = (Point)ClickPriotity[i + 1]; Thread.Sleep(200); //textBox1.Text += "Mouse!" + "\r\n"; if (WindwosHook.Buttons.Left.ToString() == ClickPriotity[i].ToString()) { SimulateControl.MouseControl.LeftClick(); } else if (WindwosHook.Buttons.Right.ToString() == ClickPriotity[i].ToString()) { SimulateControl.MouseControl.RightClick(); } i += 2; } else { SimulateControl.KeyboardControl.KeyDown((Keys)ClickPriotity[i]); Thread.Sleep(30); SimulateControl.KeyboardControl.KeyUp((Keys)ClickPriotity[i]); textBox1.Text += "keyboard!" + "\r\n"; i++; } } }
public void TestGetType() { var p = new Point(); Assert.AreEqual(p.GetType(), typeof(Point)); // class 'Type' has override "==" Assert.True(p.GetType() == typeof(Point)); Assert.True(p is Point); }
private static void getTypeAndTypeOfExamples() { Point p = new Point(); Console.WriteLine(p.GetType().Name); // Point Console.WriteLine(typeof(Point).Name); // Point Console.WriteLine(p.GetType() == typeof(Point)); // True Console.WriteLine(p.X.GetType().Name); // Int32 Console.WriteLine(p.Y.GetType().FullName); // System.Int32 }
static void testBoxUnbox() { Point p1 = new Point(6, 7); Student std = new Student(); Console.WriteLine(p1.GetType()); // => Point Console.WriteLine(std.GetType()); // => Student Object o = p1; // ldloc.0 + box Point + stloc.1 Point p2 = (Point)o; // ldloc.1 + unbox + stloc.2 o.GetType(); // ldloc.1 + callvirt Object::GetType p1.GetType(); // ldloc.0 + box Point + callvirt Object::GetType p1.Print(); // NÂO existe BOX }
private void Start() { int nVertices = nVerticesPerCube * CubeNum; material = new Material(shader); CSMainkernel = CSshader.FindKernel("CSMain"); Point[] allVertices = new Point[nVertices]; allVerticesInit(ref allVertices); //writing verticesBuffer to material/shader verticesBuffer = new ComputeBuffer(allVertices.Length, Marshal.SizeOf(allVertices.GetType().GetElementType())); verticesBuffer.SetData(allVertices); posBuffer = new ComputeBuffer(CubeNum * 3, 4);//x,y,z CSshader.SetBuffer(CSMainkernel, "posbuf", posBuffer); material.SetBuffer("posbuf", posBuffer); material.SetBuffer("points", verticesBuffer); //tell renderenging when to draw geometry camera_command_buffer = new CommandBuffer(); camera_command_buffer.DrawProcedural(Matrix4x4.identity, material, 0, MeshTopology.Triangles, nVertices); camera_source.AddCommandBuffer(CameraEvent.BeforeGBuffer, camera_command_buffer); //tell renderengine when to draw geometry for shadow pass light_command_buffer = new CommandBuffer(); light_command_buffer.DrawProcedural(Matrix4x4.identity, material, 1, MeshTopology.Triangles, nVertices); light_source.AddCommandBuffer(LightEvent.BeforeShadowMapPass, light_command_buffer); cnt = 0; }
public static void Main3() { // Create two Point instances on the stack. Point p1 = new Point(10, 10); Point p2 = new Point(20, 20); // p1 does NOT get boxed to call ToString (a virtual method). Console.WriteLine(p1.ToString());// "(10, 10)" // p DOES get boxed to call GetType (a non-virtual method). Console.WriteLine(p1.GetType());// "Point" // p1 does NOT get boxed to call CompareTo. // p2 does NOT get boxed because CompareTo(Point) is called. Console.WriteLine(p1.CompareTo(p2));// "-1" // p1 DOES get boxed, and the reference is placed in c. IComparable c = p1; Console.WriteLine(c.GetType());// "Point" // p1 does NOT get boxed to call CompareTo. // Since CompareTo is not being passed a Point variable, // CompareTo(Object) is called which requires a reference to // a boxed Point. // c does NOT get boxed because it already refers to a boxed Point. Console.WriteLine(p1.CompareTo(c));// "0" // c does NOT get boxed because it already refers to a boxed Point. // p2 does get boxed because CompareTo(Object) is called. Console.WriteLine(c.CompareTo(p2));// "-1" // c is unboxed, and fields are copied into p2. p2 = (Point)c; // Proves that the fields got copied into p2. Console.WriteLine(p2.ToString());// "(10, 10)" }
static void Main(string[] args) { Point p1 = new Point(10, 10); Point p2 = new Point(20, 20); // p1 не пакуется тк этот метод перекрыт(вызывает невиртуально) Console.WriteLine(p1.ToString()); // p1 пакуется тк getType метод базового класса (нужна ссылка this) Console.WriteLine(p1.GetType()); // "Point" // p1 не пакуется тк в структуре есть метод compareTo требующий аргумент Point(те не метод реализованный от интерфейса) // p2 не пакуется тк требуется аргумент как раз типа Point Console.WriteLine(p1.CompareTo(p2)); // p1 пакуется, тк Интерфейсы - это ссылочный тип IComparable c = p1; Console.WriteLine(c.GetType()); // "Point" //p1 не пакуется тк вызвана версия реализованная от интерфейса //c не пкауется тк это и есть ссылочный тип Console.WriteLine(p1.CompareTo(c)); // c - ссылочный тип // p2 пакуется тк c интерфейс и вызывает версию реализованную от интерфейса (compareTo(object o)) Console.WriteLine(c.CompareTo(p2)); // Распаковка C из кучи и копирование полей в p2 p2 = (Point)c; }
static void Main() { A a = new A(); Point p = new Point(7, 11); Type typeOfA = a.GetType(); Type typeOfPoint = p.GetType(); }
public void ReadFieldValue() { Point point = new Point(1, 2); double x = (double)point.GetType().GetField("X").GetValue(point); // TODO: Read the X value from the point Assert.AreEqual(1, x); }
public static void ModifyPropertyByRef() { object point = new Point(); var setter = point.GetType().GetProperty(nameof(Point.X)).SetMethod.Unreflect(); setter(point, 42); Equal(42, Unbox <Point>(point).X); }
public static void Main() { Point p = new Point(7, 3); p.Print(); Console.WriteLine(p.ToString()); // Redefinido em Point Console.WriteLine(p.GetType()); // box + call Console.WriteLine(p.GetHashCode()); // Herdado de Object }
public void PointShouldBeValidWithCorrectValues() { var newPoint = new Point(10, 10, 102100); newPoint.Should().Not.Be.Null(); newPoint.GetType().Should().Be <Point>(); newPoint.X.Should().Be(10); newPoint.Y.Should().Be(10); newPoint.SpatialReference.WKID.Should().Be(102100); }
public static void ValueTypes() { var p1 = new Point(0, 10.5); var sizeOfP1 = System.Runtime.InteropServices.Marshal.SizeOf(p1); Console.WriteLine($"Point {p1.GetX()} , {p1.GetY()} : {p1.GetType()} : Size {sizeOfP1} bytes"); var sundaySize = Value.DAYS.SUNDAY; Console.WriteLine($"enum {Value.DAYS.SUNDAY} : type: {Value.DAYS.SUNDAY.GetType()} : size {sundaySize}"); }
public void PointShouldBeValidWithCorrectValues() { var newPoint = new Point(10, 10, 102100); newPoint.Should().Not.Be.Null(); newPoint.GetType().Should().Be<Point>(); newPoint.X.Should().Be(10); newPoint.Y.Should().Be(10); newPoint.SpatialReference.WKID.Should().Be(102100); }
private static void DemoValueTypes() { Console.WriteLine("Demo start: Demo of value types."); Point p1 = new Point(5, 10); Point p2 = new Point(5, 10); Point p3 = new Point(3, 4); // What type is this valuetype & what is it derived from Console.WriteLine(" The " + p1.GetType() + " type is derived from " + p1.GetType().BaseType); // Value types compare for equality by comparing the fields Console.WriteLine(" Does p1 equal p1: " + p1.Equals(p1)); // True Console.WriteLine(" Does p1 equal p2: " + p1.Equals(p2)); // True Console.WriteLine(" Does p1 equal p3: " + p1.Equals(p3)); // False Console.WriteLine(" p1={0}, p3={1}", p1.ToString(), p3.ToString()); Console.WriteLine("Demo stop: Demo of value types."); }
static void Main() { Student p = new Student(); Console.WriteLine(p.GetType()); p.Print(); Point pt = new Point(); pt.GetType(); // TPC:Ver p IL gerado e dizer porquê? }
static void testBoxUnbox() { S s = new S(); // => inicializado => IL initobj => Iniciar espaço a Zeros C c = new C(); // => instanciado => IL newobj => malloc() + call .ctor Point p1 = new Point(); // => initobj Point p2 = new Point(6, 7); // => ___ + ldc.i4 6 + ldc.i4 7 + call Point::.ctor // Student std = new Student(); Object o = p1; // box Point p3 = (Point)o; // unbox p1.GetType(); // => box }
//private Point startPoint; //private Point endPoint; protected DrawLine(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } _shapeoutline = new ShapeOutline(this); startPoint = (Point)info.GetValue("startPoint", startPoint.GetType()); endPoint = (Point)info.GetValue("endPoint", endPoint.GetType()); _shapeoutline = (ShapeOutline)info.GetValue("shapeoutline", _shapeoutline.GetType()); }
public Edge(SerializationInfo info, StreamingContext context) { FlagVisible = 0; region = new Region(); ForInvalidate = new GraphicsPath(); variable = null; calculate = null; pen = new Pen(Color.Black, 7); PathLine = new GraphicsPath(); BeginEllips = new GraphicsPath(); EndEllips = new GraphicsPath(); BeginPoint = (Point)info.GetValue("BeginPoint", BeginPoint.GetType()); EndPoint = (Point)info.GetValue("EndPoint", EndPoint.GetType()); LastLocation = (Point)info.GetValue("LastLocation", LastLocation.GetType()); try { calculate = (ICalculate)info.GetValue("calculate", ((BaseControl)calculate).GetType()); } catch { calculate = null; } try { variable = (IVariable)info.GetValue("variable", variable.GetType()); } catch { variable = null; } BeginEllips.AddEllipse(BeginPoint.X - 10, BeginPoint.Y - 10, 20, 20); PathLine.AddLine(BeginPoint, EndPoint); EndEllips.AddEllipse(EndPoint.X - 10, EndPoint.Y - 10, 20, 20); if (Move != null) { Move(this, BeginPoint, EndPoint); } }
protected void Page_Load(object sender, EventArgs e) { Point p = new Point(100, 200); JavaScriptSerializer jss = new JavaScriptSerializer(); string json = jss.Serialize(p); JsonOutput.Text = HttpUtility.HtmlEncode (json); MemoryStream ms = new MemoryStream(); XmlSerializer xs = new XmlSerializer(p.GetType()); xs.Serialize(ms, p); string xml = new ASCIIEncoding().GetString(ms.ToArray()); XmlOutput.Text = HttpUtility.HtmlEncode (xml); }
/// <summary> /// Initializes Mqueue instance to exchange messages /// </summary> /// <param name="label">Label associated to the queue</param> /// <returns>an instance of a Mqueue</returns> private MessageQueue InitMqueue(string queue, string label) { _readerWriteLockSlim.EnterWriteLock(); try { if (MessageQueue.Exists(queue) == false) { _log.Info(string.Format("{0} ==> ERROR: No existe la Cola [{1}], se procede a crearla", MethodBase.GetCurrentMethod().Name, queue)); // Si no existe crea la cola de comunicacion MessageQueue.Create(queue); } // Abre la cola de comunicacion _adquisitionQueue = new MessageQueue(queue); // Create a new trustee to represent the "Everyone" user group. SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); var account = (NTAccount)everyone.Translate(typeof(NTAccount)); Trustee tr = new Trustee(account.Value); // Create a MessageQueueAccessControlEntry, granting the trustee the right to receive messages from the queue. MessageQueueAccessControlEntry entry = new MessageQueueAccessControlEntry(tr, MessageQueueAccessRights.FullControl, AccessControlEntryType.Allow); // Apply the MessageQueueAccessControlEntry to the queue. _adquisitionQueue.SetPermissions(entry); _adquisitionQueue.Label = string.Format("POINTS - {0}", label); _adquisitionQueue.DefaultPropertiesToSend.TimeToReachQueue = new TimeSpan(0, 0, 1); // Timeout 1 segundo if (_adquisitionQueue != null) { Point point = new Point(); Object o = new Object(); System.Type[] arrTypes = new System.Type[2]; arrTypes[0] = point.GetType(); arrTypes[1] = o.GetType(); _adquisitionQueue.Formatter = new XmlMessageFormatter(arrTypes); } return(_adquisitionQueue); } finally { _readerWriteLockSlim.ExitWriteLock(); } }
private void Start() { int nVerticesPerCube = 36; //its just like that. int nVertices = nVerticesPerCube * resX * resY; Point[] allVertices = new Point[nVertices]; int cubeCounter = 0; Vector3 cubeScale = new Vector3(range / (float)resX, range / (float)resY, range / (float)resY); //calculating size of each cublet according to range and resX & resY //iterating through each cubeposition with resX & resY aka columns/rows for (int j = 0; j < resY; j++) { for (int k = 0; k < resX; k++) { cubeCounter = (j * resY + k) * nVerticesPerCube; Vector3 posOffset = new Vector3(j * (range / resX) - range / 2f, 0, k * (range / resY) - range / 2f); //defining posiition for each cublet //getting cube data GetCube(out Vector3[] verts, out Vector3[] norms, out Vector4[] tangs, out Vector2[] uvvs, out Color[] colz); //iterating through the data we got from the function above and write it into allVertices array. for (int i = 0; i < verts.Length; i++) { Vector3 vp = new Vector3(verts[i].x * cubeScale.x, verts[i].y * cubeScale.y, verts[i].z * cubeScale.z); allVertices[cubeCounter + i].vertex = vp + posOffset; allVertices[cubeCounter + i].uv = uvvs[i]; allVertices[cubeCounter + i].normal = norms[i]; allVertices[cubeCounter + i].tangent = tangs[i]; allVertices[cubeCounter + i].color = colz[i]; allVertices[cubeCounter + i].uvHeight = new Vector2((float)k / (float)resX, (float)j / (float)resY); } } } //writing verticesBuffer to material/shader verticesBuffer = new ComputeBuffer(allVertices.Length, Marshal.SizeOf(allVertices.GetType().GetElementType())); verticesBuffer.SetData(allVertices); material.SetBuffer("points", verticesBuffer); //tell renderenging when to draw geometry camera_command_buffer = new CommandBuffer(); camera_command_buffer.DrawProcedural(Matrix4x4.identity, material, 0, MeshTopology.Triangles, nVertices); camera_source.AddCommandBuffer(CameraEvent.BeforeGBuffer, camera_command_buffer); //tell renderengine when to draw geometry for shadow pass light_command_buffer = new CommandBuffer(); light_command_buffer.DrawProcedural(Matrix4x4.identity, material, 1, MeshTopology.Triangles, nVertices); light_source.AddCommandBuffer(LightEvent.BeforeShadowMapPass, light_command_buffer); }
static void Main(string[] args) { Console.WriteLine("\n11. Differences between an abstract class and an interface \n------------------------------------"); // Instantiate using an Abstract class DerivedClass o = new DerivedClass(); o.AbstractMethod(); Console.WriteLine("- using an abstract class: w = {0}", o.W); // Instantiate using an Interface class Point pt = new Point(2, 3); Console.Write("- using an interface class: Point is " + pt.GetType() + "\n"); pt.PrintPoint(pt); }
public static void Main(String [] args) { Student s = new Student(65142, "Ze Manel", 11); // Chamada a um metodo virtual string r = s.ToString(); // ldloc.0 + callvirt Console.WriteLine(r); // > Student I am a Student // Chamada a um metodo NAO virtual // s.Print(); // ldloc.0 + callvirt Point p = new Point(5, 7); p.Module(); // ldloca + call p.GetType(); // ldloc.1 + box + call }
private void simulateRecord() { int sleepTime = Int16.Parse(textBox1.Text); int times = Int16.Parse(textBox2.Text); while (times != 0) { for (int i = 0; i < ClickPriotity.Count - 2;) //錄製結束時(Alt+F1)會多2次keydown,故減2 { Thread.Sleep(sleepTime); if (cts_run.IsCancellationRequested) { return; } if (Object.ReferenceEquals(ClickPriotity[i + 1].GetType(), CursorPos.GetType())) { Cursor.Position = (Point)ClickPriotity[i + 1]; Thread.Sleep(80); if (WindwosHook.MouseButtons.Left.ToString() == ClickPriotity[i].ToString()) { SimulateControl.MouseControl.LeftClick(); } else if (WindwosHook.MouseButtons.Right.ToString() == ClickPriotity[i].ToString()) { SimulateControl.MouseControl.RightClick(); } i += 2; } else { SimulateControl.KeyboardControl.KeyDown((Keys)ClickPriotity[i]); Thread.Sleep(30); SimulateControl.KeyboardControl.KeyUp((Keys)ClickPriotity[i]); i++; } } times--; } hotkey_Run_isWorking = false; MessageBox.Show("完成!!!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information); nicon_Click(this.nicon, new EventArgs()); }
/// <summary> /// Process the user action in the current point /// </summary> /// <param name="Methods"></param> public void ProcessAction(string Method) { if (Point != null) { MethodInfo MI = Point.GetType().GetRuntimeMethod(Method, new Type[0]); if (MI != null) { //If method is found, invoke it MI.Invoke(Point, null); //Rebuild possible actions BuildActions(); //Notify NotifyPropertyChanges(); } } }
public static void Go() { // Create two Point instances on the stack. Point p1 = new Point(10, 10); Point p2 = new Point(20, 20); // p1 does NOT get boxed to call ToString (a virtual method). Console.WriteLine(p1.ToString()); // "(10, 10)" // p DOES get boxed to call GetType (a non-virtual method). Console.WriteLine(p1.GetType()); // "Point" // p1 does NOT get boxed to call CompareTo. // p2 does NOT get boxed because CompareTo(Point) is called. Console.WriteLine(p1.CompareTo(p2)); // "-1" // p1 DOES get boxed, and the reference is placed in c. IComparable c = p1; Console.WriteLine(c.GetType()); // "Point" // p1 does NOT get boxed to call CompareTo. // Since CompareTo is not being passed a Point variable, // CompareTo(Object) is called which requires a reference to // a boxed Point. // c does NOT get boxed because it already refers to a boxed Point. Console.WriteLine(p1.CompareTo(c)); // "0" // c does NOT get boxed because it already refers to a boxed Point. // p2 does get boxed because CompareTo(Object) is called. Console.WriteLine(c.CompareTo(p2)); // "-1" var myObj = (int?)null; myObj = 78; // c is unboxed, and fields are copied into p2. p2 = (Point)c; // Proves that the fields got copied into p2. Console.WriteLine(p2.ToString()); // "(10, 10)" }
/// <summary> /// Compares for reference AND value equality. /// </summary> /// <param name="obj">The object to compare with this instance.</param> /// <returns> /// <c>true</c> if both operands are equal; otherwise, <c>false</c>. /// </returns> public bool Equals(Point obj) { bool ivarsEqual = true; if (obj.GetType() != this.GetType()) { return false; } if (this._x != obj._x) { ivarsEqual = false; } if (this._y != obj._y) { ivarsEqual = false; } return ivarsEqual; }
/** * The equals method doesn't always work--mostly on on classes that consist only of primitives. Be careful. */ public bool equals(Point rhs) { bool ivarsEqual = true; if(rhs.GetType() != this.GetType()) return false; if( ! (_x == rhs._x)) ivarsEqual = false; if( ! (_y == rhs._y)) ivarsEqual = false; return ivarsEqual; }
private static Point XMLDeserializer() { FileStream stream = new FileStream("data.xml", FileMode.Open, FileAccess.Read); Point p = new Point(); XmlSerializer serializer = new XmlSerializer(p.GetType()); p = (Point)serializer.Deserialize(stream); stream.Close(); return p; }
public virtual void ClickablePointPropertyTest () { IRawElementProviderSimple provider = GetProvider (); bool offscreen = (bool) provider.GetPropertyValue (AutomationElementIdentifiers.IsOffscreenProperty.Id); object clickablePointObj = provider.GetPropertyValue (AutomationElementIdentifiers.ClickablePointProperty.Id); Point clickablePoint = new Point (0, 0); // Clickable point should be either null or Rect.Empty if (offscreen) { if (clickablePointObj != null) { try { clickablePoint = (Point) clickablePointObj; Assert.IsTrue (clickablePoint.X >= 0, string.Format ("X is negative, your provider should be OffScreen: {0}", clickablePoint.X)); Assert.IsTrue (clickablePoint.Y >= 0, string.Format ("Y is negative, your provider should be OffScreen: {0}", clickablePoint.Y)); } catch (InvalidCastException) { Assert.Fail (string.Format ("You are not returning System.Windows.Point in ClickablePointProperty: {0}", clickablePoint,GetType ())); } } // Clickable point should intersect bounding rectangle... } else { if (clickablePointObj == null) // ...unless you are not clickable at all return; Assert.IsNotNull (clickablePoint, "Your ClickablePointProperty should not be null."); try { clickablePoint = (Point) clickablePointObj; Assert.IsTrue (clickablePoint.X >= 0, string.Format ("X is negative, your provider should be OffScreen: {0}", clickablePoint.X)); Assert.IsTrue (clickablePoint.Y >= 0, string.Format ("Y is negative, your provider should be OffScreen: {0}", clickablePoint.Y)); } catch (InvalidCastException) { Assert.Fail (string.Format ("You are not returning System.Windows.Point in ClickablePointProperty: {0}", clickablePoint.GetType ())); } object boundingRectangle = provider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id); Assert.IsNotNull (boundingRectangle, "You need to return BoundingRectangle if you return ClickablePointProperty."); try { Rect boundingRectangleRect = (Rect) boundingRectangle; Assert.AreNotEqual (Rect.Empty, boundingRectangleRect, "BoundingRectangle SHOULD NOT be Rect.Empty"); Rect clickablePointRect = new Rect (clickablePoint.X, clickablePoint.Y, 1, 1); Assert.IsTrue (boundingRectangleRect.Contains (clickablePointRect), string.Format ("ClickablePoint ({0}) SHOULD Intersect with BoundingRectangle: {1}", clickablePointRect.ToString (), boundingRectangleRect.ToString ())); } catch (InvalidCastException) { Assert.Fail (string.Format ("You are not returning System.Windows.Rect in BoundingRectangle: {0}", boundingRectangle.GetType ())); } } }