本文整理汇总了C#中System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager.ReportError方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowMarkupSerializationManager.ReportError方法的具体用法?C# WorkflowMarkupSerializationManager.ReportError怎么用?C# WorkflowMarkupSerializationManager.ReportError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager
的用法示例。
在下文中一共展示了WorkflowMarkupSerializationManager.ReportError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeContents
internal void SerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj, XmlWriter writer, bool dictionaryKey)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (obj == null)
throw new ArgumentNullException("obj");
if (writer == null)
throw new ArgumentNullException("writer");
WorkflowMarkupSerializer serializer = null;
try
{
//Now get the serializer to persist the properties, if the serializer is not found then we dont serialize the properties
serializer = serializationManager.GetSerializer(obj.GetType(), typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
}
catch (Exception e)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerThrewException, obj.GetType().FullName, e.Message), e));
return;
}
if (serializer == null)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNotAvailableForSerialize, obj.GetType().FullName)));
return;
}
try
{
serializer.OnBeforeSerialize(serializationManager, obj);
}
catch (Exception e)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerThrewException, obj.GetType().FullName, e.Message), e));
return;
}
Hashtable allProperties = new Hashtable();
ArrayList complexProperties = new ArrayList();
IDictionary<DependencyProperty, object> dependencyProperties = null;
List<PropertyInfo> properties = new List<PropertyInfo>();
List<EventInfo> events = new List<EventInfo>();
Hashtable designTimeTypeNames = null;
// Serialize the extended properties for primitive types also
if (obj.GetType().IsPrimitive || obj.GetType() == typeof(string) || obj.GetType() == typeof(decimal) ||
obj.GetType() == typeof(DateTime) || obj.GetType() == typeof(TimeSpan) || obj.GetType().IsEnum ||
obj.GetType() == typeof(Guid))
{
if (obj.GetType() == typeof(char) || obj.GetType() == typeof(byte) ||
obj.GetType() == typeof(System.Int16) || obj.GetType() == typeof(decimal) ||
obj.GetType() == typeof(DateTime) || obj.GetType() == typeof(TimeSpan) ||
obj.GetType().IsEnum || obj.GetType() == typeof(Guid))
{
//These non CLS-compliant are not supported in the XmlWriter
if ((obj.GetType() != typeof(char)) || (char)obj != '\0')
{
//These non CLS-compliant are not supported in the XmlReader
string stringValue = String.Empty;
if (obj.GetType() == typeof(DateTime))
{
stringValue = ((DateTime)obj).ToString("o", CultureInfo.InvariantCulture);
}
else
{
TypeConverter typeConverter = TypeDescriptor.GetConverter(obj.GetType());
if (typeConverter != null && typeConverter.CanConvertTo(typeof(string)))
stringValue = typeConverter.ConvertTo(null, CultureInfo.InvariantCulture, obj, typeof(string)) as string;
else
stringValue = Convert.ToString(obj, CultureInfo.InvariantCulture);
}
writer.WriteValue(stringValue);
}
}
else if (obj.GetType() == typeof(string))
{
string attribValue = obj as string;
attribValue = attribValue.Replace('\0', ' ');
if (!(attribValue.StartsWith("{", StringComparison.Ordinal) && attribValue.EndsWith("}", StringComparison.Ordinal)))
writer.WriteValue(attribValue);
else
writer.WriteValue("{}" + attribValue);
}
else
{
writer.WriteValue(obj);
}
// For Key properties, we don;t want to get the extended properties
if (!dictionaryKey)
properties.AddRange(serializationManager.GetExtendedProperties(obj));
}
else
{
// Serialize properties
//We first get all the properties, once we have them all, we start distinguishing between
//simple and complex properties, the reason for that is XmlWriter needs to write attributes
//.........这里部分代码省略.........
示例2: ContentProperty
public ContentProperty(WorkflowMarkupSerializationManager serializationManager, WorkflowMarkupSerializer parentObjectSerializer, object parentObject)
{
this.serializationManager = serializationManager;
this.parentObjectSerializer = parentObjectSerializer;
this.parentObject = parentObject;
this.contentProperty = GetContentProperty(this.serializationManager, this.parentObject);
if (this.contentProperty != null)
{
this.contentPropertySerializer = this.serializationManager.GetSerializer(this.contentProperty.PropertyType, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (this.contentPropertySerializer != null)
{
try
{
XmlReader reader = this.serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
object contentPropertyValue = null;
if (reader == null)
{
contentPropertyValue = this.contentProperty.GetValue(this.parentObject, null);
}
else if (!this.contentProperty.PropertyType.IsValueType &&
!this.contentProperty.PropertyType.IsPrimitive &&
this.contentProperty.PropertyType != typeof(string) &&
!IsMarkupExtension(this.contentProperty.PropertyType) &&
this.contentProperty.CanWrite)
{
WorkflowMarkupSerializer serializer = serializationManager.GetSerializer(this.contentProperty.PropertyType, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (serializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, this.contentProperty.PropertyType.FullName), reader));
return;
}
try
{
contentPropertyValue = serializer.CreateInstance(serializationManager, this.contentProperty.PropertyType);
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerCreateInstanceFailed, this.contentProperty.PropertyType.FullName, e.Message), reader));
return;
}
this.contentProperty.SetValue(this.parentObject, contentPropertyValue, null);
}
if (contentPropertyValue != null)
{
if (reader != null)
{
this.contentPropertySerializer.OnBeforeDeserialize(this.serializationManager, contentPropertyValue);
this.contentPropertySerializer.OnBeforeDeserializeContents(this.serializationManager, contentPropertyValue);
}
}
}
catch (Exception e)
{
this.serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerThrewException, this.parentObject.GetType(), e.Message), e));
}
}
else
{
this.serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNotAvailableForSerialize, this.contentProperty.PropertyType.FullName)));
}
}
}
示例3: GetContentProperty
private PropertyInfo GetContentProperty(WorkflowMarkupSerializationManager serializationManager, object parentObject)
{
PropertyInfo contentProperty = null;
string contentPropertyName = String.Empty;
object[] contentPropertyAttributes = parentObject.GetType().GetCustomAttributes(typeof(ContentPropertyAttribute), true);
if (contentPropertyAttributes != null && contentPropertyAttributes.Length > 0)
contentPropertyName = ((ContentPropertyAttribute)contentPropertyAttributes[0]).Name;
if (!String.IsNullOrEmpty(contentPropertyName))
{
contentProperty = parentObject.GetType().GetProperty(contentPropertyName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public);
if (contentProperty == null)
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_ContentPropertyCouldNotBeFound, contentPropertyName, parentObject.GetType().FullName)));
}
return contentProperty;
}
示例4: DeserializeFromCompactFormat
// This function parses the data bind syntax (markup extension in xaml terms). The syntax is:
// {ObjectTypeName arg1, arg2, name3=arg3, name4=arg4, ...}
// For example, an ActivityBind would have the syntax as the following:
// {wcm:ActivityBind ID=Workflow1, Path=error1}
// We also support positional arguments, so the above expression is equivalent to
// {wcm:ActivityBind Workflow1, Path=error1} or {wcm:ActivityBind Workflow1, error1}
// Notice that the object must have the appropriate constructor to support positional arugments.
// There should be no constructors that takes the same number of arugments, regardless of their types.
internal object DeserializeFromCompactFormat(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, string attrValue)
{
if (attrValue.Length == 0 || !attrValue.StartsWith("{", StringComparison.Ordinal) || !attrValue.EndsWith("}", StringComparison.Ordinal))
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.IncorrectSyntax, attrValue), reader));
return null;
}
// check for correct format: typename name=value name=value
int argIndex = attrValue.IndexOf(" ", StringComparison.Ordinal);
if (argIndex == -1)
argIndex = attrValue.IndexOf("}", StringComparison.Ordinal);
string typename = attrValue.Substring(1, argIndex - 1).Trim();
string arguments = attrValue.Substring(argIndex + 1, attrValue.Length - (argIndex + 1));
// lookup the type of the target
string prefix = String.Empty;
int typeIndex = typename.IndexOf(":", StringComparison.Ordinal);
if (typeIndex >= 0)
{
prefix = typename.Substring(0, typeIndex);
typename = typename.Substring(typeIndex + 1);
}
Type type = serializationManager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
if (type == null && !typename.EndsWith("Extension", StringComparison.Ordinal))
{
typename = typename + "Extension";
type = serializationManager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
}
if (type == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_MarkupSerializerTypeNotResolved, typename), reader));
return null;
}
// Break apart the argument string.
object obj = null;
Dictionary<string, object> namedArgs = new Dictionary<string, object>();
ArrayList argTokens = null;
try
{
argTokens = TokenizeAttributes(serializationManager, arguments, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1);
}
catch (Exception error)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_MarkupExtensionDeserializeFailed, attrValue, error.Message), reader));
return null;
}
if (argTokens != null)
{
// Process the positional arugments and find the correct constructor to call.
ArrayList positionalArgs = new ArrayList();
bool firstEqual = true;
for (int i = 0; i < argTokens.Count; i++)
{
char token = (argTokens[i] is char) ? (char)argTokens[i] : '\0';
if (token == '=')
{
if (positionalArgs.Count > 0 && firstEqual)
positionalArgs.RemoveAt(positionalArgs.Count - 1);
firstEqual = false;
namedArgs.Add(argTokens[i - 1] as string, argTokens[i + 1] as string);
i++;
}
if (token == ',')
continue;
if (namedArgs.Count == 0)
positionalArgs.Add(argTokens[i] as string);
}
if (positionalArgs.Count > 0)
{
ConstructorInfo matchConstructor = null;
ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
ParameterInfo[] matchParameters = null;
foreach (ConstructorInfo ctor in constructors)
{
ParameterInfo[] parameters = ctor.GetParameters();
if (parameters.Length == positionalArgs.Count)
{
matchConstructor = ctor;
matchParameters = parameters;
break;
}
}
if (matchConstructor != null)
{
for (int i = 0; i < positionalArgs.Count; i++)
{
//.........这里部分代码省略.........
示例5: DeserializeContents
private void DeserializeContents(WorkflowMarkupSerializationManager serializationManager, object obj, XmlReader reader)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (obj == null)
throw new ArgumentNullException("obj");
if (reader == null)
throw new ArgumentNullException("reader");
if (reader.NodeType != XmlNodeType.Element)
return;
// get the serializer
WorkflowMarkupSerializer serializer = serializationManager.GetSerializer(obj.GetType(), typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (serializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, obj.GetType().FullName), reader));
return;
}
try
{
serializer.OnBeforeDeserialize(serializationManager, obj);
}
catch (Exception e)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerThrewException, obj.GetType().FullName, e.Message), e));
return;
}
bool isEmptyElement = reader.IsEmptyElement;
string elementNamespace = reader.NamespaceURI;
List<PropertyInfo> props = new List<PropertyInfo>();
List<EventInfo> events = new List<EventInfo>();
// Add the extended properties for primitive types
if (obj.GetType().IsPrimitive || obj.GetType() == typeof(string) || obj.GetType() == typeof(decimal) ||
obj.GetType().IsEnum || obj.GetType() == typeof(DateTime) || obj.GetType() == typeof(TimeSpan) ||
obj.GetType() == typeof(Guid))
{
props.AddRange(serializationManager.GetExtendedProperties(obj));
}
else
{
try
{
props.AddRange(serializer.GetProperties(serializationManager, obj));
props.AddRange(serializationManager.GetExtendedProperties(obj));
events.AddRange(serializer.GetEvents(serializationManager, obj));
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerThrewException, obj.GetType(), e.Message), e, reader));
return;
}
}
//First we try to deserialize simple properties
if (reader.HasAttributes)
{
while (reader.MoveToNextAttribute())
{
//
if (reader.LocalName.Equals("xmlns", StringComparison.Ordinal) || reader.Prefix.Equals("xmlns", StringComparison.Ordinal))
continue;
//
XmlQualifiedName xmlQualifiedName = new XmlQualifiedName(reader.LocalName, reader.LookupNamespace(reader.Prefix));
if (xmlQualifiedName.Namespace.Equals(StandardXomlKeys.Definitions_XmlNs, StringComparison.Ordinal) &&
!IsMarkupExtension(xmlQualifiedName) &&
!ExtendedPropertyInfo.IsExtendedProperty(serializationManager, props, xmlQualifiedName) &&
!ExtendedPropertyInfo.IsExtendedProperty(serializationManager, xmlQualifiedName))
{
serializationManager.FireFoundDefTag(new WorkflowMarkupElementEventArgs(reader));
continue;
}
//For simple properties we assume that if . indicates
string propName = XmlConvert.DecodeName(reader.LocalName);
string propVal = reader.Value;
DependencyProperty dependencyProperty = ResolveDependencyProperty(serializationManager, reader, obj, propName);
if (dependencyProperty != null)
{
serializationManager.Context.Push(dependencyProperty);
try
{
if (dependencyProperty.IsEvent)
DeserializeEvent(serializationManager, reader, obj, propVal);
else
DeserializeSimpleProperty(serializationManager, reader, obj, propVal);
}
finally
{
Debug.Assert(serializationManager.Context.Current == dependencyProperty, "Serializer did not remove an object it pushed into stack.");
serializationManager.Context.Pop();
}
}
else
{
PropertyInfo property = WorkflowMarkupSerializer.LookupProperty(props, propName);
if (property != null)
//.........这里部分代码省略.........
示例6: ProcessDefTag
internal static void ProcessDefTag(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, Activity activity, bool newSegment, string fileName)
{
System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("System.Workflow.ComponentModel.StringResources", typeof(System.Workflow.ComponentModel.ActivityBind).Assembly);
if (reader.NodeType == XmlNodeType.Attribute)
{
switch (reader.LocalName)
{
case StandardXomlKeys.Definitions_Class_LocalName:
activity.SetValue(WorkflowMarkupSerializer.XClassProperty, reader.Value);
break;
default:
serializationManager.ReportError(new WorkflowMarkupSerializationException(string.Format(CultureInfo.CurrentCulture, resourceManager.GetString("UnknownDefinitionTag"), new object[] { StandardXomlKeys.Definitions_XmlNs_Prefix, reader.LocalName, StandardXomlKeys.Definitions_XmlNs }), (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1));
break;
}
return;
}
bool exitLoop = false;
bool isEmptyElement = reader.IsEmptyElement;
int initialDepth = reader.Depth;
do
{
XmlNodeType currNodeType = reader.NodeType;
switch (currNodeType)
{
case XmlNodeType.Element:
{
/*
if (!reader.LocalName.Equals(localName))
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(string.Format(resourceManager.GetString("DefnTagsCannotBeNested"), "def", localName, reader.LocalName), reader.LineNumber, reader.LinePosition));
return;
}
*/
switch (reader.LocalName)
{
case StandardXomlKeys.Definitions_Code_LocalName:
break;
case "Constructor":
default:
serializationManager.ReportError(new WorkflowMarkupSerializationException(string.Format(CultureInfo.CurrentCulture, resourceManager.GetString("UnknownDefinitionTag"), StandardXomlKeys.Definitions_XmlNs_Prefix, reader.LocalName, StandardXomlKeys.Definitions_XmlNs), (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1));
return;
}
// if an empty element do a Reader then exit
if (isEmptyElement)
exitLoop = true;
break;
}
case XmlNodeType.EndElement:
{
//reader.Read();
if (reader.Depth == initialDepth)
exitLoop = true;
break;
}
case XmlNodeType.CDATA:
case XmlNodeType.Text:
{
//
int lineNumber = (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1;
int linePosition = (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1;
CodeSnippetTypeMember codeSegment = new CodeSnippetTypeMember(reader.Value);
codeSegment.LinePragma = new CodeLinePragma(fileName, Math.Max(lineNumber - 1, 1));
codeSegment.UserData[UserDataKeys.CodeSegment_New] = newSegment;
codeSegment.UserData[UserDataKeys.CodeSegment_ColumnNumber] = linePosition + reader.Name.Length - 1;
CodeTypeMemberCollection codeSegments = activity.GetValue(WorkflowMarkupSerializer.XCodeProperty) as CodeTypeMemberCollection;
if (codeSegments == null)
{
codeSegments = new CodeTypeMemberCollection();
activity.SetValue(WorkflowMarkupSerializer.XCodeProperty, codeSegments);
}
codeSegments.Add(codeSegment);
//}
/*else
{
serializationManager.ReportError( new WorkflowMarkupSerializationException(
string.Format(resourceManager.GetString("IllegalCDataTextScoping"),
"def",
reader.LocalName,
(currNodeType == XmlNodeType.CDATA ? resourceManager.GetString("CDATASection") : resourceManager.GetString("TextSection"))),
reader.LineNumber,
reader.LinePosition)
);
}
*/
break;
}
}
}
while (!exitLoop && reader.Read());
}
示例7: DeserializeSimpleMember
private void DeserializeSimpleMember(WorkflowMarkupSerializationManager serializationManager, Type memberType, XmlReader reader, object obj, string value)
{
//Get the serializer for the member type
WorkflowMarkupSerializer memberSerializer = serializationManager.GetSerializer(memberType, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (memberSerializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, memberType.FullName), reader));
return;
}
//Try to deserialize
object memberValue = null;
try
{
memberValue = memberSerializer.DeserializeFromString(serializationManager, memberType, value);
memberValue = GetValueFromMarkupExtension(serializationManager, memberValue);
DependencyProperty dependencyProperty = serializationManager.Context.Current as DependencyProperty;
if (dependencyProperty != null)
{
//Get the serializer for the property type
WorkflowMarkupSerializer objSerializer = serializationManager.GetSerializer(obj.GetType(), typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (objSerializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, obj.GetType().FullName), reader));
return;
}
objSerializer.SetDependencyPropertyValue(serializationManager, obj, dependencyProperty, memberValue);
}
else
{
EventInfo evt = serializationManager.Context.Current as EventInfo;
if (evt != null)
{
try
{
WorkflowMarkupSerializationHelpers.SetEventHandlerName(obj, evt.Name, memberValue as string);
}
catch (Exception e)
{
while (e is TargetInvocationException && e.InnerException != null)
e = e.InnerException;
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerMemberSetFailed, new object[] { reader.LocalName, reader.Value, reader.LocalName, obj.GetType().FullName, e.Message }), e, reader));
}
}
else
{
PropertyInfo property = serializationManager.Context.Current as PropertyInfo;
if (property != null)
{
try
{
if (memberValue is string && TypeProvider.IsAssignable(typeof(Type), property.PropertyType))
{
string key = property.ReflectedType.FullName + "." + property.Name;
Helpers.SetDesignTimeTypeName(obj, key, memberValue as string);
}
else if (property.CanWrite)
{
property.SetValue(obj, memberValue, null);
}
else if (typeof(ICollection<string>).IsAssignableFrom(memberValue.GetType()))
{
ICollection<string> propVal = property.GetValue(obj, null) as ICollection<string>;
ICollection<string> deserializedValue = memberValue as ICollection<string>;
if (propVal != null && deserializedValue != null)
{
foreach (string content in deserializedValue)
propVal.Add(content);
}
}
}
catch (Exception e)
{
while (e is TargetInvocationException && e.InnerException != null)
e = e.InnerException;
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerMemberSetFailed, new object[] { reader.LocalName, reader.Value, reader.LocalName, obj.GetType().FullName, e.Message }), e, reader));
}
}
}
}
}
catch (Exception e)
{
while (e is TargetInvocationException && e.InnerException != null)
e = e.InnerException;
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerMemberSetFailed, new object[] { reader.LocalName, reader.Value, reader.LocalName, obj.GetType().FullName, e.Message }), e, reader));
}
}
示例8: DeserializeCompoundProperty
private void DeserializeCompoundProperty(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, object obj)
{
string propertyName = reader.LocalName;
bool isReadOnly = false;
DependencyProperty dependencyProperty = serializationManager.Context.Current as DependencyProperty;
PropertyInfo property = serializationManager.Context.Current as PropertyInfo;
if (dependencyProperty != null)
isReadOnly = ((dependencyProperty.DefaultMetadata.Options & DependencyPropertyOptions.ReadOnly) == DependencyPropertyOptions.ReadOnly);
else if (property != null)
isReadOnly = !property.CanWrite;
else
{
Debug.Assert(false);
return;
}
//Deserialize compound properties
if (isReadOnly)
{
object propValue = null;
if (dependencyProperty != null && obj is DependencyObject)
{
if (((DependencyObject)obj).IsBindingSet(dependencyProperty))
propValue = ((DependencyObject)obj).GetBinding(dependencyProperty);
else if (!dependencyProperty.IsEvent)
propValue = ((DependencyObject)obj).GetValue(dependencyProperty);
else
propValue = ((DependencyObject)obj).GetHandler(dependencyProperty);
}
else if (property != null)
propValue = property.CanRead ? property.GetValue(obj, null) : null;
if (propValue != null)
DeserializeContents(serializationManager, propValue, reader);
else
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerReadOnlyPropertyAndValueIsNull, propertyName, obj.GetType().FullName), reader));
}
else if (!reader.IsEmptyElement)
{
//
if (reader.HasAttributes)
{
//We allow xmlns on the complex property nodes
while (reader.MoveToNextAttribute())
{
//
if (string.Equals(reader.LocalName, "xmlns", StringComparison.Ordinal) || string.Equals(reader.Prefix, "xmlns", StringComparison.Ordinal))
continue;
else
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerAttributesFoundInComplexProperty, propertyName, obj.GetType().FullName), reader));
}
}
do
{
if (!reader.Read())
return;
} while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.Element && reader.NodeType != XmlNodeType.ProcessingInstruction && reader.NodeType != XmlNodeType.EndElement);
if (reader.NodeType == XmlNodeType.Text)
{
this.DeserializeSimpleProperty(serializationManager, reader, obj, reader.Value);
}
else
{
AdvanceReader(reader);
if (reader.NodeType == XmlNodeType.Element)
{
object propValue = DeserializeObject(serializationManager, reader);
if (propValue != null)
{
propValue = GetValueFromMarkupExtension(serializationManager, propValue);
if (propValue != null && propValue.GetType() == typeof(string) && ((string)propValue).StartsWith("{}", StringComparison.Ordinal))
propValue = ((string)propValue).Substring(2);
if (dependencyProperty != null)
{
//Get the serializer for the property type
WorkflowMarkupSerializer objSerializer = serializationManager.GetSerializer(obj.GetType(), typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (objSerializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, obj.GetType().FullName), reader));
return;
}
try
{
objSerializer.SetDependencyPropertyValue(serializationManager, obj, dependencyProperty, propValue);
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerThrewException, obj.GetType().FullName, e.Message), e, reader));
return;
}
}
else if (property != null)
{
try
//.........这里部分代码省略.........
示例9: DeserializeSimpleProperty
private void DeserializeSimpleProperty(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, object obj, string value)
{
Type propertyType = null;
bool isReadOnly = false;
DependencyProperty dependencyProperty = serializationManager.Context.Current as DependencyProperty;
PropertyInfo property = serializationManager.Context.Current as PropertyInfo;
if (dependencyProperty != null)
{
propertyType = dependencyProperty.PropertyType;
isReadOnly = ((dependencyProperty.DefaultMetadata.Options & DependencyPropertyOptions.ReadOnly) == DependencyPropertyOptions.ReadOnly);
}
else if (property != null)
{
propertyType = property.PropertyType;
isReadOnly = !property.CanWrite;
}
else
{
Debug.Assert(false);
return;
}
if (isReadOnly && !typeof(ICollection<string>).IsAssignableFrom(propertyType))
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerPrimitivePropertyReadOnly, new object[] { property.Name, property.Name, obj.GetType().FullName }), reader));
return;
}
DeserializeSimpleMember(serializationManager, propertyType, reader, obj, value);
}
示例10: SetDependencyPropertyValue
private void SetDependencyPropertyValue(WorkflowMarkupSerializationManager serializationManager, object obj, DependencyProperty dependencyProperty, object value)
{
if (dependencyProperty == null)
throw new ArgumentNullException("dependencyProperty");
if (obj == null)
throw new ArgumentNullException("obj");
DependencyObject dependencyObject = obj as DependencyObject;
if (dependencyObject == null)
throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");
if (dependencyProperty.IsEvent)
{
if (value is ActivityBind)
dependencyObject.SetBinding(dependencyProperty, value as ActivityBind);
else if (dependencyProperty.IsAttached)
{
MethodInfo methodInfo = dependencyProperty.OwnerType.GetMethod("Add" + dependencyProperty.Name + "Handler", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
if (methodInfo != null)
{
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters == null || parameters.Length != 2 || parameters[0].ParameterType != typeof(object) || parameters[1].ParameterType != typeof(object))
methodInfo = null;
}
if (methodInfo != null)
WorkflowMarkupSerializationHelpers.SetEventHandlerName(dependencyObject, dependencyProperty.Name, value as string);
else
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_MissingAddHandler, dependencyProperty.Name, dependencyProperty.OwnerType.FullName)));
}
else
WorkflowMarkupSerializationHelpers.SetEventHandlerName(dependencyObject, dependencyProperty.Name, value as string);
}
else
{
if (value is ActivityBind)
dependencyObject.SetBinding(dependencyProperty, value as ActivityBind);
else if (value is string && TypeProvider.IsAssignable(typeof(Type), dependencyProperty.PropertyType))
Helpers.SetDesignTimeTypeName(obj, dependencyProperty, value as string);
else if (dependencyProperty.IsAttached)
{
MethodInfo methodInfo = dependencyProperty.OwnerType.GetMethod("Set" + dependencyProperty.Name, BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
if (methodInfo != null)
{
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters == null || parameters.Length != 2 || parameters[0].ParameterType != typeof(object) || parameters[1].ParameterType != typeof(object))
methodInfo = null;
}
if (methodInfo != null)
methodInfo.Invoke(null, new object[] { dependencyObject, value });
else
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_MissingSetAccessor, dependencyProperty.Name, dependencyProperty.OwnerType.FullName)));
}
else
{
List<PropertyInfo> pis = new List<PropertyInfo>();
pis.AddRange(GetProperties(serializationManager, obj));
//The following condition is workaround for the partner team as they depend on the dependencyObject.SetValue being called
//for non assignable property values
PropertyInfo pi = LookupProperty(pis, dependencyProperty.Name);
if (pi != null &&
(value == null || pi.PropertyType.IsAssignableFrom(value.GetType())))
{
if (pi.CanWrite)
{
pi.SetValue(obj, value, null);
}
else if (typeof(ICollection<string>).IsAssignableFrom(value.GetType()))
{
ICollection<string> propVal = pi.GetValue(obj, null) as ICollection<string>;
ICollection<string> deserializedValue = value as ICollection<string>;
if (propVal != null && deserializedValue != null)
{
foreach (string content in deserializedValue)
propVal.Add(content);
}
}
}
else
{
dependencyObject.SetValue(dependencyProperty, value);
}
}
}
}
示例11: CreateInstance
private object CreateInstance(WorkflowMarkupSerializationManager serializationManager, XmlQualifiedName xmlQualifiedName, XmlReader reader)
{
object obj = null;
// resolve the type
Type type = null;
try
{
type = serializationManager.GetType(xmlQualifiedName);
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolvedWithInnerError, new object[] { GetClrFullName(serializationManager, xmlQualifiedName), e.Message }), e, reader));
return null;
}
if (type == null && !xmlQualifiedName.Name.EndsWith("Extension", StringComparison.Ordinal))
{
string typename = xmlQualifiedName.Name + "Extension";
try
{
type = serializationManager.GetType(new XmlQualifiedName(typename, xmlQualifiedName.Namespace));
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolvedWithInnerError, new object[] { GetClrFullName(serializationManager, xmlQualifiedName), e.Message }), e, reader));
return null;
}
}
if (type == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolved, new object[] { GetClrFullName(serializationManager, xmlQualifiedName) }), reader));
return null;
}
if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal) || type == typeof(DateTime) ||
type == typeof(TimeSpan) || type.IsEnum || type == typeof(Guid))
{
try
{
string stringValue = reader.ReadString();
if (type == typeof(DateTime))
{
obj = DateTime.Parse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
}
else if (type.IsPrimitive || type == typeof(decimal) || type == typeof(TimeSpan) || type.IsEnum || type == typeof(Guid))
{
//These non CLS-compliant are not supported in the XmlReader
TypeConverter typeConverter = TypeDescriptor.GetConverter(type);
if (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
obj = typeConverter.ConvertFrom(null, CultureInfo.InvariantCulture, stringValue);
else if (typeof(IConvertible).IsAssignableFrom(type))
obj = Convert.ChangeType(stringValue, type, CultureInfo.InvariantCulture);
}
else
{
obj = stringValue;
}
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerCreateInstanceFailed, e.Message), reader));
return null;
}
}
else
{
// get the serializer
WorkflowMarkupSerializer serializer = serializationManager.GetSerializer(type, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (serializer == null)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, type.FullName), reader));
return null;
}
// create an instance
try
{
obj = serializer.CreateInstance(serializationManager, type);
}
catch (Exception e)
{
serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerCreateInstanceFailed, type.FullName, e.Message), reader));
return null;
}
}
return obj;
}
示例12: GetDependencyProperties
//
private IDictionary<DependencyProperty, object> GetDependencyProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (obj == null)
throw new ArgumentNullException("obj");
List<PropertyInfo> pis = new List<PropertyInfo>();
pis.AddRange(GetProperties(serializationManager, obj));
List<EventInfo> eis = new List<EventInfo>();
eis.AddRange(GetEvents(serializationManager, obj));
Dictionary<DependencyProperty, object> dependencyProperties = new Dictionary<DependencyProperty, object>();
DependencyObject dependencyObject = obj as DependencyObject;
if (dependencyObject != null)
{
foreach (DependencyProperty dependencyProperty in dependencyObject.MetaDependencyProperties)
{
Attribute[] visibilityAttrs = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
if (visibilityAttrs.Length > 0 && ((DesignerSerializationVisibilityAttribute)visibilityAttrs[0]).Visibility == DesignerSerializationVisibility.Hidden)
continue;
//If the dependency property is readonly and we have not marked it with DesignerSerializationVisibility.Content attribute the we should not
//serialize it
if ((dependencyProperty.DefaultMetadata.Options & DependencyPropertyOptions.ReadOnly) == DependencyPropertyOptions.ReadOnly)
{
object[] serializationVisibilityAttribute = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
if (serializationVisibilityAttribute == null ||
serializationVisibilityAttribute.Length == 0 ||
((DesignerSerializationVisibilityAttribute)serializationVisibilityAttribute[0]).Visibility != DesignerSerializationVisibility.Content)
{
continue;
}
}
object obj1 = null;
if (!dependencyProperty.IsAttached && !dependencyProperty.DefaultMetadata.IsMetaProperty)
{
if (dependencyProperty.IsEvent)
obj1 = LookupEvent(eis, dependencyProperty.Name);
else
obj1 = LookupProperty(pis, dependencyProperty.Name);
if (obj1 == null)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_MissingCLRProperty, dependencyProperty.Name, obj.GetType().FullName)));
continue;
}
}
if (dependencyObject.IsBindingSet(dependencyProperty))
{
dependencyProperties.Add(dependencyProperty, dependencyObject.GetBinding(dependencyProperty));
}
else if (!dependencyProperty.IsEvent)
{
object propValue = null;
propValue = dependencyObject.GetValue(dependencyProperty);
if (!dependencyProperty.IsAttached && !dependencyProperty.DefaultMetadata.IsMetaProperty)
{
PropertyInfo propertyInfo = obj1 as PropertyInfo;
// if the propertyValue is assignable to the type in of the .net property then call the .net property's getter also
// else add the keep the value that we got
if (propValue != null && propertyInfo.PropertyType.IsAssignableFrom(propValue.GetType()))
propValue = (obj1 as PropertyInfo).GetValue(dependencyObject, null);
}
dependencyProperties.Add(dependencyProperty, propValue);
}
else
{
dependencyProperties.Add(dependencyProperty, dependencyObject.GetHandler(dependencyProperty));
}
}
foreach (DependencyProperty dependencyProperty in dependencyObject.DependencyPropertyValues.Keys)
{
Attribute[] visibilityAttrs = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
if (visibilityAttrs.Length > 0 && ((DesignerSerializationVisibilityAttribute)visibilityAttrs[0]).Visibility == DesignerSerializationVisibility.Hidden)
continue;
if (!dependencyProperty.DefaultMetadata.IsMetaProperty && dependencyProperty.IsAttached && VerifyAttachedPropertyConditions(dependencyProperty))
dependencyProperties.Add(dependencyProperty, dependencyObject.GetValue(dependencyProperty));
}
}
return dependencyProperties;
}
示例13: SerializeToString
protected internal sealed override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;
if (writer == null)
throw new ArgumentNullException("writer");
if (value == null)
throw new ArgumentNullException("value");
writer.WriteString(MarkupExtensionSerializer.CompactFormatStart);
string prefix = String.Empty;
XmlQualifiedName qualifiedName = serializationManager.GetXmlQualifiedName(value.GetType(), out prefix);
writer.WriteQualifiedName(qualifiedName.Name, qualifiedName.Namespace);
int index = 0;
Dictionary<string, string> constructorArguments = null;
InstanceDescriptor instanceDescriptor = this.GetInstanceDescriptor(serializationManager, value);
if (instanceDescriptor != null)
{
ConstructorInfo ctorInfo = instanceDescriptor.MemberInfo as ConstructorInfo;
if (ctorInfo != null)
{
ParameterInfo[] parameters = ctorInfo.GetParameters();
if (parameters != null && parameters.Length == instanceDescriptor.Arguments.Count)
{
int i = 0;
foreach (object argValue in instanceDescriptor.Arguments)
{
if (constructorArguments == null)
constructorArguments = new Dictionary<string, string>();
//
if (argValue == null)
continue;
constructorArguments.Add(parameters[i].Name, parameters[i++].Name);
if (index++ > 0)
writer.WriteString(MarkupExtensionSerializer.CompactFormatPropertySeperator);
else
writer.WriteString(MarkupExtensionSerializer.CompactFormatTypeSeperator);
if (argValue.GetType() == typeof(string))
{
writer.WriteString(CreateEscapedValue(argValue as string));
}
else if (argValue is System.Type)
{
Type argType = argValue as Type;
if (argType.Assembly != null)
{
string typePrefix = String.Empty;
XmlQualifiedName typeQualifiedName = serializationManager.GetXmlQualifiedName(argType, out typePrefix);
writer.WriteQualifiedName(XmlConvert.EncodeName(typeQualifiedName.Name), typeQualifiedName.Namespace);
}
else
{
writer.WriteString(argType.FullName);
}
}
else
{
string stringValue = base.SerializeToString(serializationManager, argValue);
if (stringValue != null)
writer.WriteString(stringValue);
}
}
}
}
}
List<PropertyInfo> properties = new List<PropertyInfo>();
properties.AddRange(GetProperties(serializationManager, value));
properties.AddRange(serializationManager.GetExtendedProperties(value));
foreach (PropertyInfo serializableProperty in properties)
{
if (Helpers.GetSerializationVisibility(serializableProperty) != DesignerSerializationVisibility.Hidden && serializableProperty.CanRead && serializableProperty.GetValue(value, null) != null)
{
WorkflowMarkupSerializer propSerializer = serializationManager.GetSerializer(serializableProperty.PropertyType, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
if (propSerializer == null)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNotAvailable, serializableProperty.PropertyType.FullName)));
continue;
}
if (constructorArguments != null)
{
object[] attributes = serializableProperty.GetCustomAttributes(typeof(ConstructorArgumentAttribute), false);
if (attributes.Length > 0 && constructorArguments.ContainsKey((attributes[0] as ConstructorArgumentAttribute).ArgumentName))
// Skip this property, it has already been represented by a constructor parameter
continue;
}
//Get the property serializer so that we can convert the bind object to string
serializationManager.Context.Push(serializableProperty);
try
{
object propValue = serializableProperty.GetValue(value, null);
if (propSerializer.ShouldSerializeValue(serializationManager, propValue))
{
//We do not allow nested bind syntax
//.........这里部分代码省略.........
示例14: CreateInstance
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (type == null)
throw new ArgumentNullException("type");
object designer = null;
IDesignerHost host = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost;
XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
if (host != null && reader != null)
{
//Find the associated activity
string associatedActivityName = String.Empty;
while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal));
if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue())
associatedActivityName = reader.Value;
reader.MoveToElement();
if (!String.IsNullOrEmpty(associatedActivityName))
{
CompositeActivityDesigner parentDesigner = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner;
if (parentDesigner == null)
{
Activity activity = host.RootComponent as Activity;
if (activity != null && !associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
{
foreach (IComponent component in host.Container.Components)
{
activity = component as Activity;
if (activity != null && associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
break;
}
}
if (activity != null)
designer = host.GetDesigner(activity);
}
else
{
CompositeActivity compositeActivity = parentDesigner.Activity as CompositeActivity;
if (compositeActivity != null)
{
Activity matchingActivity = null;
foreach (Activity activity in compositeActivity.Activities)
{
if (associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
{
matchingActivity = activity;
break;
}
}
if (matchingActivity != null)
designer = host.GetDesigner(matchingActivity);
}
}
if (designer == null)
serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationActivityNotFound, reader.LocalName, associatedActivityName, "Name"));
}
else
{
serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationAssociatedActivityNotFound, reader.LocalName, "Name"));
}
}
return designer;
}
示例15: CreateInstance
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
{
Activity activity3;
if (serializationManager == null)
{
throw new ArgumentNullException("serializationManager");
}
if (type == null)
{
throw new ArgumentNullException("type");
}
object obj2 = null;
IDesignerHost service = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost;
XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
if ((service == null) || (reader == null))
{
return obj2;
}
string str = string.Empty;
while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal))
{
}
if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue())
{
str = reader.Value;
}
reader.MoveToElement();
if (string.IsNullOrEmpty(str))
{
serializationManager.ReportError(SR.GetString("Error_LayoutSerializationAssociatedActivityNotFound", new object[] { reader.LocalName, "Name" }));
return obj2;
}
CompositeActivityDesigner designer = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner;
if (designer != null)
{
CompositeActivity activity2 = designer.Activity as CompositeActivity;
if (activity2 == null)
{
goto Label_01D0;
}
activity3 = null;
foreach (Activity activity4 in activity2.Activities)
{
if (str.Equals(activity4.Name, StringComparison.Ordinal))
{
activity3 = activity4;
break;
}
}
}
else
{
Activity rootComponent = service.RootComponent as Activity;
if ((rootComponent != null) && !str.Equals(rootComponent.Name, StringComparison.Ordinal))
{
foreach (IComponent component in service.Container.Components)
{
rootComponent = component as Activity;
if ((rootComponent != null) && str.Equals(rootComponent.Name, StringComparison.Ordinal))
{
break;
}
}
}
if (rootComponent != null)
{
obj2 = service.GetDesigner(rootComponent);
}
goto Label_01D0;
}
if (activity3 != null)
{
obj2 = service.GetDesigner(activity3);
}
Label_01D0:
if (obj2 == null)
{
serializationManager.ReportError(SR.GetString("Error_LayoutSerializationActivityNotFound", new object[] { reader.LocalName, str, "Name" }));
}
return obj2;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:81,代码来源:ActivityDesignerLayoutSerializer.cs