/// <summary> /// Intializes a new instance of the <see cref="GeneratedProperty"/> class (for overrides). /// </summary> /// <param name="engine">The code generation engine.</param> /// <param name="property">Inherited property to override.</param> /// <param name="implementation">Implementation strategy to use (may be null).</param> internal GeneratedProperty( CodeGenEngine engine, InheritedProperty property, IPropertyImplementation implementation) : base(engine) { // check parameters if (property == null) { throw new ArgumentNullException("property"); } mName = property.Name; mKind = PropertyKind.Override; mType = property.Type; mGetAccessorMethod = engine.AddOverride(property.GetAccessor); mSetAccessorMethod = engine.AddOverride(property.SetAccessor); mImplementation = implementation; if (mImplementation != null) { mImplementation.Declare(engine, this); } // do not allow changes to overridden properties // (signature must match the signature of the inherited property) Freeze(); }
/// <summary> /// Intializes a new instance of the <see cref="GeneratedProperty"/> class. /// </summary> /// <param name="engine">The code generation engine.</param> /// <param name="kind">Kind of property to generate.</param> /// <param name="type">Type of the property.</param> /// <param name="name">Name of the property (may be null).</param> /// <param name="implementation">Implementation strategy to use (may be null).</param> internal GeneratedProperty( CodeGenEngine engine, PropertyKind kind, Type type, string name, IPropertyImplementation implementation) : base(engine) { // check parameters if (type == null) { throw new ArgumentNullException("type"); } // ensure that the specified type is public and all nested types are public, too // => otherwise the dynamically created assembly is not able to access it CodeGenHelpers.CheckTypeIsTotallyPublic(type); mName = name; mKind = kind; mType = type; if (mName == null || mName.Trim().Length == 0) { mName = "X" + Guid.NewGuid().ToString("N"); } // declare the 'get' accessor method mGetAccessorMethod = engine.AddMethod(kind.ToMethodKind(), "get_" + name, type, Type.EmptyTypes, Visibility.Public); mGetAccessorMethod.AdditionalMethodAttributes = MethodAttributes.SpecialName | MethodAttributes.HideBySig; // declare the 'set' accessor method mSetAccessorMethod = engine.AddMethod(kind.ToMethodKind(), "set_" + name, typeof(void), new Type[] { type }, Visibility.Public); mSetAccessorMethod.AdditionalMethodAttributes = MethodAttributes.SpecialName | MethodAttributes.HideBySig; mImplementation = implementation; if (mImplementation != null) { mImplementation.Declare(engine, this); } }