次の方法で共有


TypeLibVarAttribute クラス

COM タイプ ライブラリからこのフィールド用に元来インポートされた VARFLAGS を格納します。

この型のすべてのメンバの一覧については、TypeLibVarAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.Runtime.InteropServices.TypeLibVarAttribute

<AttributeUsage(AttributeTargets.Field)>
NotInheritable Public Class TypeLibVarAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Field)]
public sealed class TypeLibVarAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Field)]
public __gc __sealed class TypeLibVarAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Field)
class TypeLibVarAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

タイプ ライブラリ インポータ (Tlbimp.exe) は、この属性をフィールドに適用します。

この属性はタイプ ライブラリがインポートされるときに適用され、変更されることはありません。適用されるのは、メソッドの VARFLAGS が 0 以外の場合だけです。この属性は、元の VARFLAGS がどのように設定されたかを把握する必要のあるツールが使用するために設計されています。共通言語ランタイムでは、この属性は使用されません。

使用例

[Visual Basic, C#, C++] フィールドの TypeLibVarAttribute 値を取得する方法を次の例に示します。

 
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

Module D
    Public Function IsHiddenField(ByVal fi As FieldInfo) As Boolean
        Dim FieldAttributes As Object() = fi.GetCustomAttributes(GetType(TypeLibVarAttribute), True)

        If FieldAttributes.Length > 0 Then
            Dim tlv As TypeLibVarAttribute = FieldAttributes(0)
            Dim flags As TypeLibVarFlags = tlv.Value
            Return (flags & TypeLibVarFlags.FHidden) > 0
        End If
        Return False
    End Function
End Module

[C#] 

using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace D
{
    class ClassD
    {
        public static bool IsHiddenField( FieldInfo fi )
        {
            object[] FieldAttributes = fi.GetCustomAttributes( typeof( TypeLibVarAttribute ), true);
        
            if( FieldAttributes.Length > 0 )
            {
                TypeLibVarAttribute tlv = ( TypeLibVarAttribute )FieldAttributes[0];
                TypeLibVarFlags  flags = tlv.Value;
                return ( flags & TypeLibVarFlags.FHidden ) != 0; 
            }
            return false;
        }
    }
}

[C++] 

#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

__gc class ClassD
{
public:
    static bool IsHiddenField( FieldInfo* fi )
    {
        Object* FieldAttributes[] = fi->GetCustomAttributes( __typeof( TypeLibVarAttribute ), true);

        if( FieldAttributes->Length > 0 )
        {
            TypeLibVarAttribute* tlv = dynamic_cast<TypeLibVarAttribute*>(FieldAttributes[0]);
            TypeLibVarFlags  flags = tlv->Value;
            return ( flags & TypeLibVarFlags::FHidden ) != 0; 
        }
        return false;
    }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Runtime.InteropServices

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

TypeLibVarAttribute メンバ | System.Runtime.InteropServices 名前空間 | タイプ ライブラリ インポータ (Tlbimp.exe)