Type.IsContextful 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,通过该值指示 Type 在上下文中是否可以被承载。
public:
property bool IsContextful { bool get(); };
public bool IsContextful { get; }
member this.IsContextful : bool
Public ReadOnly Property IsContextful As Boolean
属性值
如果 Type 能够在某个上下文中承载,则为 true
;否则为 false
。
实现
示例
下面的示例演示了 IsContextful
类的、 IsMarshalByRef 和 IsPrimitive 属性 Type 。 它会检查给定的类型是否可在上下文中承载,是否可以按引用进行封送处理,以及该类型是否为基元数据类型。
using namespace System;
using namespace System::Runtime::Remoting::Contexts;
public ref class ContextBoundClass: public ContextBoundObject
{
public:
String^ Value;
};
public ref class Example
{
public:
void Demo()
{
// Determine whether the types can be hosted in a Context.
Console::WriteLine("The IsContextful property for the {0} type is {1}.",
Example::typeid->Name, Example::typeid->IsContextful);
Console::WriteLine("The IsContextful property for the {0} type is {1}.",
ContextBoundClass::typeid->Name, ContextBoundClass::typeid->IsContextful);
// Determine whether the types are marshalled by reference.
Console::WriteLine("The IsMarshalByRef property of {0} is {1}.",
Example::typeid->Name, Example::typeid->IsMarshalByRef );
Console::WriteLine("The IsMarshalByRef property of {0} is {1}.",
ContextBoundClass::typeid->Name, ContextBoundClass::typeid->IsMarshalByRef );
// Determine whether the types are primitive datatypes.
Console::WriteLine("{0} is a primitive data type: {1}.",
int::typeid->Name, int::typeid->IsPrimitive );
Console::WriteLine("{0} is a primitive data type: {1}.",
String::typeid->Name, String::typeid->IsPrimitive );
}
};
int main()
{
Example^ ex = gcnew Example;
ex->Demo();
}
// The example displays the following output:
// The IsContextful property for the Example type is False.
// The IsContextful property for the ContextBoundClass type is True.
// The IsMarshalByRef property of Example is False.
// The IsMarshalByRef property of ContextBoundClass is True.
// Int32 is a primitive data type: True.
// String is a primitive data type: False.
using System;
using System.Runtime.Remoting.Contexts;
public class ContextBoundClass: ContextBoundObject
{
public string Value = "The Value property.";
}
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 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 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);
}
}
// The example displays the following output:
// The IsContextful property for the Example type is False.
// The IsContextful property for the ContextBoundClass type is True.
// The IsMarshalByRef property of Example is False.
// The IsMarshalByRef property of ContextBoundClass is True.
// Int32 is a primitive data type: True.
// String is a primitive data type: False.
Imports System.Runtime.Remoting.Contexts
Public Class ContextBoundClass : Inherits ContextBoundObject
Public Value As String = "The Value property."
End Class
Public Class Example
Public Shared Sub Main()
' Determine whether the types can be hosted in a Context.
Console.WriteLine("The IsContextful property for the {0} type is {1}.",
GetType(Example).Name, GetType(Example).IsContextful)
Console.WriteLine("The IsContextful property for the {0} type is {1}.",
GetType(ContextBoundClass).Name, GetType(ContextBoundClass).IsContextful)
' Determine whether the types are marshalled by reference.
Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
GetType(Example).Name, GetType(Example).IsMarshalByRef)
Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
GetType(ContextBoundClass).Name, GetType(ContextBoundClass).IsMarshalByRef)
' Determine whether the types are primitive datatypes.
Console.WriteLine("{0} is a primitive data type: {1}.",
GetType(Integer).Name, GetType(Integer).IsPrimitive)
Console.WriteLine("{0} is a primitive data type: {1}.",
GetType(String).Name, GetType(String).IsPrimitive)
End Sub
End Class
' The example displays the following output:
' The IsContextful property for the Example type is False.
' The IsContextful property for the ContextBoundClass type is True.
' The IsMarshalByRef property of Example is False.
' The IsMarshalByRef property of ContextBoundClass is True.
' Int32 is a primitive data type: True.
' String is a primitive data type: False.
注解
上下文会截获对类成员的调用,并强制实施应用于类的策略,如同步。 有关远程处理上下文的更多详细信息,请参阅 Context 。
如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false
。