示例#1
0
 internal override bool TryDeleteValue(CodeContext /*!*/ context, object instance, PythonType owner)
 {
     Assert.NotNull(context, owner);
     throw ReadOnlyException(DynamicHelpers.GetPythonTypeFromType(Info.DeclaringType));
 }
示例#2
0
 public void __set__(CodeContext context, object instance, object value)
 {
     TrySetValue(context, instance, DynamicHelpers.GetPythonType(instance), value);
 }
示例#3
0
 public string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(String.Format("<method '{0}' of '{1}' objects>",
                          Template.Name,
                          DynamicHelpers.GetPythonTypeFromType(DeclaringType).Name));
 }
示例#4
0
        internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value)
        {
            if (instance == null)
            {
                return(false);
            }

            if (!(instance is IPythonObject sdo))
            {
                throw PythonOps.TypeError("__class__ assignment: only for user defined types");
            }

            if (!(value is PythonType dt))
            {
                throw PythonOps.TypeError("__class__ must be set to new-style class, not '{0}' object", DynamicHelpers.GetPythonType(value).Name);
            }

            if (dt.UnderlyingSystemType != DynamicHelpers.GetPythonType(instance).UnderlyingSystemType)
            {
                throw PythonOps.TypeErrorForIncompatibleObjectLayout("__class__ assignment", DynamicHelpers.GetPythonType(instance), dt.UnderlyingSystemType);
            }

            sdo.SetPythonType(dt);
            return(true);
        }
示例#5
0
 public static ReflectedEvent.BoundEvent MakeBoundEvent(ReflectedEvent eventObj, object instance, Type type)
 {
     return(new ReflectedEvent.BoundEvent(eventObj, instance, DynamicHelpers.GetPythonTypeFromType(type)));
 }
示例#6
0
 public string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(string.Format("<property# {0} on {1}>",
                          __name__,
                          DynamicHelpers.GetPythonTypeFromType(DeclaringType).Name));
 }
示例#7
0
 public void __set__(CodeContext context, object instance, object value)
 {
     // TODO: Throw?  currently we have a test that verifies we never throw when this is called directly.
     TrySetValue(context, instance, DynamicHelpers.GetPythonType(instance), value);
 }