本文整理汇总了C#中IDesignerSerializationManager.AddSerializationProvider方法的典型用法代码示例。如果您正苦于以下问题:C# IDesignerSerializationManager.AddSerializationProvider方法的具体用法?C# IDesignerSerializationManager.AddSerializationProvider怎么用?C# IDesignerSerializationManager.AddSerializationProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDesignerSerializationManager
的用法示例。
在下文中一共展示了IDesignerSerializationManager.AddSerializationProvider方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public override object Deserialize(IDesignerSerializationManager manager, object codeObject)
{
if ((manager == null) || (codeObject == null))
{
throw new ArgumentNullException((manager == null) ? "manager" : "codeObject");
}
object obj2 = null;
using (CodeDomSerializerBase.TraceScope("RootCodeDomSerializer::Deserialize"))
{
if (!(codeObject is CodeTypeDeclaration))
{
throw new ArgumentException(System.Design.SR.GetString("SerializerBadElementType", new object[] { typeof(CodeTypeDeclaration).FullName }));
}
bool caseInsensitive = false;
CodeDomProvider service = manager.GetService(typeof(CodeDomProvider)) as CodeDomProvider;
if (service != null)
{
caseInsensitive = (service.LanguageOptions & LanguageOptions.CaseInsensitive) != LanguageOptions.None;
}
CodeTypeDeclaration declaration = (CodeTypeDeclaration) codeObject;
CodeTypeReference reference = null;
Type type = null;
foreach (CodeTypeReference reference2 in declaration.BaseTypes)
{
Type type2 = manager.GetType(CodeDomSerializerBase.GetTypeNameFromCodeTypeReference(manager, reference2));
if ((type2 != null) && !type2.IsInterface)
{
reference = reference2;
type = type2;
break;
}
}
if (type == null)
{
Exception exception = new SerializationException(System.Design.SR.GetString("SerializerTypeNotFound", new object[] { reference.BaseType })) {
HelpLink = "SerializerTypeNotFound"
};
throw exception;
}
if (type.IsAbstract)
{
Exception exception2 = new SerializationException(System.Design.SR.GetString("SerializerTypeAbstract", new object[] { type.FullName })) {
HelpLink = "SerializerTypeAbstract"
};
throw exception2;
}
ResolveNameEventHandler handler = new ResolveNameEventHandler(this.OnResolveName);
manager.ResolveName += handler;
if (!(manager is DesignerSerializationManager))
{
manager.AddSerializationProvider(new CodeDomSerializationProvider());
}
obj2 = manager.CreateInstance(type, null, declaration.Name, true);
this.nameTable = new HybridDictionary(declaration.Members.Count, caseInsensitive);
this.statementTable = new HybridDictionary(declaration.Members.Count, caseInsensitive);
this.initMethod = null;
RootContext context = new RootContext(new CodeThisReferenceExpression(), obj2);
manager.Context.Push(context);
try
{
foreach (CodeTypeMember member in declaration.Members)
{
if (member is CodeMemberField)
{
if (string.Compare(member.Name, declaration.Name, caseInsensitive, CultureInfo.InvariantCulture) != 0)
{
this.nameTable[member.Name] = member;
}
}
else if ((this.initMethod == null) && (member is CodeMemberMethod))
{
CodeMemberMethod method = (CodeMemberMethod) member;
if ((string.Compare(method.Name, this.InitMethodName, caseInsensitive, CultureInfo.InvariantCulture) == 0) && (method.Parameters.Count == 0))
{
this.initMethod = method;
}
}
}
if (this.initMethod != null)
{
foreach (CodeStatement statement in this.initMethod.Statements)
{
CodeVariableDeclarationStatement statement2 = statement as CodeVariableDeclarationStatement;
if (statement2 != null)
{
this.nameTable[statement2.Name] = statement;
}
}
}
if (this.nameTable[declaration.Name] != null)
{
this.nameTable[declaration.Name] = obj2;
}
if (this.initMethod != null)
{
this.FillStatementTable(this.initMethod, declaration.Name);
}
PropertyDescriptor descriptor = manager.Properties["SupportsStatementGeneration"];
if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool) descriptor.GetValue(manager)))
{
//.........这里部分代码省略.........
示例2: Serialize
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
// Add the provider to supply the ComponentCodeSerializer, Primitives..., etc
manager.AddSerializationProvider (_provider);
RootContext rootContext = new RootContext (new CodeThisReferenceExpression (), value);
manager.Context.Push (rootContext);
// Initialize code map
if (_codeMap != null)
_codeMap = new CodeMap (value.GetType (), manager.GetName (value));
_codeMap.Clear ();
CodeStatementCollection statements = null;
CodeDomSerializer serializer = null;
foreach (object component in ((IComponent) value).Site.Container.Components) {
if (!Object.ReferenceEquals (component, value)) {
serializer = base.GetSerializer (manager, component) as CodeDomSerializer; // ComponentCodeDomSerializer
if (serializer != null) {
// add an expressioncontext to inform the component that we want it fully serialized (it is in context)
ExpressionContext context = new ExpressionContext (null, null, null, component);
manager.Context.Push (context);
_codeMap.AddField (new CodeMemberField (value.GetType (), manager.GetName (value)));
statements = (CodeStatementCollection) serializer.Serialize (manager, component);
manager.Context.Pop ();
// XXX: what if there are more than one objects constructed by the serializer?
// this will only add the first one on the statements list.
CodeStatement ctorStatement = ExtractCtorStatement (statements);
if (ctorStatement != null)
_codeMap.AddPreInitStatement (ctorStatement);
_codeMap.AddInitStatements (statements);
}
}
}
// Serializer root component
//
statements = new CodeStatementCollection ();
base.SerializeProperties (manager, statements, value, new Attribute[0]);
base.SerializeEvents (manager, statements, value, new Attribute[0]);
_codeMap.AddInitStatements (statements);
manager.Context.Pop ();
return _codeMap.GenerateClass ();
}
示例3: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value)
{
if ((manager == null) || (value == null))
{
throw new ArgumentNullException((manager == null) ? "manager" : "value");
}
CodeTypeDeclaration declaration = new CodeTypeDeclaration(manager.GetName(value));
RootContext context = new RootContext(new CodeThisReferenceExpression(), value);
using (CodeDomSerializerBase.TraceScope("RootCodeDomSerializer::Serialize"))
{
declaration.BaseTypes.Add(value.GetType());
this.containerRequired = false;
manager.Context.Push(context);
manager.Context.Push(this);
manager.Context.Push(declaration);
if (!(manager is DesignerSerializationManager))
{
manager.AddSerializationProvider(new CodeDomSerializationProvider());
}
try
{
if (value is IComponent)
{
ISite site = ((IComponent) value).Site;
if (site == null)
{
return declaration;
}
ICollection components = site.Container.Components;
StatementContext context2 = new StatementContext();
context2.StatementCollection.Populate(components);
manager.Context.Push(context2);
try
{
foreach (IComponent component in components)
{
if ((component != value) && !base.IsSerialized(manager, component))
{
if (base.GetSerializer(manager, component) != null)
{
base.SerializeToExpression(manager, component);
}
else
{
manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { component.GetType().FullName }));
}
}
}
manager.Context.Push(value);
try
{
if ((base.GetSerializer(manager, value) != null) && !base.IsSerialized(manager, value))
{
base.SerializeToExpression(manager, value);
}
else
{
manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { value.GetType().FullName }));
}
}
finally
{
manager.Context.Pop();
}
}
finally
{
manager.Context.Pop();
}
CodeMemberMethod method = new CodeMemberMethod {
Name = this.InitMethodName,
Attributes = MemberAttributes.Private
};
declaration.Members.Add(method);
ArrayList elements = new ArrayList();
foreach (object obj2 in components)
{
if (obj2 != value)
{
elements.Add(context2.StatementCollection[obj2]);
}
}
if (context2.StatementCollection[value] != null)
{
elements.Add(context2.StatementCollection[value]);
}
if (this.ContainerRequired)
{
this.SerializeContainerDeclaration(manager, method.Statements);
}
this.SerializeElementsToStatements(elements, method.Statements);
}
return declaration;
}
finally
{
manager.Context.Pop();
manager.Context.Pop();
manager.Context.Pop();
}
//.........这里部分代码省略.........