本文整理汇总了C#中Mono.CSharp.MethodSpec类的典型用法代码示例。如果您正苦于以下问题:C# MethodSpec类的具体用法?C# MethodSpec怎么用?C# MethodSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodSpec类属于Mono.CSharp命名空间,在下文中一共展示了MethodSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PendingImplementation
PendingImplementation (TypeContainer container, MissingInterfacesInfo[] missing_ifaces, MethodSpec[] abstract_methods, int total)
{
var type_builder = container.Definition;
this.container = container;
pending_implementations = new TypeAndMethods [total];
int i = 0;
if (abstract_methods != null) {
int count = abstract_methods.Length;
pending_implementations [i].methods = new MethodSpec [count];
pending_implementations [i].need_proxy = new MethodSpec [count];
pending_implementations [i].methods = abstract_methods;
pending_implementations [i].found = new MethodData [count];
pending_implementations [i].type = type_builder;
++i;
}
foreach (MissingInterfacesInfo missing in missing_ifaces) {
var iface = missing.Type;
var mi = MemberCache.GetInterfaceMethods (iface);
int count = mi.Count;
pending_implementations [i].type = iface;
pending_implementations [i].optional = missing.Optional;
pending_implementations [i].methods = mi;
pending_implementations [i].found = new MethodData [count];
pending_implementations [i].need_proxy = new MethodSpec [count];
i++;
}
}
示例2: 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, InvokeBuilder.MethodBuilder, Location);
return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
base.ApplyAttributeBuilder (a, ctor, cdata, pa);
}
示例3: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.CLSCompliant) {
method.Compiler.Report.Warning (3023, 1, a.Location,
"CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
}
// This occurs after Warning -28
if (builder == null)
return;
base.ApplyAttributeBuilder (a, ctor, cdata, pa);
}
示例4: CheckReservedNameConflict
protected void CheckReservedNameConflict (string prefix, MethodSpec accessor)
{
string name;
AParametersCollection parameters;
if (accessor != null) {
name = accessor.Name;
parameters = accessor.Parameters;
} else {
name = prefix + ShortName;
if (IsExplicitImpl)
name = MemberName.Left + "." + name;
if (this is Indexer) {
parameters = ((Indexer) this).ParameterInfo;
if (prefix[0] == 's') {
var data = new IParameterData[parameters.Count + 1];
Array.Copy (parameters.FixedParameters, data, data.Length - 1);
data[data.Length - 1] = new ParameterData ("value", Parameter.Modifier.NONE);
var types = new TypeSpec[data.Length];
Array.Copy (parameters.Types, types, data.Length - 1);
types[data.Length - 1] = member_type;
parameters = new ParametersImported (data, types, false);
}
} else {
if (prefix[0] == 's')
parameters = ParametersCompiled.CreateFullyResolved (new[] { member_type });
else
parameters = ParametersCompiled.EmptyReadOnlyParameters;
}
}
var conflict = MemberCache.FindMember (Parent.Definition,
new MemberFilter (name, 0, MemberKind.Method, parameters, null),
BindingRestriction.DeclaredOnly | BindingRestriction.NoAccessors);
if (conflict != null) {
Report.SymbolRelatedToPreviousError (conflict);
Report.Error (82, Location, "A member `{0}' is already reserved", conflict.GetSignatureForError ());
}
}
示例5: 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);
}
示例6: CheckBase
protected override bool CheckBase ()
{
if (!base.CheckBase ())
return false;
if ((caching_flags & Flags.MethodOverloadsExist) != 0)
CheckForDuplications ();
if (IsExplicitImpl)
return true;
// For System.Object only
if (Parent.BaseType == null)
return true;
MemberSpec candidate;
bool overrides = false;
var base_member = FindBaseMember (out candidate, ref overrides);
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
if (base_member == null) {
if (candidate == null) {
if (this is Method && ((Method)this).ParameterInfo.IsEmpty && MemberName.Name == Destructor.MetadataName && MemberName.Arity == 0) {
Report.Error (249, Location, "Do not override `{0}'. Use destructor syntax instead",
"object.Finalize()");
} else {
Report.Error (115, Location, "`{0}' is marked as an override but no suitable {1} found to override",
GetSignatureForError (), SimpleName.GetMemberType (this));
}
} else {
Report.SymbolRelatedToPreviousError (candidate);
if (this is Event)
Report.Error (72, Location, "`{0}': cannot override because `{1}' is not an event",
GetSignatureForError (), TypeManager.GetFullNameSignature (candidate));
else if (this is PropertyBase)
Report.Error (544, Location, "`{0}': cannot override because `{1}' is not a property",
GetSignatureForError (), TypeManager.GetFullNameSignature (candidate));
else
Report.Error (505, Location, "`{0}': cannot override because `{1}' is not a method",
GetSignatureForError (), TypeManager.GetFullNameSignature (candidate));
}
return false;
}
//
// Handles ambiguous overrides
//
if (candidate != null) {
Report.SymbolRelatedToPreviousError (candidate);
Report.SymbolRelatedToPreviousError (base_member);
// Get member definition for error reporting
var m1 = MemberCache.GetMember (base_member.DeclaringType.GetDefinition (), base_member);
var m2 = MemberCache.GetMember (candidate.DeclaringType.GetDefinition (), candidate);
Report.Error (462, Location,
"`{0}' cannot override inherited members `{1}' and `{2}' because they have the same signature when used in type `{3}'",
GetSignatureForError (), m1.GetSignatureForError (), m2.GetSignatureForError (), Parent.GetSignatureForError ());
}
if (!CheckOverrideAgainstBase (base_member))
return false;
ObsoleteAttribute oa = base_member.GetAttributeObsolete ();
if (oa != null) {
if (OptAttributes == null || !OptAttributes.Contains (Module.PredefinedAttributes.Obsolete)) {
Report.SymbolRelatedToPreviousError (base_member);
Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'",
GetSignatureForError (), base_member.GetSignatureForError ());
}
} else {
if (OptAttributes != null && OptAttributes.Contains (Module.PredefinedAttributes.Obsolete)) {
Report.SymbolRelatedToPreviousError (base_member);
Report.Warning (809, 1, Location, "Obsolete member `{0}' overrides non-obsolete member `{1}'",
GetSignatureForError (), base_member.GetSignatureForError ());
}
}
base_method = base_member as MethodSpec;
return true;
}
if (base_member == null && candidate != null && (!(candidate is IParametersMember) || !(this is IParametersMember)))
base_member = candidate;
if (base_member == null) {
if ((ModFlags & Modifiers.NEW) != 0) {
if (base_member == null) {
Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required",
GetSignatureForError ());
}
}
} else {
if ((ModFlags & Modifiers.NEW) == 0) {
ModFlags |= Modifiers.NEW;
if (!IsCompilerGenerated) {
Report.SymbolRelatedToPreviousError (base_member);
if (!IsInterface && (base_member.Modifiers & (Modifiers.ABSTRACT | Modifiers.VIRTUAL | Modifiers.OVERRIDE)) != 0) {
Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
//.........这里部分代码省略.........
示例7: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
base.ApplyAttributeBuilder (a, ctor, cdata, pa);
//
// When struct constains fixed fixed and struct layout has explicitly
// set CharSet, its value has to be propagated to compiler generated
// fixed types
//
if (a.Type == pa.StructLayout) {
var value = a.GetNamedValue ("CharSet");
if (value == null)
return;
for (int i = 0; i < Members.Count; ++i) {
FixedField ff = Members [i] as FixedField;
if (ff == null)
continue;
ff.CharSet = (CharSet) System.Enum.Parse (typeof (CharSet), value.GetValue ().ToString ());
}
}
}
示例8: SetCustomAttribute
public void SetCustomAttribute (MethodSpec ctor, byte[] data)
{
FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data);
}
示例9: 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);
}
示例10: Define
public override bool Define ()
{
if (!base.Define ())
return false;
if (!CheckBase ())
return false;
MemberKind kind;
if (this is Operator)
kind = MemberKind.Operator;
else if (this is Destructor)
kind = MemberKind.Destructor;
else
kind = MemberKind.Method;
string explicit_name;
if (IsPartialDefinition) {
caching_flags &= ~Flags.Excluded_Undetected;
caching_flags |= Flags.Excluded;
// Add to member cache only when a partial method implementation has not been found yet
if ((caching_flags & Flags.PartialDefinitionExists) != 0)
return true;
if (IsExplicitImpl)
return true;
explicit_name = null;
} else {
MethodData = new MethodData (this, ModFlags, flags, this, base_method);
if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
return false;
explicit_name = MethodData.MetadataName;
}
spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, parameters, ModFlags);
if (MemberName.Arity > 0)
spec.IsGeneric = true;
Parent.MemberCache.AddMember (this, explicit_name, spec);
return true;
}
示例11: CheckImplementingMethodConstraints
public static bool CheckImplementingMethodConstraints (TypeContainer container, MethodSpec method, MethodSpec baseMethod)
{
var tparams = method.Constraints;
var base_tparams = baseMethod.Constraints;
for (int i = 0; i < tparams.Length; ++i) {
if (!tparams[i].HasSameConstraintsImplementation (base_tparams[i])) {
container.Compiler.Report.SymbolRelatedToPreviousError (method);
container.Compiler.Report.SymbolRelatedToPreviousError (baseMethod);
// Using container location because the interface can be implemented
// by base class
container.Compiler.Report.Error (425, container.Location,
"The constraints for type parameter `{0}' of method `{1}' must match the constraints for type parameter `{2}' of interface method `{3}'. Consider using an explicit interface implementation instead",
tparams[i].GetSignatureForError (), method.GetSignatureForError (),
base_tparams[i].GetSignatureForError (), baseMethod.GetSignatureForError ());
return false;
}
}
return true;
}
示例12: ApplyToExtraTarget
protected virtual void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
throw new NotSupportedException ("You forgot to define special attribute target handling");
}
示例13: Define
//
// Creates the ConstructorBuilder
//
public override bool Define ()
{
if (ConstructorBuilder != null)
return true;
if (!CheckAbstractAndExtern (block != null))
return false;
// Check if arguments were correct.
if (!CheckBase ())
return false;
if (Parent.PrimaryConstructorParameters != null && !IsPrimaryConstructor && !IsStatic) {
if (Parent.Kind == MemberKind.Struct && Initializer is ConstructorThisInitializer && Initializer.Arguments == null) {
Report.Error (8043, Location, "`{0}': Structs with primary constructor cannot specify default constructor initializer",
GetSignatureForError ());
} else if (Initializer == null || Initializer is ConstructorBaseInitializer) {
Report.Error (8037, Location, "`{0}': Instance constructor of type with primary constructor must specify `this' constructor initializer",
GetSignatureForError ());
}
}
var ca = ModifiersExtensions.MethodAttr (ModFlags) | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;
ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
ca, CallingConventions,
parameters.GetMetaInfo ());
spec = new MethodSpec (MemberKind.Constructor, Parent.Definition, this, Compiler.BuiltinTypes.Void, parameters, ModFlags);
Parent.MemberCache.AddMember (spec);
if (block != null) {
// It's here only to report an error
if (block.IsIterator) {
member_type = Compiler.BuiltinTypes.Void;
Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
}
if (Compiler.Settings.WriteMetadataOnly)
block = null;
}
return true;
}
示例14: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.Conditional) {
Error_ConditionalAttributeIsNotValid ();
return;
}
base.ApplyAttributeBuilder (a, ctor, cdata, pa);
}
示例15: ApplyAttributeBuilder
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.FieldOffset) {
status |= Status.HAS_OFFSET;
if (!Parent.PartialContainer.HasExplicitLayout) {
Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
return;
}
if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
return;
}
}
if (a.Type == pa.FixedBuffer) {
Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
return;
}
#if false
if (a.Type == pa.MarshalAs) {
UnmanagedMarshal marshal = a.GetMarshal (this);
if (marshal != null) {
FieldBuilder.SetMarshal (marshal);
}
return;
}
#endif
if ((a.HasSecurityAttribute)) {
a.Error_InvalidSecurityParent ();
return;
}
if (a.Type == pa.Dynamic) {
a.Error_MisusedDynamicAttribute ();
return;
}
FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
}