/// <summary> /// Initialize the handler and generates the needed Javascript code /// </summary> /// <param name="bridge">The <see cref="BridgeController" /> object requesting initialization</param> public virtual void Initialize(BridgeController bridge) { var builder = new StringBuilder(); builder.Append(ClassBridge.GenerateNameSpace(GenericType)); builder.Append(ClassBridge.GenerateProxyClass(Identification, true)); lock (Lock) { if (Methods != null) { if (Fields != null) { foreach (var field in Fields) { builder.Append(ClassBridge.GenerateProxyField(Identification, field)); } } foreach (var method in Methods) { builder.Append(ClassBridge.GenerateProxyMethod(Identification, method.Key, method.Value)); } } } OnPushJavascript(new FireJavascriptEventArgs(builder.ToString(), bridge)); }
/// <summary> /// Initialize the handler and generates the needed Javascript code /// </summary> /// <param name="bridge">The <see cref="BridgeController" /> object requesting initialization</param> public virtual void Initialize(BridgeController bridge) { var builder = new StringBuilder(); builder.Append(ClassBridge.GenerateNameSpace(GenericType)); builder.Append(ClassBridge.GenerateProxyClass(Identification, false)); lock (Lock) { if (Fields != null) { foreach (var field in Fields) { builder.Append(ClassBridge.GenerateProxyField(Identification, field)); } } if (Methods != null) { if (Properties != null) { foreach (var property in Properties) { var get = property.GetGetMethod(); if ((get != null) && !Methods.ContainsKey(get)) { get = null; } var set = property.GetSetMethod(); if ((set != null) && !Methods.ContainsKey(set)) { set = null; } builder.Append(ClassBridge.GenerateProxyProperty(Identification, property, get, set)); } } foreach ( var method in Methods.Where( pair => (Events == null) || !Events.Any( info => (pair.Key == info.GetAddMethod()) || (pair.Key == info.GetRemoveMethod())))) { builder.Append(ClassBridge.GenerateProxyMethod(Identification, method.Key, method.Value)); } } if (Events != null) { foreach (var info in Events) { var isStatic = info.GetAddMethod().IsStatic || info.GetRemoveMethod().IsStatic; builder.Append(ClassBridge.GenerateProxyField(Identification, info.Name, isStatic, true, new object[0])); builder.Append(ClassBridge.GenerateProxyEventMethods(Identification, info, isStatic)); } } } foreach (var instance in Instances.Where(pair => pair.Key != null).ToArray()) { var instanceId = GlobalPool.GetInstanceId(instance.Key); if (instanceId != null) { builder.AppendLine(ClassBridge.GenerateInstanceChange(Identification, instanceId, false)); foreach (var variableName in instance.Value.Where(s => !string.IsNullOrWhiteSpace(s))) { builder.AppendLine(ClassBridge.GenerateInstanceVariable(Identification, instanceId, variableName)); } } } OnPushJavascript(new FireJavascriptEventArgs(builder.ToString(), bridge)); lock (Lock) { if (SubEnumerations != null) { foreach (var subEnum in SubEnumerations) { subEnum.Initialize(bridge); } } if (SubClasses != null) { foreach (var subClass in SubClasses) { subClass.Initialize(bridge); } } } }