protected virtual unsafe void DefineGenericTypeParameter(TypeBuilder typeBuilder, GenericTypeParameterBuilder paramBuilder, BCSYM_GenericParam* pParam) { paramBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(pParam)); List<Type> list = new List<Type>(); for (BCSYM_GenericConstraint* constraintPtr = *((BCSYM_GenericConstraint**) (pParam + 0x54)); constraintPtr != null; constraintPtr = *((BCSYM_GenericConstraint**) (constraintPtr + 8))) { if (((byte) (*(((byte*) constraintPtr)) == 0x26)) != 0) { BCSYM* pSymbol = BCSYM.DigThroughNamedType(*((BCSYM* modopt(IsConst) modopt(IsConst)*) (constraintPtr + 12))); Type item = this.GetType(typeBuilder, pSymbol); if (BCSYM.IsInterface(pSymbol)) { list.Add(item); } else { paramBuilder.SetBaseTypeConstraint(item); } } } if (list.Count > 0) { paramBuilder.SetInterfaceConstraints(list.ToArray()); } }
public HandlerClassBuildingContext(IReadOnlyList<ServiceDescription> serviceDescriptionChain, MethodDescription methodDescription, TypeBuilder builder, GenericTypeParameterBuilder[] genericTypeParameterBuilders, HandlerClassFieldCache fields) { ServiceDescriptionChain = serviceDescriptionChain; MethodDescription = methodDescription; Builder = builder; GenericTypeParameterBuilders = genericTypeParameterBuilders; Fields = fields; }
internal void RegisterBuilder(GenericTypeParameterBuilder builder) { if (Builder != null) { throw new InvalidOperationException(); } Builder = builder; Info = Builder; }
/// <summary>测试给定的对象是否为 EventToken 的实例,并检查它是否与当前实例相等。</summary> /// <returns>如果 <paramref name="o" /> 为 EventToken 的实例并等于当前实例,则返回 true;否则返回 false。</returns> /// <param name="o">要与当前实例进行比较的对象。</param> public override bool Equals(object o) { GenericTypeParameterBuilder parameterBuilder = o as GenericTypeParameterBuilder; if ((Type)parameterBuilder == (Type)null) { return(false); } return(parameterBuilder.m_type == this.m_type); }
public override bool Equals(object o) { GenericTypeParameterBuilder builder = o as GenericTypeParameterBuilder; if (builder == null) { return(false); } return(object.ReferenceEquals(builder.m_type, this.m_type)); }
public StubInfo(MethodBase methodBase, ParameterInfo[] parameters, GenericTypeParameterBuilder[] typeParameters, Type returnType) { Debug.Assert(methodBase is MethodBuilder || methodBase is ConstructorBuilder); this.methodBase = methodBase; this.Parameters = parameters; this.TypeParameters = typeParameters; this.ReturnType = returnType; }
public override bool Equals(object o) { GenericTypeParameterBuilder g = o as GenericTypeParameterBuilder; if (g == null) { return(false); } return(object.ReferenceEquals(g.m_type, m_type)); }
public BindDelegateExpression(Type @delegate, Expression owner, MethodInfo methodToBindTo, GenericTypeParameterBuilder[] genericTypeParams) { delegateCtor = @delegate.GetConstructors()[0]; this.methodToBindTo = methodToBindTo; if(@delegate.IsGenericTypeDefinition) { var closedDelegate = @delegate.MakeGenericType(genericTypeParams); delegateCtor = TypeBuilder.GetConstructor(closedDelegate, delegateCtor); this.methodToBindTo = methodToBindTo.MakeGenericMethod(genericTypeParams); } this.owner = owner; }
internal void FinishDefinition(GenericTypeParameterBuilder arg) { Contracts.Require.IsNotNull("arg", arg); arg.SetGenericParameterAttributes(Attributes); if (_baseTypeConstraint != null) { arg.SetBaseTypeConstraint(_baseTypeConstraint.Target); } if (_interfaceConstraints.Count > 0) { arg.SetInterfaceConstraints((from i in _interfaceConstraints select i.Target).ToArray()); } }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) { throw new ArgumentNullException("names"); } generic_params = new GenericTypeParameterBuilder [names.Length]; for (int i = 0; i < names.Length; i++) { generic_params [i] = new GenericTypeParameterBuilder( type, this, names [i], i); } return(generic_params); }
public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names) { if (names == null) throw new ArgumentNullException ("names"); if (names.Length == 0) throw new ArgumentException ("", "names"); type.check_not_created (); generic_params = new GenericTypeParameterBuilder [names.Length]; for (int i = 0; i < names.Length; i++) { string item = names [i]; if (item == null) throw new ArgumentNullException ("names"); generic_params [i] = new GenericTypeParameterBuilder (type, this, item, i); } return generic_params; }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) { throw new ArgumentNullException(nameof(names)); } if (names.Length == 0) { throw new ArgumentException(SR.Arg_EmptyArray, nameof(names)); } if (m_inst != null) { throw new InvalidOperationException( SR.InvalidOperation_GenericParametersAlreadySet ); } for (int i = 0; i < names.Length; i++) { if (names[i] == null) { throw new ArgumentNullException(nameof(names)); } } if (m_token != 0) { throw new InvalidOperationException(SR.InvalidOperation_MethodBuilderBaked); } m_bIsGenMethDef = true; m_inst = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) { m_inst[i] = new GenericTypeParameterBuilder(new TypeBuilder(names[i], i, this)); } return(m_inst); }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) { throw new ArgumentNullException(nameof(names)); } if (names.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(names)); } Contract.EndContractBlock(); if (m_inst != null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_GenericParametersAlreadySet")); } for (int i = 0; i < names.Length; i++) { if (names[i] == null) { throw new ArgumentNullException(nameof(names)); } } if (m_tkMethod.Token != 0) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodBuilderBaked")); } m_bIsGenMethDef = true; m_inst = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) { m_inst[i] = new GenericTypeParameterBuilder(new TypeBuilder(names[i], i, this)); } return(m_inst); }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (m_inst != null) { throw new InvalidOperationException(); } if (names == null) { throw new ArgumentNullException("names"); } for (int i = 0; i < names.Length; i++) { if (names[i] == null) { throw new ArgumentNullException("names"); } } if (m_tkMethod.Token != 0) { throw new InvalidOperationException(); } if (names.Length == 0) { throw new ArgumentException(); } m_bIsGenMethDef = true; m_inst = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) { m_inst[i] = new GenericTypeParameterBuilder(new TypeBuilder(names[i], i, this)); } return(m_inst); }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) { throw new ArgumentNullException(nameof(names)); } if (names.Length == 0) { throw new ArgumentException(SR.Arg_EmptyArray, nameof(names)); } type.check_not_created(); generic_params = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) { string item = names[i]; if (item == null) { throw new ArgumentNullException(nameof(names)); } generic_params[i] = new GenericTypeParameterBuilder(type, this, item, i); } return(generic_params); }
private void EmitCustomAttributes(GenericTypeParameterBuilder genericParamBuilder, IEnumerable<Cci.ICustomAttribute> attributes) { foreach (var attribute in attributes) { genericParamBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute)); } }
private void DefineGenericParameterConstraints(GenericTypeParameterBuilder gpBuilder, Cci.IGenericParameter typeParameter) { List<Type> typeConstraints = new List<Type>(); foreach (var constraint in typeParameter.GetConstraints(_context)) { // generic constraints must be loaded before the declaring type: var typeConstraint = ResolveType(constraint, dependentType: (TypeBuilder)gpBuilder.DeclaringType, valueTypeDependency: false); typeConstraints.Add(typeConstraint); } // The types actually don't need to be interfaces. Ref.Emit merges them eventually with base type constraint into a single list. // Besides there might be multiple non-interface constraints applied on the parameter if they are another type parameters. gpBuilder.SetInterfaceConstraints(typeConstraints.ToArray()); gpBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(typeParameter)); }
void DefineGenericParameters(GenericTypeParameterBuilder[] builders, GenericParameterDeclaration[] declarations) { // Set builders for (int i = 0; i < builders.Length; i++) { SetBuilder(declarations[i], builders[i]); } // TODO: Set constraints }
private static void CopyNonInheritableAttributes(GenericTypeParameterBuilder newGenericParameter, Type originalGenericArgument) { foreach (var attribute in originalGenericArgument.GetTypeInfo().GetNonInheritableAttributes()) { newGenericParameter.SetCustomAttribute(attribute); } }
private static Type AdjustConstraintToNewGenericParameters( Type constraint, MethodInfo methodToCopyGenericsFrom, Type[] originalGenericParameters, GenericTypeParameterBuilder[] newGenericParameters) { if (constraint.GetTypeInfo().IsGenericType) { var genericArgumentsOfConstraint = constraint.GetGenericArguments(); for (var i = 0; i < genericArgumentsOfConstraint.Length; ++i) { genericArgumentsOfConstraint[i] = AdjustConstraintToNewGenericParameters(genericArgumentsOfConstraint[i], methodToCopyGenericsFrom, originalGenericParameters, newGenericParameters); } return constraint.GetGenericTypeDefinition().MakeGenericType(genericArgumentsOfConstraint); } else if (constraint.GetTypeInfo().IsGenericParameter) { // Determine the source of the parameter if (constraint.GetTypeInfo().DeclaringMethod != null) { // constraint comes from the method var index = Array.IndexOf(originalGenericParameters, constraint); Trace.Assert(index != -1, "When a generic method parameter has a constraint on another method parameter, both parameters must be declared on the same method."); return newGenericParameters[index].AsType(); } else // parameter from surrounding type { Trace.Assert(constraint.DeclaringType.GetTypeInfo().IsGenericTypeDefinition); Trace.Assert(methodToCopyGenericsFrom.DeclaringType.GetTypeInfo().IsGenericType && constraint.DeclaringType == methodToCopyGenericsFrom.DeclaringType.GetGenericTypeDefinition(), "When a generic method parameter has a constraint on a generic type parameter, the generic type must be the declaring typer of the method."); var index = Array.IndexOf(constraint.DeclaringType.GetGenericArguments(), constraint); Trace.Assert(index != -1, "The generic parameter comes from the given type."); return methodToCopyGenericsFrom.DeclaringType.GetGenericArguments()[index]; // these are the actual, concrete types } } else { return constraint; } }
private void DefineGenericParameter(InternalGenericParameter parameter, GenericTypeParameterBuilder builder) { // Set base type constraint if (parameter.BaseType != TypeSystemServices.ObjectType) { builder.SetBaseTypeConstraint(GetSystemType(parameter.BaseType)); } // Set interface constraints Type[] interfaceTypes = Array.ConvertAll<IType, Type>( parameter.GetInterfaces(), GetSystemType); builder.SetInterfaceConstraints(interfaceTypes); // Set special attributes GenericParameterAttributes attributes = GenericParameterAttributes.None; if (parameter.IsClass) attributes |= GenericParameterAttributes.ReferenceTypeConstraint; if (parameter.IsValueType) attributes |= GenericParameterAttributes.NotNullableValueTypeConstraint; if (parameter.MustHaveDefaultConstructor) attributes |= GenericParameterAttributes.DefaultConstructorConstraint; builder.SetGenericParameterAttributes(attributes); }
private void VerificationHelper(GenericTypeParameterBuilder[] desiredParameters, Type[] actualParameters) { if (null == desiredParameters) Assert.Null(actualParameters); if (null != desiredParameters) { Assert.NotNull(actualParameters); Assert.Equal(desiredParameters.Length, actualParameters.Length); for (int i = 0; i < actualParameters.Length; ++i) { Assert.True(desiredParameters[i].Equals(actualParameters[i])); } } }
public static FieldBuilder DefineField(this TypeBuilder tb, string fieldName, GenericTypeParameterBuilder genericTypeParameterBuilder, FieldAttributes attributes) { return(tb.DefineField(fieldName, genericTypeParameterBuilder.AsType(), attributes)); }
/// <summary> /// This is the first method which is called during the resolving /// process; we're called immediately after creating the type parameters /// with SRE (by calling `DefineGenericParameters()' on the TypeBuilder / /// MethodBuilder). /// /// We're either called from TypeContainer.DefineType() or from /// GenericMethod.Define() (called from Method.Define()). /// </summary> public void Define (GenericTypeParameterBuilder type) { if (this.type != null) throw new InvalidOperationException (); this.type = type; TypeManager.AddTypeParameter (type, this); }
private static void UpdateGenericParameterContraints(RppGenericParameter genericParameter, GenericTypeParameterBuilder nativeGenericParameter) { if (genericParameter.Constraint != null) { if (genericParameter.Constraint.IsClass) { nativeGenericParameter.SetBaseTypeConstraint(genericParameter.Constraint.NativeType); } else { nativeGenericParameter.SetInterfaceConstraints(genericParameter.Constraint.NativeType); } } }
private static void UpdateGenericParameter(RppGenericParameter genericParameter, GenericTypeParameterBuilder nativeGenericParameter) { genericParameter.SetGenericTypeParameterBuilder(nativeGenericParameter); UpdateGenericParameterContraints(genericParameter, nativeGenericParameter); }
private static Type[] AdjustGenericConstraints(MethodInfo methodToCopyGenericsFrom, GenericTypeParameterBuilder[] newGenericParameters, Type[] originalGenericArguments, Type[] constraints) { for (var i = 0; i < constraints.Length; i++) { constraints[i] = AdjustConstraintToNewGenericParameters(constraints[i], methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); } return constraints; }
public void EmitConstraints (GenericTypeParameterBuilder builder) { var attr = GenericParameterAttributes.None; if (spec.Variance == Variance.Contravariant) attr |= GenericParameterAttributes.Contravariant; else if (spec.Variance == Variance.Covariant) attr |= GenericParameterAttributes.Covariant; if (spec.HasSpecialClass) attr |= GenericParameterAttributes.ReferenceTypeConstraint; else if (spec.HasSpecialStruct) attr |= GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint; if (spec.HasSpecialConstructor) attr |= GenericParameterAttributes.DefaultConstructorConstraint; if (spec.BaseType != TypeManager.object_type) builder.SetBaseTypeConstraint (spec.BaseType.GetMetaInfo ()); if (spec.InterfacesDefined != null) builder.SetInterfaceConstraints (spec.InterfacesDefined.Select (l => l.GetMetaInfo ()).ToArray ()); if (spec.TypeArguments != null) builder.SetInterfaceConstraints (spec.TypeArguments.Select (l => l.GetMetaInfo ()).ToArray ()); builder.SetGenericParameterAttributes (attr); }
public static void RegisterBuilders(this IReadOnlyList<GenericParameterStructure> gnr, GenericTypeParameterBuilder[] builders) { for (var i = 0; i < gnr.Count; ++i) { gnr[i].RegisterBuilder(builders[i]); } }
private static void BuildCtor(DynamicTypeInfo info, TypeBuilder typBuilder, List<FieldBuilder> fieldBuilders, GenericTypeParameterBuilder[] parameterBuilders) { Type[] ctorParams = parameterBuilders; var ctorBuilder = typBuilder.DefineConstructor( MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, ctorParams); ILGenerator ctorIL = ctorBuilder.GetILGenerator(); ctorIL.Emit(OpCodes.Ldarg_0); // var baseCtorInfo = typeof(Object).GetConstructor(new Type[0]); var baseCtorInfo = typeof(DynamicTypeBase).GetConstructor(new Type[0]); ctorIL.Emit(OpCodes.Call, baseCtorInfo); for (byte i = 0; i < info.PropertyNames.Count; i++) { ctorIL.Emit(OpCodes.Ldarg_0); if (i == 0) { ctorIL.Emit(OpCodes.Ldarg_1); } else if (i == 1) { ctorIL.Emit(OpCodes.Ldarg_2); } else if (i == 2) { ctorIL.Emit(OpCodes.Ldarg_3); } else { ctorIL.Emit(OpCodes.Ldarg_S, i + 1); } ctorIL.Emit(OpCodes.Stfld, fieldBuilders[i]); } //Get the base constructor ctorIL.Emit(OpCodes.Ret); }
void DefineGenericParameters(GenericTypeParameterBuilder[] builders, GenericParameterDeclaration[] declarations) { for (int i = 0; i < builders.Length; i++) { SetBuilder(declarations[i], builders[i]); DefineGenericParameter(((InternalGenericParameter)declarations[i].Entity), builders[i]); } }
//// This method does not work for Silverlight. It executes but the call to Equals fails with a VerificationException at runtime //private static void BuildEqualsMethod(DynamicTypeInfo info, TypeBuilder typBuilder, List<FieldBuilder> fields) { // var methodBuilder = typBuilder.DefineMethod("Equals", // MethodAttributes.Public | MethodAttributes.ReuseSlot | // MethodAttributes.Virtual | MethodAttributes.HideBySig, // typeof(bool), new Type[] { typeof(object) }); // var generator = methodBuilder.GetILGenerator(); // LocalBuilder other = generator.DeclareLocal(typBuilder); // Label next = generator.DefineLabel(); // generator.Emit(OpCodes.Ldarg_1); // generator.Emit(OpCodes.Isinst, typBuilder); // generator.Emit(OpCodes.Stloc, other); // generator.Emit(OpCodes.Ldloc, other); // generator.Emit(OpCodes.Brtrue_S, next); // generator.Emit(OpCodes.Ldc_I4_0); // generator.Emit(OpCodes.Ret); // generator.MarkLabel(next); // var tuples = info.PropertyTypes.Zip(fields, (t, f) => Tuple.Create(t, f)); // foreach (var tuple in tuples) { // // can't use field.FieldType because it returns an unresolved generic type. // Type fieldType = tuple.Item1; // field.FieldType; // FieldBuilder field = tuple.Item2; // Type ct = typeof(EqualityComparer<>).MakeGenericType(fieldType); // next = generator.DefineLabel(); // generator.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null); // generator.Emit(OpCodes.Ldarg_0); // generator.Emit(OpCodes.Ldfld, field); // generator.Emit(OpCodes.Ldloc, other); // generator.Emit(OpCodes.Ldfld, field); // generator.EmitCall(OpCodes.Callvirt, ct.GetMethod("Equals", new Type[] { fieldType, fieldType }), null); // generator.Emit(OpCodes.Brtrue_S, next); // generator.Emit(OpCodes.Ldc_I4_0); // generator.Emit(OpCodes.Ret); // generator.MarkLabel(next); // } // generator.Emit(OpCodes.Ldc_I4_1); // generator.Emit(OpCodes.Ret); //} //// This method does not work for Silverlight. It executes but the call to GetHashCode fails with a VerificationException at runtime //private static void BuildGetHashCodeMethod(DynamicTypeInfo info, TypeBuilder typBuilder, List<FieldBuilder> fields) { // var mb = typBuilder.DefineMethod("GetHashCode", // MethodAttributes.Public | MethodAttributes.ReuseSlot | // MethodAttributes.Virtual | MethodAttributes.HideBySig, // typeof(int), Type.EmptyTypes); // var generator = mb.GetILGenerator(); // generator.Emit(OpCodes.Ldc_I4_0); // var tuples = info.PropertyTypes.Zip(fields, (t, f) => Tuple.Create(t, f)); // foreach (var tuple in tuples) { // Type fieldType = tuple.Item1; // field.FieldType; // var field = tuple.Item2; // Type ct = typeof(EqualityComparer<>).MakeGenericType(fieldType); // generator.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null); // generator.Emit(OpCodes.Ldarg_0); // generator.Emit(OpCodes.Ldfld, field); // generator.EmitCall(OpCodes.Callvirt, ct.GetMethod("GetHashCode", new Type[] { fieldType }), null); // generator.Emit(OpCodes.Xor); // } // generator.Emit(OpCodes.Ret); //} private static IEnumerable<FieldBuilder> BuildFields(DynamicTypeInfo info, TypeBuilder typBuilder, GenericTypeParameterBuilder[] parameterBuilders) { var propertyCount = info.PropertyNames.Count; for (int i = 0; i < propertyCount; i++) { yield return typBuilder.DefineField("_" + info.PropertyNames[i], parameterBuilders[i], FieldAttributes.Private | FieldAttributes.InitOnly); } }
private static Type[] AdjustGenericConstraints(MethodInfo methodToCopyGenericsFrom, GenericTypeParameterBuilder[] newGenericParameters, Type[] originalGenericArguments, Type[] constraints) { // HACK: the mono runtime has a strange bug where assigning to the constraints // parameter and returning it throws, so we'll create a new array. // System.ArrayTypeMismatchException : Source array type cannot be assigned to destination array type. Type[] adjustedConstraints = new Type[constraints.Length]; for (var i = 0; i < constraints.Length; i++) { adjustedConstraints[i] = AdjustConstraintToNewGenericParameters(constraints[i], methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); } return adjustedConstraints; }
// // This is the first method which is called during the resolving // process; we're called immediately after creating the type parameters // with SRE (by calling `DefineGenericParameters()' on the TypeBuilder / // MethodBuilder). // public void Define (GenericTypeParameterBuilder type, TypeSpec declaringType) { if (builder != null) throw new InternalErrorException (); this.builder = type; spec.DeclaringType = declaringType; spec.SetMetaInfo (type); }
public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names) { if (names == null) throw new ArgumentNullException ("names"); if (names.Length == 0) throw new ArgumentException ("names"); generic_params = new GenericTypeParameterBuilder [names.Length]; for (int i = 0; i < names.Length; i++) { string item = names [i]; if (item == null) throw new ArgumentNullException ("names"); generic_params [i] = new GenericTypeParameterBuilder (type, this, item, i); } return generic_params; }
public static PropertyBuilder DefineProperty(this TypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, GenericTypeParameterBuilder returnType, Type[] parameterTypes) { return(tb.DefineProperty(name, attributes, callingConvention, returnType.AsType(), parameterTypes)); }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) throw new ArgumentNullException("names"); if (names.Length == 0) throw new ArgumentException(); Contract.EndContractBlock(); for (int i = 0; i < names.Length; i ++) if (names[i] == null) throw new ArgumentNullException("names"); if (m_inst != null) throw new InvalidOperationException(); m_inst = new GenericTypeParameterBuilder[names.Length]; for(int i = 0; i < names.Length; i ++) m_inst[i] = new GenericTypeParameterBuilder(new TypeBuilder(names[i], i, this)); return m_inst; }
private static Type SubstituteGenericArguments( Type type, Type[] argumentsToSubstitute, GenericTypeParameterBuilder[] substitutes) { if (type.IsGenericType) { Type[] genericArguments = type.GetGenericArguments(); type = type.GetGenericTypeDefinition(); for (int i = 0; i < genericArguments.Length; ++i) { int substitutionIndex = Array.IndexOf(argumentsToSubstitute, genericArguments[i]); if (substitutionIndex != -1) { genericArguments[i] = substitutes[substitutionIndex]; } } return type.MakeGenericType(genericArguments); } else { return type; } }
private static void BuildProperties(DynamicTypeInfo info, TypeBuilder typBuilder, List<FieldBuilder> fieldBuilders, GenericTypeParameterBuilder[] parameterBuilders) { for (int i = 0; i < info.PropertyNames.Count; i++) { //var propBuilder = typBuilder.DefineProperty( // info.PropertyNames[i], PropertyAttributes.None, parameterBuilders[i], Type.EmptyTypes); var propBuilder = typBuilder.DefineProperty( info.PropertyNames[i], PropertyAttributes.HasDefault, parameterBuilders[i], Type.EmptyTypes); // Build Get prop var getMethBuilder = typBuilder.DefineMethod( "get_" + info.PropertyNames[i], MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, parameterBuilders[i], Type.EmptyTypes); var generator = getMethBuilder.GetILGenerator(); generator.Emit(OpCodes.Ldarg_0); // load 'this' generator.Emit(OpCodes.Ldfld, fieldBuilders[i]); // load the field generator.Emit(OpCodes.Ret); propBuilder.SetGetMethod(getMethBuilder); // Build Set prop var setMethBuilder = typBuilder.DefineMethod( "set_" + info.PropertyNames[i], MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, typeof(void), new Type[] { fieldBuilders[i].FieldType }); generator = setMethBuilder.GetILGenerator(); generator.Emit(OpCodes.Ldarg_0); // load 'this' generator.Emit(OpCodes.Ldarg_1); // load value generator.Emit(OpCodes.Stfld, fieldBuilders[i]); generator.Emit(OpCodes.Ret); propBuilder.SetSetMethod(setMethBuilder); } }
public ParameterDeclaration(string name, TypeSpecifier constrainingType, Location location) : base(location) { this.name = name; this.constrainingType = constrainingType; builder = null; }
/// <summary>Tests whether the given object is an instance of <see langword="EventToken" /> and is equal to the current instance.</summary> /// <param name="o">The object to be compared with the current instance.</param> /// <returns>Returns <see langword="true" /> if <paramref name="o" /> is an instance of <see langword="EventToken" /> and equals the current instance; otherwise, <see langword="false" />.</returns> // Token: 0x06004D12 RID: 19730 RVA: 0x00116AD8 File Offset: 0x00114CD8 public override bool Equals(object o) { GenericTypeParameterBuilder genericTypeParameterBuilder = o as GenericTypeParameterBuilder; return(!(genericTypeParameterBuilder == null) && genericTypeParameterBuilder.m_type == this.m_type); }
public void SetConstraints (GenericTypeParameterBuilder type) { GenericParameterAttributes attr = GenericParameterAttributes.None; if (variance == Variance.Contravariant) attr |= GenericParameterAttributes.Contravariant; else if (variance == Variance.Covariant) attr |= GenericParameterAttributes.Covariant; if (gc != null) { if (gc.HasClassConstraint || gc.HasValueTypeConstraint) type.SetBaseTypeConstraint (gc.EffectiveBaseClass); attr |= gc.Attributes; type.SetInterfaceConstraints (gc.InterfaceConstraints); TypeManager.RegisterBuilder (type, gc.InterfaceConstraints); } type.SetGenericParameterAttributes (attr); }