本文整理汇总了C#中Mono.CSharp.MethodSpec.GetMetaInfo方法的典型用法代码示例。如果您正苦于以下问题:C# MethodSpec.GetMetaInfo方法的具体用法?C# MethodSpec.GetMetaInfo怎么用?C# MethodSpec.GetMetaInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.MethodSpec
的用法示例。
在下文中一共展示了MethodSpec.GetMetaInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
#if false
if (a.Type == pa.MarshalAs) {
UnmanagedMarshal marshal = a.GetMarshal (this);
if (marshal != null) {
builder.SetMarshal (marshal);
}
return;
}
#endif
if (a.HasSecurityAttribute) {
a.Error_InvalidSecurityParent ();
return;
}
if (a.Type == pa.Dynamic) {
a.Error_MisusedDynamicAttribute ();
return;
}
builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例2: DefineProxy
/// <summary>
/// C# allows this kind of scenarios:
/// interface I { void M (); }
/// class X { public void M (); }
/// class Y : X, I { }
///
/// For that case, we create an explicit implementation function
/// I.M in Y.
/// </summary>
void DefineProxy (TypeSpec iface, MethodSpec base_method, MethodSpec iface_method)
{
// TODO: Handle nested iface names
string proxy_name;
var ns = iface.MemberDefinition.Namespace;
if (string.IsNullOrEmpty (ns))
proxy_name = iface.MemberDefinition.Name + "." + iface_method.Name;
else
proxy_name = ns + "." + iface.MemberDefinition.Name + "." + iface_method.Name;
var param = iface_method.Parameters;
MethodBuilder proxy = container.TypeBuilder.DefineMethod (
proxy_name,
MethodAttributes.Private |
MethodAttributes.HideBySig |
MethodAttributes.NewSlot |
MethodAttributes.CheckAccessOnOverride |
MethodAttributes.Virtual | MethodAttributes.Final,
CallingConventions.Standard | CallingConventions.HasThis,
base_method.ReturnType.GetMetaInfo (), param.GetMetaInfo ());
if (iface_method.IsGeneric) {
var gnames = iface_method.GenericDefinition.TypeParameters.Select (l => l.Name).ToArray ();
proxy.DefineGenericParameters (gnames);
}
for (int i = 0; i < param.Count; i++) {
string name = param.FixedParameters [i].Name;
ParameterAttributes attr = ParametersCompiled.GetParameterAttribute (param.FixedParameters [i].ModFlags);
proxy.DefineParameter (i + 1, attr, name);
}
int top = param.Count;
var ec = new EmitContext (new ProxyMethodContext (container), proxy.GetILGenerator (), null);
ec.EmitThis ();
// TODO: GetAllParametersArguments
for (int i = 0; i < top; i++)
ec.EmitArgumentLoad (i);
ec.Emit (OpCodes.Call, base_method);
ec.Emit (OpCodes.Ret);
container.TypeBuilder.DefineMethodOverride (proxy, (MethodInfo) iface_method.GetMetaInfo ());
}
示例3: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.HasSecurityAttribute) {
a.Error_InvalidSecurityParent ();
return;
}
if (a.Type == pa.Dynamic) {
a.Error_MisusedDynamicAttribute ();
return;
}
PropertyBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例4: Emit
public void Emit (OpCode opcode, MethodSpec method)
{
if (IsAnonymousStoreyMutateRequired)
method = method.Mutate (CurrentAnonymousMethod.Storey.Mutator);
if (method.IsConstructor)
ig.Emit (opcode, (ConstructorInfo) method.GetMetaInfo ());
else
ig.Emit (opcode, (MethodInfo) method.GetMetaInfo ());
if (TrackStackTypes) {
//
// Don't bother with ldftn/Ldvirtftn they can never appear on open stack
//
if (method.IsConstructor) {
if (opcode == OpCodes.Newobj)
SetStackType (method.DeclaringType);
} else {
if (method.ReturnType.Kind != MemberKind.Void) {
SetStackType (method.ReturnType);
}
}
}
}
示例5: SetCustomAttribute
public void SetCustomAttribute (MethodSpec ctor, byte[] data)
{
FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data);
}
示例6: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Target == AttributeTargets.Method) {
foreach (var m in members) {
var c = m as Constructor;
if (c == null)
continue;
if (c.IsPrimaryConstructor) {
c.ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
}
throw new InternalErrorException ();
}
if (has_normal_indexers && a.Type == pa.DefaultMember) {
Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer");
return;
}
if (a.Type == pa.Required) {
Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
return;
}
TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例7: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.CLSCompliant || a.Type == pa.Obsolete || a.Type == pa.Conditional) {
Report.Error (1667, a.Location,
"Attribute `{0}' is not valid on property or event accessors. It is valid on `{1}' declarations only",
a.Type.GetSignatureForError (), a.GetValidTargets ());
return;
}
if (a.IsValidSecurityAttribute ()) {
a.ExtractSecurityPermissionSet (ctor, ref declarative_security);
return;
}
if (a.Target == AttributeTargets.Method) {
method_data.MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
return;
}
if (a.Target == AttributeTargets.ReturnValue) {
if (return_attributes == null)
return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location);
return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
ApplyToExtraTarget (a, ctor, cdata, pa);
}
示例8: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Target == AttributeTargets.ReturnValue) {
if (return_attributes == null)
return_attributes = new ReturnParameter (this, MethodBuilder, Location);
return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
if (a.IsInternalMethodImplAttribute) {
is_external_implementation = true;
}
if (a.Type == pa.DllImport) {
const Modifiers extern_static = Modifiers.EXTERN | Modifiers.STATIC;
if ((ModFlags & extern_static) != extern_static) {
Report.Error (601, a.Location, "The DllImport attribute must be specified on a method marked `static' and `extern'");
}
is_external_implementation = true;
}
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null)
declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
a.ExtractSecurityPermissionSet (declarative_security);
return;
}
if (MethodBuilder != null)
MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例9: SetCustomAttribute
void SetCustomAttribute (MethodSpec ctor, byte[] data)
{
if (module_target_attrs != null)
module_target_attrs.AddAssemblyAttribute (ctor, data);
else
Builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data);
}
示例10: ApplyAttributeBuilder
public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.CLSCompliant) {
if (CodeGen.Assembly.ClsCompliantAttribute == null) {
Report.Warning (3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
} else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.GetSignatureForError ());
Report.Warning (3017, 1, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
return;
}
}
builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例11: ApplyAttributeBuilder
//.........这里部分代码省略.........
} catch {
Report.RuntimeMissingSupport (a.Location, "AssemblyVersionAttribute setting");
}
return;
}
if (a.Type == pa.AssemblyAlgorithmId) {
const int pos = 2; // skip CA header
uint alg = (uint) cdata [pos];
alg |= ((uint) cdata [pos + 1]) << 8;
alg |= ((uint) cdata [pos + 2]) << 16;
alg |= ((uint) cdata [pos + 3]) << 24;
try {
var fi = typeof (AssemblyBuilder).GetField ("algid", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
fi.SetValue (CodeGen.Assembly.Builder, alg);
} catch {
Report.RuntimeMissingSupport (a.Location, "AssemblyAlgorithmIdAttribute setting");
}
return;
}
if (a.Type == pa.AssemblyFlags) {
const int pos = 2; // skip CA header
uint flags = (uint) cdata[pos];
flags |= ((uint) cdata[pos + 1]) << 8;
flags |= ((uint) cdata[pos + 2]) << 16;
flags |= ((uint) cdata[pos + 3]) << 24;
// Ignore set PublicKey flag if assembly is not strongnamed
if ((flags & (uint) AssemblyNameFlags.PublicKey) != 0 && (CodeGen.Assembly.Builder.GetName ().KeyPair == null))
flags &= ~(uint)AssemblyNameFlags.PublicKey;
try {
var fi = typeof (AssemblyBuilder).GetField ("flags", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
fi.SetValue (CodeGen.Assembly.Builder, flags);
} catch {
Report.RuntimeMissingSupport (a.Location, "AssemblyFlagsAttribute setting");
}
return;
}
if (a.Type == pa.InternalsVisibleTo && !CheckInternalsVisibleAttribute (a))
return;
if (a.Type == pa.TypeForwarder) {
TypeSpec t = a.GetArgumentType ();
if (t == null || TypeManager.HasElementType (t)) {
Report.Error (735, a.Location, "Invalid type specified as an argument for TypeForwardedTo attribute");
return;
}
if (emitted_forwarders == null) {
emitted_forwarders = new Dictionary<ITypeDefinition, Attribute> ();
} else if (emitted_forwarders.ContainsKey (t.MemberDefinition)) {
Report.SymbolRelatedToPreviousError(emitted_forwarders[t.MemberDefinition].Location, null);
Report.Error(739, a.Location, "A duplicate type forward of type `{0}'",
TypeManager.CSharpName(t));
return;
}
emitted_forwarders.Add(t.MemberDefinition, a);
if (t.Assembly == Builder) {
Report.SymbolRelatedToPreviousError (t);
Report.Error (729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly",
TypeManager.CSharpName (t));
return;
}
if (t.IsNested) {
Report.Error (730, a.Location, "Cannot forward type `{0}' because it is a nested type",
TypeManager.CSharpName (t));
return;
}
if (add_type_forwarder == null) {
add_type_forwarder = typeof (AssemblyBuilder).GetMethod ("AddTypeForwarder",
BindingFlags.NonPublic | BindingFlags.Instance);
if (add_type_forwarder == null) {
Report.RuntimeMissingSupport (a.Location, "TypeForwardedTo attribute");
return;
}
}
add_type_forwarder.Invoke (Builder, new object[] { t.GetMetaInfo () });
return;
}
if (a.Type == pa.Extension) {
a.Error_MisusedExtensionAttribute ();
return;
}
Builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例12: BaseImplements
/// <summary>
/// This function tells whether one of our base classes implements
/// the given method (which turns out, it is valid to have an interface
/// implementation in a base
/// </summary>
bool BaseImplements (TypeSpec iface_type, MethodSpec mi, out MethodSpec base_method)
{
var base_type = container.BaseType;
//
// Setup filter with no return type to give better error message
// about mismatch at return type when the check bellow rejects them
//
var filter = new MemberFilter (mi.Name, mi.Arity, MemberKind.Method, mi.Parameters, null);
base_method = (MethodSpec) MemberCache.FindMember (base_type, filter, BindingRestriction.None);
if (base_method == null || (base_method.Modifiers & Modifiers.PUBLIC) == 0)
return false;
if (base_method.DeclaringType.IsInterface)
return false;
if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, base_method.ReturnType))
return false;
if (!base_method.IsVirtual) {
#if STATIC
var base_builder = base_method.GetMetaInfo () as MethodBuilder;
if (base_builder != null) {
//
// We can avoid creating a proxy if base_method can be marked 'final virtual'. This can
// be done for all methods from compiled assembly
//
base_builder.__SetAttributes (base_builder.Attributes | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.NewSlot);
return true;
}
#endif
DefineProxy (iface_type, base_method, mi);
}
return true;
}
示例13: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}
示例14: BaseImplements
//.........这里部分代码省略.........
MethodSpec similar_candidate = null;
foreach (var candidate in candidates) {
if (candidate.Kind != MemberKind.Method)
continue;
if (candidate.Arity != mi.Arity)
continue;
var candidate_param = ((MethodSpec) candidate).Parameters;
if (!TypeSpecComparer.Override.IsSame (parameters.Types, candidate_param.Types))
continue;
bool modifiers_match = true;
for (int i = 0; i < parameters.Count; ++i) {
//
// First check exact ref/out match
//
const Parameter.Modifier ref_out = Parameter.Modifier.REF | Parameter.Modifier.OUT;
if ((parameters.FixedParameters[i].ModFlags & ref_out) == (candidate_param.FixedParameters[i].ModFlags & ref_out))
continue;
modifiers_match = false;
//
// Different in ref/out only
//
if ((parameters.FixedParameters[i].ModFlags & candidate_param.FixedParameters[i].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
if (similar_candidate == null) {
if (!candidate.IsPublic)
break;
if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, ((MethodSpec) candidate).ReturnType))
break;
// It's used for ref/out ambiguity overload check
similar_candidate = (MethodSpec) candidate;
}
continue;
}
similar_candidate = null;
break;
}
if (!modifiers_match)
continue;
//
// From this point on the candidate is used for detailed error reporting
// because it's very close match to what we are looking for
//
base_method = (MethodSpec) candidate;
if (!candidate.IsPublic)
return false;
if (!TypeSpecComparer.Override.IsEqual (mi.ReturnType, base_method.ReturnType))
return false;
if (mi.IsGeneric && !Method.CheckImplementingMethodConstraints (container, base_method, mi)) {
return true;
}
}
if (base_method != null) {
if (similar_candidate != null) {
Report.SymbolRelatedToPreviousError (similar_candidate);
Report.SymbolRelatedToPreviousError (mi);
Report.SymbolRelatedToPreviousError (container);
Report.Warning (1956, 1, ((MemberCore) base_method.MemberDefinition).Location,
"The interface method `{0}' implementation is ambiguous between following methods: `{1}' and `{2}' in type `{3}'",
mi.GetSignatureForError (), base_method.GetSignatureForError (), similar_candidate.GetSignatureForError (), container.GetSignatureForError ());
}
break;
}
base_type = candidates[0].DeclaringType.BaseType;
if (base_type == null)
return false;
}
if (!base_method.IsVirtual) {
#if STATIC
var base_builder = base_method.GetMetaInfo () as MethodBuilder;
if (base_builder != null) {
//
// We can avoid creating a proxy if base_method can be marked 'final virtual'. This can
// be done for all methods from compiled assembly
//
base_builder.__SetAttributes (base_builder.Attributes | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.NewSlot);
return true;
}
#endif
DefineProxy (iface_type, base_method, mi);
}
return true;
}
示例15: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Target == AttributeTargets.Assembly) {
assembly.ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
if (a.Type == pa.DefaultCharset) {
switch (a.GetCharSetValue ()) {
case CharSet.Ansi:
case CharSet.None:
break;
case CharSet.Auto:
DefaultCharSet = CharSet.Auto;
DefaultCharSetType = TypeAttributes.AutoClass;
break;
case CharSet.Unicode:
DefaultCharSet = CharSet.Unicode;
DefaultCharSetType = TypeAttributes.UnicodeClass;
break;
default:
Report.Error (1724, a.Location, "Value specified for the argument to `{0}' is not valid",
a.GetSignatureForError ());
break;
}
} else if (a.Type == pa.CLSCompliant) {
Attribute cls = DeclaringAssembly.CLSCompliantAttribute;
if (cls == null) {
Report.Warning (3012, 1, a.Location,
"You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
} else if (DeclaringAssembly.IsCLSCompliant != a.GetBoolean ()) {
Report.SymbolRelatedToPreviousError (cls.Location, cls.GetSignatureForError ());
Report.Warning (3017, 1, a.Location,
"You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
return;
}
}
builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}