本文整理汇总了C#中System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowMarkupSerializationManager.GetType方法的具体用法?C# WorkflowMarkupSerializationManager.GetType怎么用?C# WorkflowMarkupSerializationManager.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager
的用法示例。
在下文中一共展示了WorkflowMarkupSerializationManager.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeFromString
protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
{
CodeTypeReference reference;
if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
{
return null;
}
if (string.IsNullOrEmpty(value) || base.IsValidCompactAttributeFormat(value))
{
return null;
}
try
{
Type type = serializationManager.GetType(value);
if (type != null)
{
reference = new CodeTypeReference(type);
reference.UserData["QualifiedName"] = type.AssemblyQualifiedName;
return reference;
}
}
catch (Exception)
{
}
reference = new CodeTypeReference(value);
reference.UserData["QualifiedName"] = value;
return reference;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:CodeTypeReferenceSerializer.cs
示例2: SerializeToString
protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (value == null)
throw new ArgumentNullException("value");
CodeTypeReference reference = value as CodeTypeReference;
if (reference == null)
return string.Empty;
// make the typename as best we can, and try to get the fully qualified name
// if a type is used in an assembly not referenced, GetType will complain
string typeName = ConvertTypeReferenceToString(reference);
Type type = serializationManager.GetType(typeName);
if (type == null)
{
// TypeProvider can't find it, see if it's a common type in mscorlib
type = Type.GetType(typeName, false);
if (type == null)
{
// still no luck finding it, so simply save the name without assembly information
// this is equivalent to what happened before
return typeName;
}
}
//
// If we get a real type make sure that we get the correct fully qualified name for the target framework version
string assemblyFullName = null;
TypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;
if (typeProvider != null)
{
assemblyFullName = typeProvider.GetAssemblyName(type);
}
//
// If we didn't find an assembly value it is either a local type or something is wrong
// However per the general guidance on multi-targeting it is up to the caller
// to make sure that writers (such as Xoml) are given types that exist in the target framework
// This makes it the job of the rules designer or rules validator to not call the Xoml stack
// with types that do not exist in the target framework
if (string.IsNullOrEmpty(assemblyFullName))
{
typeName = type.AssemblyQualifiedName;
}
else
{
typeName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName);
}
return typeName;
}
示例3: SerializeToString
protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
{
if (serializationManager == null)
{
throw new ArgumentNullException("serializationManager");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
CodeTypeReference reference = value as CodeTypeReference;
if (reference == null)
{
return string.Empty;
}
string typeName = ConvertTypeReferenceToString(reference);
Type type = serializationManager.GetType(typeName);
if (type == null)
{
type = Type.GetType(typeName, false);
if (type == null)
{
return typeName;
}
}
string assemblyName = null;
TypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;
if (service != null)
{
assemblyName = service.GetAssemblyName(type);
}
if (string.IsNullOrEmpty(assemblyName))
{
return type.AssemblyQualifiedName;
}
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[] { type.FullName, assemblyName });
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:CodeTypeReferenceSerializer.cs
示例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: ResolveDependencyProperty
private DependencyProperty ResolveDependencyProperty(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, object attachedObj, string fullPropertyName)
{
Type ownerType = null;
string propertyName = String.Empty;
int separatorIndex = fullPropertyName.IndexOf(".");
if (separatorIndex != -1)
{
string ownerTypeName = fullPropertyName.Substring(0, separatorIndex);
propertyName = fullPropertyName.Substring(separatorIndex + 1);
if (!String.IsNullOrEmpty(ownerTypeName) && !String.IsNullOrEmpty(propertyName))
ownerType = serializationManager.GetType(new XmlQualifiedName(ownerTypeName, reader.LookupNamespace(reader.Prefix)));
}
else
{
ownerType = attachedObj.GetType();
propertyName = fullPropertyName;
}
if (ownerType == null)
return null;
//We need to make sure that the register method is always called for the dynamic property before we try to resolve it
//In cases of attached properties if this statement is not there then the dynamic property wont be found as it is
//not registered till the first access of the static field
DependencyProperty dependencyProperty = null;
FieldInfo fieldInfo = ownerType.GetField(propertyName + "Property", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
if (fieldInfo == null)
fieldInfo = ownerType.GetField(propertyName + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
if (fieldInfo != null)
{
dependencyProperty = fieldInfo.GetValue(attachedObj) as DependencyProperty;
if (dependencyProperty != null)
{
object[] attributes = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
if (attributes.Length > 0)
{
DesignerSerializationVisibilityAttribute serializationVisibilityAttribute = attributes[0] as DesignerSerializationVisibilityAttribute;
if (serializationVisibilityAttribute.Visibility == DesignerSerializationVisibility.Hidden)
dependencyProperty = null;
}
}
}
return dependencyProperty;
}
示例6: 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;
}
示例7: InternalDeserializeFromString
private object InternalDeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
{
if (serializationManager == null)
throw new ArgumentNullException("serializationManager");
if (propertyType == null)
throw new ArgumentNullException("propertyType");
if (value == null)
throw new ArgumentNullException("value");
object propVal = null;
XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
if (reader == null)
{
Debug.Assert(false, "XmlReader not available.");
return null;
}
if (IsValidCompactAttributeFormat(value))
{
propVal = DeserializeFromCompactFormat(serializationManager, reader, value);
}
else
{
if (value.StartsWith("{}", StringComparison.Ordinal))
value = value.Substring(2);
// Check for Nullable types
if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
Type genericType = (Type)propertyType.GetGenericArguments()[0];
Debug.Assert(genericType != null);
propertyType = genericType;
}
if (propertyType.IsPrimitive || propertyType == typeof(System.String))
{
propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
}
else if (propertyType.IsEnum)
{
propVal = Enum.Parse(propertyType, value, true);
}
else if (typeof(Delegate).IsAssignableFrom(propertyType))
{
// Just return the method name. This must happen after Bind syntax has been checked.
propVal = value;
}
else if (typeof(TimeSpan) == propertyType)
{
propVal = TimeSpan.Parse(value, CultureInfo.InvariantCulture);
}
else if (typeof(DateTime) == propertyType)
{
propVal = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
}
else if (typeof(Guid) == propertyType)
{
propVal = Utility.CreateGuid(value);
}
else if (typeof(Type).IsAssignableFrom(propertyType))
{
propVal = serializationManager.GetType(value);
if (propVal != null)
{
Type type = propVal as Type;
if (type.IsPrimitive || type.IsEnum || type == typeof(System.String))
return type;
}
ITypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider;
if (typeProvider != null)
{
Type type = typeProvider.GetType(value);
if (type != null)
return type;
}
return value;
}
else if (typeof(IConvertible).IsAssignableFrom(propertyType))
{
propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
}
else if (propertyType.IsAssignableFrom(value.GetType()))
{
propVal = value;
}
else
{
throw CreateSerializationError(SR.GetString(SR.Error_SerializerPrimitivePropertyNoLogic, new object[] { "", value.Trim(), "" }), reader);
}
}
return propVal;
}
示例8: DeserializeFromString
protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
{
if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
return null;
// if the string is empty or markup extension,
// then the object is null
if (string.IsNullOrEmpty(value) || IsValidCompactAttributeFormat(value))
return null;
// value is the fully qualified name of the type
// however, it may refer to non-existant assemblies, so we may get an error
CodeTypeReference result;
try
{
Type type = serializationManager.GetType(value);
if (type != null)
{
result = new CodeTypeReference(type);
result.UserData[QualifiedName] = type.AssemblyQualifiedName;
return result;
}
}
catch (Exception)
{
// something went wrong getting the type, so simply pass in the string and
// let CodeTypeReference figure it out. Note that CodeTypeReference has a method
// RipOffAssemblyInformationFromTypeName, so assembly names are ignored.
}
result = new CodeTypeReference(value);
result.UserData[QualifiedName] = value;
return result;
}
示例9: ResolveWellKnownTypes
internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
{
Type resolvedType = null;
List<WorkflowMarkupSerializerMapping> knownMappings = new List<WorkflowMarkupSerializerMapping>();
if (xmlns.Equals(StandardXomlKeys.WorkflowXmlNs, StringComparison.Ordinal))
{
if (!WorkflowMarkupSerializerMapping.wellKnownTypes.TryGetValue(typeName, out resolvedType))
{
if (typeName.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
{
knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
}
if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
{
knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
}
else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
{
knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
}
else if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) ||
typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
{
knownMappings.Add(WorkflowMarkupSerializerMapping.Rules);
}
}
}
else if (xmlns.Equals(StandardXomlKeys.Definitions_XmlNs, StringComparison.Ordinal))
{
knownMappings.Add(WorkflowMarkupSerializerMapping.Serialization);
}
if (resolvedType == null)
{
foreach (WorkflowMarkupSerializerMapping mapping in knownMappings)
{
string fullyQualifiedTypeName = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
resolvedType = manager.GetType(fullyQualifiedTypeName);
if (resolvedType != null)
break;
}
}
return resolvedType;
}
示例10: ResolveWellKnownTypes
internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
{
Type type = null;
List<WorkflowMarkupSerializerMapping> list = new List<WorkflowMarkupSerializerMapping>();
if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml/workflow", StringComparison.Ordinal))
{
if (!wellKnownTypes.TryGetValue(typeName, out type))
{
if (typeName.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
{
list.Add(Activities);
list.Add(ComponentModel);
}
if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
{
list.Add(Activities);
list.Add(ComponentModel);
list.Add(ComponentModelDesign);
}
else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
{
list.Add(ComponentModelDesign);
list.Add(Activities);
}
else if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) || typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
{
list.Add(Rules);
}
}
}
else if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml", StringComparison.Ordinal))
{
list.Add(Serialization);
}
if (type == null)
{
foreach (WorkflowMarkupSerializerMapping mapping in list)
{
string str = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
type = manager.GetType(str);
if (type != null)
{
return type;
}
}
}
return type;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:48,代码来源:WorkflowMarkupSerializerMapping.cs