📄 codedomdesignerserializationmanager.cs
字号:
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.0.3705.288
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using ICSharpCode.Core.Services;
using System;
using System.CodeDom;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Windows.Forms.Design;
namespace ICSharpCode.SharpDevelop.FormDesigner.Services
{
/// <summary>
/// CodeDom serialization service for designers
/// </summary>
/// <remarks>
/// created by - Niv
/// created on - 12/10/2002 03:02:27
/// </remarks>
public class CodeDomDesignerSerializetionManager : IDesignerSerializationManager, IServiceContainer
{
protected ContextStack context = null;
protected Hashtable nameToObject = new Hashtable();
protected Hashtable objectToName = new Hashtable();
protected PropertyDescriptorCollection props = PropertyDescriptorCollection.Empty;
protected ArrayList providers = new ArrayList();
protected IDesignerHost host = null;
private ServiceContainer services = null;
/// <summary>
/// TODO - add property description
/// </summary>
/// <remarks>
/// Interface property from IDesignerSerializationManager
/// - read only
///
/// </remarks>
public virtual ContextStack Context {
get { return context;}
}
/// <summary>
/// TODO - add property description
/// </summary>
/// <remarks>
/// Interface property from IDesignerSerializationManager
/// - read only
///
/// </remarks>
/// TODO ???????
public virtual PropertyDescriptorCollection Properties {
get {
return props;
}
}
/// <summary>
/// Default constructor - initializes all fields to default values
/// </summary>
public CodeDomDesignerSerializetionManager(IDesignerHost myHost)
{
host = myHost;
context = new ContextStack();
services = new ServiceContainer(host);
services.AddService(typeof(IDesignerSerializationManager), this);
services.AddService(typeof(IServiceContainer), this);
}
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='instance'>TODO - add parameter description</param>
/// <param name='name'>TODO - add parameter description</param>
public virtual void SetName(object instance, string name)
{
//System.Console.WriteLine("Setting name {0} for {1}",name,instance);
object oldName = objectToName[instance];
if (name == oldName as string) {
return;
}
object oldInstance = nameToObject[name];
if ((oldInstance != null) & (oldInstance != instance)) {
throw new Exception("An object with name already exists.");
}
if (oldName != null) {
nameToObject.Remove(name);
}
objectToName[instance] = name;
nameToObject[name] = instance;
Component c = instance as Component;
if (c != null && c.Site != null) {
c.Site.Name = name;
}
}
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='errorInformation'>TODO - add parameter description</param>
public virtual void ReportError(object errorInformation)
{
// IUIService uiService = (IUIService)host.GetService(typeof(IUIService));
// uiService.ShowError("Error : " + errorInformation.ToString());
}
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='provider'>TODO - add parameter description</param>
public virtual void RemoveSerializationProvider(IDesignerSerializationProvider provider)
{
//System.Console.WriteLine("removing serilization provider {0}",provider);
providers.Remove(provider);
}
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='typeName'>TODO - add parameter description</param>
public virtual System.Type GetType(string typeName)
{
///TODO use a TypeRessoulotionService if available
return host.GetType(typeName);
}
/*
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='objectType'>TODO - add parameter description</param>
/// <param name='serializerType'>TODO - add parameter description</param>
///
public virtual object GetSerializer(Type objectType, Type serializerType)
{
//System.Console.WriteLine("Looking for a serializer for {0}",objectType);
if (objectType == null)
return null;
object serializer = null;
foreach (IDesignerSerializationProvider provider in providers)
{
serializer = provider.GetSerializer(this,null,objectType, serializerType);
if (serializer != null)
return serializer;
}
AttributeCollection attributes = TypeDescriptor.GetAttributes(objectType);
foreach(Attribute att in attributes)
{
DesignerSerializerAttribute serAtt = att as DesignerSerializerAttribute;
if (serAtt != null)
{
if (serAtt.SerializerBaseTypeName.StartsWith( serializerType.FullName))
{
Type type = GetType(serAtt.SerializerTypeName);
return Activator.CreateInstance(type);
}
}
}
return GetSerializer(objectType.BaseType,serializerType);
}*/
public virtual object GetSerializer(Type objectType, Type serializerType)
{
object serializer = GetSerializerFromType(objectType, serializerType);
if (serializer != null) {
return serializer;
}
return GetSerializerFromProvider(objectType, serializerType);
}
object GetSerializerFromType(Type objectType, Type serializerType)
{
if (objectType == null) {
return null;
}
AttributeCollection attributes = TypeDescriptor.GetAttributes(objectType);
foreach (Attribute att in attributes) {
DesignerSerializerAttribute serAtt = att as DesignerSerializerAttribute;
if (serAtt != null) {
if (serAtt.SerializerBaseTypeName.StartsWith(serializerType.FullName)) {
Type type = GetType(serAtt.SerializerTypeName);
return LicenseManager.CreateWithContext(type, new DesigntimeLicenseContext()); //Activator.CreateInstance(type);
}
}
}
return GetSerializerFromType(objectType.BaseType,serializerType);
}
object GetSerializerFromProvider(Type objectType, Type serializerType)
{
if (objectType == null) {
return null;
}
object serializer = null;
foreach (IDesignerSerializationProvider provider in providers) {
serializer = provider.GetSerializer(this,null,objectType, serializerType);
if (serializer != null) {
return serializer;
}
}
return GetSerializerFromProvider(objectType.BaseType, serializerType);
}
/// <summary>
/// TODO - add method description
/// </summary>
/// <remarks>
/// Interface method from IDesignerSerializationManager
///
/// </remarks>
/// <param name='objectType'>TODO - add parameter description</param>
/// <param name='serializerType'>TODO - add parameter description</param>
public virtual CodeDomSerializer GetRootSerializer(Type objectType)
{
if (objectType == null) {
return null;
}
Type serializerType = typeof(CodeDomSerializer);
AttributeCollection attributes = TypeDescriptor.GetAttributes(objectType);
foreach (Attribute att in attributes) {
RootDesignerSerializerAttribute serAtt = att as RootDesignerSerializerAttribute;
if (serAtt != null) {
if (serAtt.SerializerBaseTypeName.StartsWith(serializerType.FullName)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -