public List GetAttrNames(ICallerContext context) { FieldIdDict attrs = new FieldIdDict(__dict__); OldClass.RecurseAttrHierarchy(this.__class__, attrs); return(List.Make(attrs)); }
/// <summary> /// All the types are guaranteed to have a ReflectedTypes, and so can be exposed to the user. /// Use GetNamesInScope() if the types need not have to be exposed to the user, as that is more performant. /// </summary> internal FieldIdDict GetTypeMap() { // Have we already promoted the Types to ReflectedTypes? if (typeMap != null) { return(typeMap); } // We lazily convert the Types to ReflectedTypes FieldIdDict newTypeMap = new FieldIdDict(); foreach (KeyValuePair <string, object> entry in rawTypeMap) { object value = entry.Value; if (value is Type) { value = Ops.GetDynamicTypeFromType((Type)value); } newTypeMap[SymbolTable.StringToId(entry.Key)] = value; } typeMap = newTypeMap; rawTypeMap = null; return(typeMap); }
public SirenField FindField(ushort id) { SirenField outProperty; FieldIdDict.TryGetValue(id, out outProperty); return(outProperty); }
private static IAttributesDictionary GetInitializedDict(ISuperDynamicObject self) { IAttributesDictionary d = self.GetDict(); if (d == null) { d = new FieldIdDict(); self.SetDict(d); } return(d); }
private static OldClass DefaultExceptionCreator(string name, object baseType) { Tuple bases = (baseType == null) ? Tuple.MakeTuple() : Tuple.MakeTuple(baseType); FieldIdDict dict = new FieldIdDict(); dict[SymbolTable.Module] = "exceptions"; OldClass oc = new OldClass(name, bases, dict); oc.SetAttr(DefaultContext.Default, SymbolTable.Init, exceptionInitMethod); oc.SetAttr(DefaultContext.Default, SymbolTable.GetItem, exceptionGetItemMethod); oc.SetAttr(DefaultContext.Default, SymbolTable.String, exceptionStrMethod); return(oc); }
private static PythonModule MakePythonModule(PythonModule importer, string name, ReflectedType type) { type.Initialize(); FieldIdDict dict = new FieldIdDict(); //!!! need a GetAttrIds foreach (string attrName in type.GetAttrNames(DefaultContext.Default)) { dict[SymbolTable.StringToId(attrName)] = type.GetAttr(DefaultContext.Default, null, SymbolTable.StringToId(attrName)); } PythonModule ret = new PythonModule(name, dict, importer.SystemState); importer.SystemState.modules[name] = ret; return(ret); }
public bool Initialize() { if (Type.IsEnum) { return(true); } //get methods SerializeMethodInfo = Type.GetMethod("Serialize", BindingFlags.Public | BindingFlags.Instance); DeserializeMethodInfo = Type.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.Instance); RegisterMethodInfo = Type.GetMethod("Register", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); if (RegisterMethodInfo != null && !Type.ContainsGenericParameters) { RegisterMethodInfo.Invoke(null, null); } //get properties uint index = 0; ushort id = GetBasePropertyCount(); var properties = Type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (var propertyInfo in properties) { var attrs = propertyInfo.GetCustomAttributes(typeof(SirenFieldAttribute), false); if (attrs.Length > 0) { SirenFieldAttribute propertyAttribute = attrs[0] as SirenFieldAttribute; if (propertyAttribute != null) { SirenField property = new SirenField(this, propertyInfo, propertyAttribute, index++, id++); Fields.Add(property); FieldIdDict.Add(property.Id, property); FieldNameDict.Add(property.Name, property); } } } if (Fields.Count == 0) { if (Type.BaseType == typeof(object) || Type.BaseType.IsValueType) { return(false); } } if (!Type.IsValueType && Type.BaseType != typeof(object) && !Type.BaseType.IsValueType) { BaseType = SirenMachine.GetClass(Type.BaseType); if (BaseType != null) { //add base properties foreach (var sirenProperty in BaseType.FieldIdDict) { FieldIdDict.Add(sirenProperty.Key, sirenProperty.Value); } foreach (var sirenProperty in BaseType.FieldNameDict) { FieldNameDict.Add(sirenProperty.Key, sirenProperty.Value); } } } return(true); }
public override void Initialize() { if (!initialized) { base.Initialize(); bool isOps = OpsReflectedType.OpsTypeToType.ContainsKey(type); lock (this) { if (initialized) return; dict = new FieldIdDict(); // if we're an ops type don't add our members to ourself // (this happens if the user gets ahold of FloatOps and then // trys to call a method on it). if (isOps) { initialized = true; return; } MemberInfo[] defaultMembers = type.GetDefaultMembers(); BindingFlags bf = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; foreach (MethodInfo mi in type.GetMethods(bf)) { AddReflectedMethod(mi, defaultMembers); } foreach (FieldInfo fi in type.GetFields(bf)) { AddReflectedField(fi); } foreach (PropertyInfo pi in type.GetProperties(bf)) { AddReflectedProperty(pi, defaultMembers); } foreach (EventInfo pi in type.GetEvents()) { AddReflectedEvent(pi); } foreach (Type ty in type.GetNestedTypes(bf)) { AddNestedType(ty); } AddEnumOperators(); AddOps(); AddPythonProtocolMethods(); CreateInitCode(); AddProtocolWrappers(); AddDocumentation(); AddInheritedStaticMethods(defaultMembers, bf); if (!dict.ContainsKey(SymbolTable.Dict)) { dict[SymbolTable.Dict] = new DictWrapper(this); } initialized = true; AddModule(); dict = new ProxyDictionary(dict.SymbolAttributes); } } }
internal static PythonModule MakePythonModule(SystemState state, string name, ReflectedType type) { type.Initialize(); FieldIdDict dict = new FieldIdDict(); foreach (string attrName in type.GetAttrNames(DefaultContext.Default)) { dict[SymbolTable.StringToId(attrName)] = type.GetAttr(DefaultContext.Default, null, SymbolTable.StringToId(attrName)); } PythonModule ret = new PythonModule(name, dict, state); state.modules[name] = ret; return ret; }
internal static OldClass DefaultExceptionCreator(string name, string module, object baseType) { Tuple bases = ObjectToTuple(baseType); FieldIdDict dict = new FieldIdDict(); dict[SymbolTable.Module] = module; OldClass oc = new OldClass(name, bases, dict); oc.SetAttr(DefaultContext.Default, SymbolTable.Init, exceptionInitMethod); oc.SetAttr(DefaultContext.Default, SymbolTable.GetItem, exceptionGetItemMethod); oc.SetAttr(DefaultContext.Default, SymbolTable.String, exceptionStrMethod); oc.SetAttr(DefaultContext.Default, SymbolTable.GetState, exceptionGetStateMethod); return oc; }
private static IAttributesDictionary GetInitializedDict(ISuperDynamicObject self) { IAttributesDictionary d = self.GetDict(); if (d == null) { d = new FieldIdDict(); if (!self.SetDict(d)) return null; } return d; }
public List GetAttrNames(ICallerContext context) { FieldIdDict attrs = new FieldIdDict(__dict__); OldClass.RecurseAttrHierarchy(this.__class__, attrs); return List.Make(attrs); }