expando معدّل

Declares that instances of a فئة دعم expando خصائص أو that a أسلوب هو an expando كائن الدالة الإنشائية.

expando statement

الوسيطات

  • statement
    مطلوبة. A فئة أو أسلوب تعريف.

ملاحظات

The expando معدّل هو used إلى mark a فئة كـ dynamically extensible (واحد that supports expando خصائص). Expando خصائص تشغيل expando فئة instances must be accessed using the [] notation; they are not accessible مع the dot عامل. The expando معدّل also marks a أسلوب كـ an expando كائن الدالة الإنشائية.

الفئات وأساليب في فئات يمكن وضع علامة مع expandoمعدّل. حقول الخصائص، الواجهات وأعضاء من الواجهات لا تأخذ expandoمعدّل.

expandoفئة له خاصية مخفي, خاصة باسم عنصر التي تأخذ واحدة Objectمعلمة و إرجاع Object. غير مسموح لك إلى تعريف خاصية بهذا توقيع تشغيل expandoفئة.

مثال 1

يوضح المثال التالي استخدام من expandoمعدّل تشغيل فئة. الفئة expando هو مثل على JScript Object، ولكن هناك بعض الاختلافات الموضحة هنا.

expando class CExpandoExample {
   var x : int = 10;
}

// New expando class-based object.
var testClass : CExpandoExample = new CExpandoExample;
// New JScript Object.
var testObject : Object = new Object;

// Add expando properties to both objects.
testClass["x"] = "ten";
testObject["x"] = "twelve";

// Access the field of the class-based object.
print(testClass.x);      // Prints 10.
// Access the expando property.
print(testClass["x"]);   // Prints ten.

// Access the property of the class-based object.
print(testObject.x);     // Prints twelve.
// Access the same property using the [] operator.
print(testObject["x"]);  // Prints twelve.

إخراج هذا تعليمات برمجية هو

10
ten
twelve
twelve

مثال 2

يوضح المثال التالي استخدام من expandoالتعديل تشغيل أسلوب. عند الأسلوب expando هو تسمى بالطريقة المعتادة، فإنه يصل إلى الحقل x . عند الأسلوب هو استخدامه الدالة الإنشائية صريحة بالعامل جديد، يقوم Access بإضافة إحدى خصائص expando لكائن جديد.

class CExpandoExample {
   var x : int;
   expando function constructor(val : int) {
      this.x = val;
      return "Method called as a function.";
   }
}

var test : CExpandoExample = new CExpandoExample;
// Call the expando method as a function.
var str = test.constructor(123);
print(str);        // The return value is a string.
print(test.x);     // The value of x has changed to 123.

// Call the expando method as a constructor.
var obj = new test.constructor(456);
// The return value is an object, not a string.
print(obj.x);      // The x property of the new object is 456.
print(test.x);     // The x property of the original object is still 123.

إخراج هذا تعليمات برمجية هو

Method called as a function.
123
456
123

المتطلبات

الإصدار.NET

راجع أيضًا:

المرجع

ثابت معدّل

var، كشف حساب

دالة، كشف حساب

فئة، كشف حساب

المبادئ

نطاق متغيرات و الثوابت

نوع تعليق توضيحي

موارد أخرى

المُعَدِّلات