Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Reflection / Emit / FieldBuilder.cs / 1305376 / FieldBuilder.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// [....]
//
namespace System.Reflection.Emit
{
using System.Runtime.InteropServices;
using System;
using CultureInfo = System.Globalization.CultureInfo;
using System.Reflection;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
[HostProtection(MayLeakOnAbort = true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_FieldBuilder))]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class FieldBuilder : FieldInfo, _FieldBuilder
{
#region Private Data Members
private int m_fieldTok;
private FieldToken m_tkField;
private TypeBuilder m_typeBuilder;
private String m_fieldName;
private FieldAttributes m_Attributes;
private Type m_fieldType;
#endregion
#region Constructor
[System.Security.SecurityCritical] // auto-generated
internal FieldBuilder(TypeBuilder typeBuilder, String fieldName, Type type,
Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
{
if (fieldName == null)
throw new ArgumentNullException("fieldName");
if (fieldName.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fieldName");
if (fieldName[0] == '\0')
throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fieldName");
if (type == null)
throw new ArgumentNullException("type");
if (type == typeof(void))
throw new ArgumentException(Environment.GetResourceString("Argument_BadFieldType"));
Contract.EndContractBlock();
m_fieldName = fieldName;
m_typeBuilder = typeBuilder;
m_fieldType = type;
m_Attributes = attributes & ~FieldAttributes.ReservedMask;
SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(m_typeBuilder.Module);
sigHelp.AddArgument(type, requiredCustomModifiers, optionalCustomModifiers);
int sigLength;
byte[] signature = sigHelp.InternalGetSignature(out sigLength);
m_fieldTok = TypeBuilder.DefineField(m_typeBuilder.GetModuleBuilder().GetNativeHandle(),
typeBuilder.TypeToken.Token, fieldName, signature, sigLength, m_Attributes);
m_tkField = new FieldToken(m_fieldTok, type);
}
#endregion
#region Internal Members
[System.Security.SecurityCritical] // auto-generated
internal void SetData(byte[] data, int size)
{
ModuleBuilder.SetFieldRVAContent(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), m_tkField.Token, data, size);
}
internal TypeBuilder GetTypeBuilder() { return m_typeBuilder; }
#endregion
#region MemberInfo Overrides
internal int MetadataTokenInternal
{
get { return m_fieldTok; }
}
public override Module Module
{
get { return m_typeBuilder.Module; }
}
public override String Name
{
get {return m_fieldName; }
}
public override Type DeclaringType
{
get
{
if (m_typeBuilder.m_isHiddenGlobalType == true)
return null;
return m_typeBuilder;
}
}
public override Type ReflectedType
{
get
{
if (m_typeBuilder.m_isHiddenGlobalType == true)
return null;
return m_typeBuilder;
}
}
#endregion
#region FieldInfo Overrides
public override Type FieldType
{
get { return m_fieldType; }
}
public override Object GetValue(Object obj)
{
// NOTE!! If this is implemented, make sure that this throws
// a NotSupportedException for Save-only dynamic assemblies.
// Otherwise, it could cause the .cctor to be executed.
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override void SetValue(Object obj,Object val,BindingFlags invokeAttr,Binder binder,CultureInfo culture)
{
// NOTE!! If this is implemented, make sure that this throws
// a NotSupportedException for Save-only dynamic assemblies.
// Otherwise, it could cause the .cctor to be executed.
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override RuntimeFieldHandle FieldHandle
{
get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); }
}
public override FieldAttributes Attributes
{
get { return m_Attributes; }
}
#endregion
#region ICustomAttributeProvider Implementation
public override Object[] GetCustomAttributes(bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override bool IsDefined(Type attributeType, bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
#endregion
#region Public Members
public FieldToken GetToken()
{
return m_tkField;
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetOffset(int iOffset)
{
m_typeBuilder.ThrowIfCreated();
TypeBuilder.SetFieldLayoutOffset(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, iOffset);
}
[System.Security.SecuritySafeCritical] // auto-generated
[Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
{
if (unmanagedMarshal == null)
throw new ArgumentNullException("unmanagedMarshal");
Contract.EndContractBlock();
m_typeBuilder.ThrowIfCreated();
byte[] ubMarshal = unmanagedMarshal.InternalGetBytes();
TypeBuilder.SetFieldMarshal(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, ubMarshal, ubMarshal.Length);
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetConstant(Object defaultValue)
{
m_typeBuilder.ThrowIfCreated();
TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), GetToken().Token, m_fieldType, defaultValue);
}
[System.Security.SecuritySafeCritical] // auto-generated
[System.Runtime.InteropServices.ComVisible(true)]
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
if (con == null)
throw new ArgumentNullException("con");
if (binaryAttribute == null)
throw new ArgumentNullException("binaryAttribute");
Contract.EndContractBlock();
ModuleBuilder module = m_typeBuilder.Module as ModuleBuilder;
m_typeBuilder.ThrowIfCreated();
TypeBuilder.DefineCustomAttribute(module,
m_tkField.Token, module.GetConstructorToken(con).Token, binaryAttribute, false, false);
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
if (customBuilder == null)
throw new ArgumentNullException("customBuilder");
Contract.EndContractBlock();
m_typeBuilder.ThrowIfCreated();
ModuleBuilder module = m_typeBuilder.Module as ModuleBuilder;
customBuilder.CreateCustomAttribute(module, m_tkField.Token);
}
#endregion
void _FieldBuilder.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _FieldBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _FieldBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _FieldBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// [....]
//
namespace System.Reflection.Emit
{
using System.Runtime.InteropServices;
using System;
using CultureInfo = System.Globalization.CultureInfo;
using System.Reflection;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
[HostProtection(MayLeakOnAbort = true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_FieldBuilder))]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class FieldBuilder : FieldInfo, _FieldBuilder
{
#region Private Data Members
private int m_fieldTok;
private FieldToken m_tkField;
private TypeBuilder m_typeBuilder;
private String m_fieldName;
private FieldAttributes m_Attributes;
private Type m_fieldType;
#endregion
#region Constructor
[System.Security.SecurityCritical] // auto-generated
internal FieldBuilder(TypeBuilder typeBuilder, String fieldName, Type type,
Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
{
if (fieldName == null)
throw new ArgumentNullException("fieldName");
if (fieldName.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fieldName");
if (fieldName[0] == '\0')
throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fieldName");
if (type == null)
throw new ArgumentNullException("type");
if (type == typeof(void))
throw new ArgumentException(Environment.GetResourceString("Argument_BadFieldType"));
Contract.EndContractBlock();
m_fieldName = fieldName;
m_typeBuilder = typeBuilder;
m_fieldType = type;
m_Attributes = attributes & ~FieldAttributes.ReservedMask;
SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(m_typeBuilder.Module);
sigHelp.AddArgument(type, requiredCustomModifiers, optionalCustomModifiers);
int sigLength;
byte[] signature = sigHelp.InternalGetSignature(out sigLength);
m_fieldTok = TypeBuilder.DefineField(m_typeBuilder.GetModuleBuilder().GetNativeHandle(),
typeBuilder.TypeToken.Token, fieldName, signature, sigLength, m_Attributes);
m_tkField = new FieldToken(m_fieldTok, type);
}
#endregion
#region Internal Members
[System.Security.SecurityCritical] // auto-generated
internal void SetData(byte[] data, int size)
{
ModuleBuilder.SetFieldRVAContent(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), m_tkField.Token, data, size);
}
internal TypeBuilder GetTypeBuilder() { return m_typeBuilder; }
#endregion
#region MemberInfo Overrides
internal int MetadataTokenInternal
{
get { return m_fieldTok; }
}
public override Module Module
{
get { return m_typeBuilder.Module; }
}
public override String Name
{
get {return m_fieldName; }
}
public override Type DeclaringType
{
get
{
if (m_typeBuilder.m_isHiddenGlobalType == true)
return null;
return m_typeBuilder;
}
}
public override Type ReflectedType
{
get
{
if (m_typeBuilder.m_isHiddenGlobalType == true)
return null;
return m_typeBuilder;
}
}
#endregion
#region FieldInfo Overrides
public override Type FieldType
{
get { return m_fieldType; }
}
public override Object GetValue(Object obj)
{
// NOTE!! If this is implemented, make sure that this throws
// a NotSupportedException for Save-only dynamic assemblies.
// Otherwise, it could cause the .cctor to be executed.
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override void SetValue(Object obj,Object val,BindingFlags invokeAttr,Binder binder,CultureInfo culture)
{
// NOTE!! If this is implemented, make sure that this throws
// a NotSupportedException for Save-only dynamic assemblies.
// Otherwise, it could cause the .cctor to be executed.
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override RuntimeFieldHandle FieldHandle
{
get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); }
}
public override FieldAttributes Attributes
{
get { return m_Attributes; }
}
#endregion
#region ICustomAttributeProvider Implementation
public override Object[] GetCustomAttributes(bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
public override bool IsDefined(Type attributeType, bool inherit)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
}
#endregion
#region Public Members
public FieldToken GetToken()
{
return m_tkField;
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetOffset(int iOffset)
{
m_typeBuilder.ThrowIfCreated();
TypeBuilder.SetFieldLayoutOffset(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, iOffset);
}
[System.Security.SecuritySafeCritical] // auto-generated
[Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
{
if (unmanagedMarshal == null)
throw new ArgumentNullException("unmanagedMarshal");
Contract.EndContractBlock();
m_typeBuilder.ThrowIfCreated();
byte[] ubMarshal = unmanagedMarshal.InternalGetBytes();
TypeBuilder.SetFieldMarshal(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, ubMarshal, ubMarshal.Length);
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetConstant(Object defaultValue)
{
m_typeBuilder.ThrowIfCreated();
TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), GetToken().Token, m_fieldType, defaultValue);
}
[System.Security.SecuritySafeCritical] // auto-generated
[System.Runtime.InteropServices.ComVisible(true)]
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
if (con == null)
throw new ArgumentNullException("con");
if (binaryAttribute == null)
throw new ArgumentNullException("binaryAttribute");
Contract.EndContractBlock();
ModuleBuilder module = m_typeBuilder.Module as ModuleBuilder;
m_typeBuilder.ThrowIfCreated();
TypeBuilder.DefineCustomAttribute(module,
m_tkField.Token, module.GetConstructorToken(con).Token, binaryAttribute, false, false);
}
[System.Security.SecuritySafeCritical] // auto-generated
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
if (customBuilder == null)
throw new ArgumentNullException("customBuilder");
Contract.EndContractBlock();
m_typeBuilder.ThrowIfCreated();
ModuleBuilder module = m_typeBuilder.Module as ModuleBuilder;
customBuilder.CreateCustomAttribute(module, m_tkField.Token);
}
#endregion
void _FieldBuilder.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _FieldBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _FieldBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _FieldBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HttpFileCollection.cs
- Root.cs
- UmAlQuraCalendar.cs
- TableLayoutStyle.cs
- ClientBuildManagerCallback.cs
- FunctionMappingTranslator.cs
- EventlogProvider.cs
- DuplexChannel.cs
- XPathNodeIterator.cs
- HttpConfigurationSystem.cs
- BaseCollection.cs
- TableLayoutStyle.cs
- Error.cs
- WebPartTransformerAttribute.cs
- BindStream.cs
- CryptoProvider.cs
- AnimationClockResource.cs
- DateBoldEvent.cs
- WebPartHelpVerb.cs
- DataGridViewCellCollection.cs
- DataComponentNameHandler.cs
- InheritablePropertyChangeInfo.cs
- Graphics.cs
- ControlPropertyNameConverter.cs
- BindingsCollection.cs
- EasingKeyFrames.cs
- DrawingServices.cs
- WindowsEditBoxRange.cs
- MemberPathMap.cs
- ScriptReferenceEventArgs.cs
- IntegerValidatorAttribute.cs
- _KerberosClient.cs
- CharKeyFrameCollection.cs
- SQLInt16.cs
- DataControlImageButton.cs
- GrammarBuilderDictation.cs
- DoubleUtil.cs
- GridView.cs
- wgx_commands.cs
- ButtonFieldBase.cs
- Button.cs
- AssemblyBuilder.cs
- CollectionCodeDomSerializer.cs
- EditorPart.cs
- CustomErrorCollection.cs
- Focus.cs
- Timer.cs
- Part.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- TypedElement.cs
- ViewEvent.cs
- ActivationService.cs
- CodeMethodReturnStatement.cs
- SafeNativeMemoryHandle.cs
- WorkflowServiceNamespace.cs
- ColumnMapCopier.cs
- UdpDiscoveryEndpointProvider.cs
- SizeF.cs
- EdmSchemaError.cs
- ChannelSinkStacks.cs
- OwnerDrawPropertyBag.cs
- ToolStripProgressBar.cs
- XmlArrayItemAttribute.cs
- UnicastIPAddressInformationCollection.cs
- RotateTransform.cs
- SiteMapNodeCollection.cs
- Base64Encoding.cs
- BooleanFunctions.cs
- BindingList.cs
- ProtocolsSection.cs
- StrongTypingException.cs
- WebPartEditorOkVerb.cs
- AppliedDeviceFiltersEditor.cs
- ToolStripEditorManager.cs
- NumberSubstitution.cs
- TemplatedWizardStep.cs
- ViewEvent.cs
- ByteStack.cs
- Parameter.cs
- DefaultProxySection.cs
- ChannelManagerHelpers.cs
- UserControl.cs
- WebPartCatalogCloseVerb.cs
- ToolStripContainer.cs
- HitTestWithGeometryDrawingContextWalker.cs
- WasAdminWrapper.cs
- PropertyToken.cs
- TextWriterTraceListener.cs
- CommandEventArgs.cs
- RecordBuilder.cs
- UndoEngine.cs
- SafeNativeMethods.cs
- DataIdProcessor.cs
- DefaultObjectMappingItemCollection.cs
- TreeSet.cs
- SoapUnknownHeader.cs
- PropertyStore.cs
- VerificationException.cs
- _SslState.cs
- SHA1.cs