private static JavaScriptConverter[] CreateConfigConverters() { List <JavaScriptConverter> list = new List <JavaScriptConverter>(); ScriptingJsonSerializationSection section = WebConfigFactory.GetJsonSerializationSection(); if (section != null) { foreach (Converter converter in section.Converters) { Type c = System.Web.Compilation.BuildManager.GetType(converter.Type, false); if (c == null) { throw new ArgumentException("类型不能为空"); } if (!typeof(JavaScriptConverter).IsAssignableFrom(c)) { throw new ArgumentException("类型没有继承自JavaScriptConverter"); } list.Add((JavaScriptConverter)TypeCreator.CreateInstance(c)); } } return(list.ToArray()); }
private static void SetValueToObject(ORMappingItem item, object graph, object data, object row, DataToObjectDeligations dod) { if (string.IsNullOrEmpty(item.SubClassPropertyName)) { SetMemberValueToObject(item.MemberInfo, graph, data); } else { if (graph != null) { MemberInfo mi = TypePropertiesWithNonPublicCacheQueue.Instance.GetPropertyInfoDirectly(graph.GetType(), item.PropertyName); if (mi == null) { mi = graph.GetType().GetField(item.PropertyName, BindingFlags.Instance | BindingFlags.Public); } if (mi != null) { object subGraph = GetMemberValueFromObject(mi, graph); if (subGraph == null) { bool useDefaultObject = true; if (dod != null) { MappingEventArgs args = new MappingEventArgs(); args.DataFieldName = item.DataFieldName; args.PropertyName = item.PropertyName; args.Graph = graph; subGraph = dod.OnCreateSubObjectDelegate(row, args, ref useDefaultObject); } if (useDefaultObject) { if (string.IsNullOrEmpty(item.SubClassTypeDescription) == false) { subGraph = TypeCreator.CreateInstance(item.SubClassTypeDescription); } else { subGraph = Activator.CreateInstance(GetRealType(mi), true); } } SetMemberValueToObject(item.MemberInfo, subGraph, data); SetMemberValueToObject(mi, graph, subGraph); } else { SetMemberValueToObject(item.MemberInfo, subGraph, data); } } } } }
public object CloneBusinessObject() { FormCommandState result = (FormCommandState)TypeCreator.CreateInstance(this.GetType()); if (Data != null) { if (Data is IClonableBusinessObject) { object data = this.Data; result.Data = ((IClonableBusinessObject)data).GenerateNewObject(); } else { BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream(1024)) { bf.Serialize(stream, this.Data); stream.Position = 0; result.Data = bf.Deserialize(stream); } } } return(result); }
/// <summary> /// /// </summary> /// <returns></returns> string ICallbackEventHandler.GetCallbackResult() { string argument = this._callbackArgument; this._callbackArgument = null; Dictionary <string, object> callInfo = JSONSerializerExecute.DeserializeObject(argument, typeof(Dictionary <string, object>)) as Dictionary <string, object>; string serverControlType = (string)callInfo["serverControlType"]; string originalControlID = (string)callInfo["originalControlID"]; Page page = WebUtility.GetCurrentPage(); Control control = null; if (originalControlID.IsNotEmpty()) { control = page.FindControl(originalControlID); } if (control == null) { control = (Control)TypeCreator.CreateInstance(serverControlType); control.ID = originalControlID; page.Controls.Add(control); if (TargetControlLoaded != null) { TargetControlLoaded(control); } } return(ScriptObjectBuilder.ExecuteCallbackMethod(control, callInfo)); }
// Del By Yuanyong 20080320 ///// <summary> ///// 获取指定连接的DbProviderFactory ///// </summary> ///// <param name="name">数据库逻辑名称</param> ///// <returns>DbProviderFactory实例</returns> //internal static DbProviderFactory GetDbProviderFactory(string name) //{ // ExceptionHelper.CheckStringIsNullOrEmpty(name, "name"); // return DbProviderFactories.GetFactory(GetDbProviderName(name)); //} /// <summary> /// 根据配置信息获得指定逻辑数据库的自定义事件参数类型 /// </summary> /// <param name="name">数据库逻辑名称</param> /// <returns>事件参数类型</returns> internal static DbEventArgs GetEventArgsType(string name) { ExceptionHelper.CheckStringIsNullOrEmpty(name, "name"); string typeName = GetConfiguration(name).EventArgsType; return(string.IsNullOrEmpty(typeName) ? null : (DbEventArgs)TypeCreator.CreateInstance(typeName)); }
public object CreateInstance(string assemblyName, string typeName, params object[] args) { Assembly a = Assembly.Load(assemblyName); Type type = a.GetType(typeName); return(TypeCreator.CreateInstance(type, args)); }
public IStateManager GetObject() { if (this._Obj == null) { this._Obj = (IStateManager)TypeCreator.CreateInstance(this._StateType); this._Obj.LoadViewState(this._State); } return(this._Obj); }
public static IModifyResult GetModifyResultByType(string type) { Type resultType = null; ExceptionHelper.FalseThrow(typeDict.TryGetValue(type, out resultType), "Can not find ModifyResult type: {0}", type); return((IModifyResult)TypeCreator.CreateInstance(resultType)); }
/// <summary> /// 反序列化 /// </summary> /// <param name="dictionary"></param> /// <param name="type"></param> /// <param name="serializer"></param> /// <returns></returns> public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer) { ProcessProgress progress = (ProcessProgress)TypeCreator.CreateInstance(typeof(ProcessProgress)); progress.MinStep = dictionary.GetValue("MinStep", progress.MinStep); progress.MaxStep = dictionary.GetValue("MaxStep", progress.MaxStep); progress.CurrentStep = dictionary.GetValue("CurrentStep", progress.CurrentStep); progress.StatusText = dictionary.GetValue("StatusText", progress.StatusText); return(progress); }
private static JavaScriptConverter[] CreateGlobalCacheConverters() { List <JavaScriptConverter> converters = new List <JavaScriptConverter>(); foreach (Type t in S_GlobalConverterTypesCache.Values) { converters.Add((JavaScriptConverter)TypeCreator.CreateInstance(t)); } //converters.Add(InternalDateTimeConverter.Instance); return(converters.ToArray()); }
/// <summary> /// /// </summary> /// <returns></returns> internal Dictionary <string, IPageModule> Create() { PageModuleElementCollection configModules = PageModules; Dictionary <string, IPageModule> modules = new Dictionary <string, IPageModule>(configModules.Count); foreach (PageModuleElement element in configModules) { IPageModule module = (IPageModule)TypeCreator.CreateInstance(element.Type); modules.Add(element.Name, module); } return(modules); }
public Validator GetValidator() { if (this._Validator == null) { NameValueCollection parameters = this.Parameters.ToNameValueCollection(); parameters["messageTemplate"] = this.MessageTemplate; parameters["tag"] = this.Tag; this._Validator = (Validator)TypeCreator.CreateInstance(this.TypeDescription, parameters); } return(this._Validator); }
/// <summary> /// 将Converter注册到上下文中 /// </summary> /// <param name="converterType"></param> public static void RegisterContextConverter(Type converterType) { converterType.NullCheck("converterType"); ObjectContextCache.Instance.ContainsKey(JSONSerializerExecute.ContextConverterTypeCacheKey).FalseThrow( "没有执行BeginRegisterContextConverters,不能执行RegisterContextConverter"); ExceptionHelper.FalseThrow(typeof(JavaScriptConverter).IsAssignableFrom(converterType), string.Format(Resources.DeluxeJsonResource.E_NotJavaScriptConverter, converterType.AssemblyQualifiedName)); Dictionary <Type, JavaScriptConverter> converters = (Dictionary <Type, JavaScriptConverter>)ObjectContextCache.Instance[JSONSerializerExecute.ContextConverterTypeCacheKey]; converters[converterType] = (JavaScriptConverter)TypeCreator.CreateInstance(converterType); }
public static ILogFormatter GetFormatter(LogConfigurationElement formatterElement) { if (formatterElement != null) { try { return((ILogFormatter)TypeCreator.CreateInstance(formatterElement.Type, formatterElement)); } catch (Exception ex) { throw new LogException("创建Formatter对象时出错:" + ex.Message, ex); } } else { return(null); } }
public static ClientSCBase CreateClientBaseObject(string schemaType) { schemaType.CheckStringIsNullOrEmpty("schemaType"); ClientSCBase result = null; Type targetType = null; if (SCObjectToClientHelper._SchemaToType.TryGetValue(schemaType, out targetType)) { result = (ClientSCBase)TypeCreator.CreateInstance(targetType, schemaType); } else { result = new ClientSCBase(schemaType); } return(result); }
private static List <JavaScriptConverter> GetGlobalConvertersInConfig() { List <JavaScriptConverter> list = S_GlobalConvertersInConfig; lock (S_GlobalConvertersInConfig) { ScriptingJsonSerializationSection section = GetJsonSerializationSection(); if (S_GlobalConverterSection != section) { list.Clear(); foreach (Converter converter in section.Converters) { Type c = System.Web.Compilation.BuildManager.GetType(converter.Type, false); if (c == null) { //沈峥调整,不抛出异常 //throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.DeluxeWebResource.E_UnknownType, new object[] { converter.Type })); System.Exception ex = new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.DeluxeJsonResource.E_UnknownType, new object[] { converter.Type })); ExceptionHelper.WriteToEventLog(ex, "JavaScriptConverter", EventLogEntryType.Warning); } else if (!typeof(JavaScriptConverter).IsAssignableFrom(c)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.DeluxeJsonResource.E_NotJavaScriptConverter, new object[] { c.Name })); } if (c != null) { list.Add((JavaScriptConverter)TypeCreator.CreateInstance(c)); } } S_GlobalConverterSection = section; } return(list); } }
/// <summary> /// Init HttpModule /// </summary> /// <param name="context"></param> protected virtual void Init(HttpApplication context) { _HttpModuleCollection = new Dictionary <string, IHttpModule>(); HttpModulesSection moduleSection = ConfigSectionFactory.GetHttpModulesSection(); foreach (HttpModuleAction moduleAction in moduleSection.Modules) { try { IHttpModule module = (IHttpModule)TypeCreator.CreateInstance(moduleAction.Type); this._HttpModuleCollection.Add(moduleAction.Name, module); module.Init(context); } catch (TypeLoadException ex) { ex.TryWriteAppLog(); } } }
private static IWfProcessDescriptor GetDefaultProcessDescriptor(string processKey) { string appName = "DefaultApplication"; string progName = "DefaultProgram"; WfProcessBuilderInfo builderInfo = GetBuilderInfo(processKey); IWfProcessDescriptor processDesp = null; if (builderInfo != null) { if (WfRuntime.ProcessContext.OriginalActivity != null) { appName = WfRuntime.ProcessContext.OriginalActivity.Process.Descriptor.ApplicationName; progName = WfRuntime.ProcessContext.OriginalActivity.Process.Descriptor.ProgramName; } WfProcessBuilderBase builder = (WfProcessBuilderBase)TypeCreator.CreateInstance(builderInfo.Builder.GetType(), appName, progName); processDesp = builder.Build(processKey, builderInfo.ProcessName); } return(processDesp); }
public object CreateInstance(string typeDesp, params object[] args) { return(TypeCreator.CreateInstance(typeDesp, args)); }
private static ILogFilter GetFilterFromConfig(LoggerFilterConfigurationElement element) { return((ILogFilter)TypeCreator.CreateInstance(element.Type, element)); }
private static FormattedTraceListenerBase GetListenerFromConfig(LogListenerElement element) { return((FormattedTraceListenerBase)TypeCreator.CreateInstance(element.Type, element)); //return ObjectBuilder.GetInstance<TraceListener>(element.TypeName); }
private static object DeserializeArrayObject(object[] input, Type type, int level) { object tempResult = null; if (typeof(Array).IsAssignableFrom(type)) { Type eltType = type.GetMethod("Get", new Type[1] { typeof(int) }).ReturnType; object[] objs = input; Array ins = Array.CreateInstance(eltType, objs.Length); for (int i = 0; i < objs.Length; i++) { ins.SetValue(DeserializeObject(objs[i], eltType), i); } tempResult = ins; } else if (typeof(ICollection <object>).IsAssignableFrom(type)) { object ins = TypeCreator.CreateInstance(type); ICollection <object> c = (ICollection <object>)ins; foreach (object o in input) { c.Add(DeserializeObject(o, type.GetGenericArguments()[0], level)); } tempResult = ins; } else if (typeof(IList).IsAssignableFrom(type)) { object ins = TypeCreator.CreateInstance(type); IList l = (IList)ins; MethodInfo mi = type.GetMethod("get_Item", new Type[1] { typeof(int) }); if (mi != null) { Type eltType = mi.ReturnType; foreach (object o in input) { l.Add(DeserializeObject(o, eltType, level)); } tempResult = ins; } } else if (typeof(ICollection).IsAssignableFrom(type)) { object ins = TypeCreator.CreateInstance(type); MethodInfo mi = type.GetMethod("get_Item", new Type[1] { typeof(int) }); if (mi != null) { Type eltType = mi.ReturnType; foreach (object o in input) { mi.Invoke(ins, new object[1] { DeserializeObject(o, eltType, level) }); } tempResult = ins; } } return(tempResult); }
/// <summary> /// /// </summary> /// <returns></returns> public virtual T CreateNewData() { return((T)TypeCreator.CreateInstance(typeof(T))); }
private static ILogFilter GetFilterFromConfig(LogConfigurationElement element) { return((ILogFilter)TypeCreator.CreateInstance(element.Type, element)); //return ObjectBuilder.GetInstance<LogFilter>(element.TypeName); }
private static FormattedTraceListenerBase GetListenerFromConfig(LoggerListenerConfigurationElement element) { return((FormattedTraceListenerBase)TypeCreator.CreateInstance(element.Type, element)); }
/// <summary> /// 建立对象的实例同时进行类型检查 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ctorParams"></param> /// <returns></returns> public T CreateInstance <T>(params object[] ctorParams) { return(TypeCreator.CreateInstance <T>(GetTypeInfo(), ctorParams)); }
public static void DescribeComponent(object instance, ScriptComponentDescriptor descriptor, IUrlResolutionService urlResolver, IControlResolver controlResolver) { // validate preconditions if (instance == null) { throw new ArgumentNullException("instance"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } if (urlResolver == null) { urlResolver = instance as IUrlResolutionService; } if (controlResolver == null) { controlResolver = instance as IControlResolver; } // describe properties // PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance); PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo prop in properties) { ScriptControlPropertyAttribute propAttr = null; ScriptControlEventAttribute eventAttr = null; string propertyName = prop.Name; System.ComponentModel.AttributeCollection attribs = new System.ComponentModel.AttributeCollection(Attribute.GetCustomAttributes(prop, false)); // Try getting a property attribute propAttr = (ScriptControlPropertyAttribute)attribs[typeof(ScriptControlPropertyAttribute)]; if (propAttr == null || !propAttr.IsScriptProperty) { // Try getting an event attribute eventAttr = (ScriptControlEventAttribute)attribs[typeof(ScriptControlEventAttribute)]; if (eventAttr == null || !eventAttr.IsScriptEvent) { continue; } } // attempt to rename the property/event ClientPropertyNameAttribute nameAttr = (ClientPropertyNameAttribute)attribs[typeof(ClientPropertyNameAttribute)]; if (nameAttr != null && !string.IsNullOrEmpty(nameAttr.PropertyName)) { propertyName = nameAttr.PropertyName; } // determine whether to serialize the value of a property. readOnly properties should always be serialized //bool serialize = true;// prop.ShouldSerializeValue(instance) || prop.IsReadOnly; //if (serialize) //{ // get the value of the property, skip if it is null Control c = null; object value = prop.GetValue(instance, new object[0] { }); if (value == null) { continue; } // convert and resolve the value if (eventAttr != null && prop.PropertyType != typeof(String)) { throw new InvalidOperationException("ScriptControlEventAttribute can only be applied to a property with a PropertyType of System.String."); } else { if (!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum) { if (prop.PropertyType == typeof(Color)) { value = ColorTranslator.ToHtml((Color)value); } else { // TODO: Determine if we should let ASP.NET AJAX handle this type of conversion, as it supports JSON serialization //TypeConverter conv = prop.Converter; //value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value); //if (prop.PropertyType == typeof(CssStyleCollection)) // value = (new CssStyleCollectionJSCoverter()).Serialize(value, new JavaScriptSerializer()); //if (prop.PropertyType == typeof(Style)) // value = (new CssStyleCollectionJSCoverter()).Serialize(((Style)value).GetStyleAttributes(null), new JavaScriptSerializer()); Type valueType = value.GetType(); JavaScriptConverterAttribute attr = (JavaScriptConverterAttribute)attribs[typeof(JavaScriptConverterAttribute)]; JavaScriptConverter converter = attr != null ? (JavaScriptConverter)TypeCreator.CreateInstance(attr.ConverterType) : JsonSerializerFactory.GetJavaScriptConverter(valueType); if (converter != null) { value = converter.Serialize(value, JsonSerializerFactory.GetJavaScriptSerializer()); } else { value = JsonHelper.PreSerializeObject(value); } //Dictionary<string, object> dict = value as Dictionary<string, object>; //if (dict != null && !dict.ContainsKey("__type")) // dict["__type"] = valueType.AssemblyQualifiedName; } } if (attribs[typeof(IDReferencePropertyAttribute)] != null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (attribs[typeof(UrlPropertyAttribute)] != null && urlResolver != null) { value = urlResolver.ResolveClientUrl((string)value); } } // add the value as an appropriate description if (eventAttr != null) { if (!string.IsNullOrEmpty((string)value)) { descriptor.AddEvent(propertyName, (string)value); } } else if (attribs[typeof(ElementReferenceAttribute)] != null) { if (c == null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (c != null) { value = c.ClientID; } descriptor.AddElementProperty(propertyName, (string)value); } else if (attribs[typeof(ComponentReferenceAttribute)] != null) { if (c == null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (c != null) { //ExtenderControlBase ex = c as ExtenderControlBase; //if (ex != null && ex.BehaviorID.Length > 0) // value = ex.BehaviorID; //else value = c.ClientID; } descriptor.AddComponentProperty(propertyName, (string)value); } else { if (c != null) { value = c.ClientID; } descriptor.AddProperty(propertyName, value); } } //} // determine if we should describe methods foreach (MethodInfo method in instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) { ScriptControlMethodAttribute methAttr = (ScriptControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod) { continue; } // We only need to support emitting the callback target and registering the WebForms.js script if there is at least one valid method Control control = instance as Control; if (control != null) { // Force WebForms.js control.Page.ClientScript.GetCallbackEventReference(control, null, null, null); // Add the callback target descriptor.AddProperty("_callbackTarget", control.UniqueID); } break; } }
protected virtual void ParseBuilders() { #region Parse <connectionString> if ((Builders != null) && (Builders.Count > 0)) { foreach (BuilderConfigurationElement elementBuilder in Builders) { ConnectionStringBuilderBase builder = (ConnectionStringBuilderBase)TypeCreator.CreateInstance(elementBuilder.Type); switch (elementBuilder.AttributeName) { case "connectionString": settings.ConnectionString = builder.BuildUp(settings.ConnectionString); break; case "name": settings.Name = builder.BuildUp(settings.Name); break; case "providerName": settings.ProviderName = builder.BuildUp(settings.ProviderName); break; } } } #endregion }
private void ParseSettingBuildersByPrefix(string prefix, ref ConnectionStringElement setting) { if ((Builders != null) && (Builders.Count > 0)) { foreach (BuilderConfigurationElement elementBuilder in Builders) { if ((elementBuilder.Name.StartsWith(prefix)) || (elementBuilder.Name.StartsWith(BothSectionPrefix))) { ConnectionStringBuilderBase builder = (ConnectionStringBuilderBase)TypeCreator.CreateInstance(elementBuilder.Type); switch (elementBuilder.AttributeName) { case "connectionString": setting.ConnectionString = builder.BuildUp(setting.ConnectionString); break; case "name": setting.Name = builder.BuildUp(setting.Name); break; case "providerName": setting.ProviderName = builder.BuildUp(setting.ProviderName); break; } } } } }
/// <summary> /// 建立对象的实例 /// </summary> /// <param name="ctorParams">创建实例的初始化参数</param> /// <returns>运用晚绑定方式动态创建一个实例</returns> public object CreateInstance(params object[] ctorParams) { return(TypeCreator.CreateInstance(Type, ctorParams)); }